Skip to content

Commit

Permalink
✅ BASE #198 new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Oct 27, 2019
1 parent 8255ed2 commit 5a7b735
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions base/test/classes/helpers/ArrayHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,77 @@ public function testValidateIdIsNumeric_OKArrayNotEmpty(){
$listArray[]=2;
$this->assertNull( ArrayHelper::validateIsArray($listArray,__METHOD__,__LINE__) );
}
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------
/**
* @expectedException InvalidArgumentException
*/
public function testFormDinDeleteRowByColumnNameAndKeyIndex_FailNull(){
ArrayHelper::formDinDeleteRowByColumnNameAndKeyIndex(null,'xx',10);
}

public function testFormDinDeleteRowByColumnNameAndKeyIndex_FailAttributeNotExist(){
$mock = new mockFormDinArray();
$array = $mock->generateTable();

$result = ArrayHelper::formDinDeleteRowByColumnNameAndKeyIndex($array,'idCarro',10);

$expected = false;
$this->assertEquals($expected, $result['result']);
$expected = TMessage::ARRAY_ATTRIBUTE_NOT_EXIST;
$this->assertEquals($expected, $result['message']);
}

public function testFormDinDeleteRowByColumnNameAndKeyIndex_FailKeyNotExist(){
$mock = new mockFormDinArray();
$array = $mock->generateTable();

$result = ArrayHelper::formDinDeleteRowByColumnNameAndKeyIndex($array,'IDPESSOA',10);

$expected = false;
$this->assertEquals($expected, $result['result']);
$expected = TMessage::ARRAY_KEY_NOT_EXIST;
$this->assertEquals($expected, $result['message']);
}

public function testFormDinDeleteRowByColumnNameAndKeyIndex_okQtd(){
$mock = new mockFormDinArray();
$array = $mock->generateTable();

$result = ArrayHelper::formDinDeleteRowByColumnNameAndKeyIndex($array,'IDPESSOA',1);

$expected = true;
$this->assertEquals($expected, $result['result']);
$expected = 3;
$resultQtd = CountHelper::count($result['formarray']['IDPESSOA']);
$this->assertEquals($expected, $resultQtd);

$this->assertEquals(3, $result['formarray']['IDPESSOA'][1]);
$this->assertEquals('Dell', $result['formarray']['NMPESSOA'][1]);
$this->assertEquals('J', $result['formarray']['TPPESSOA'][1]);
$this->assertEquals(null, $result['formarray']['NMCPF'][1]);
$this->assertEquals('72381189000110', $result['formarray']['NMCNPJ'][1]);
}

public function testFormDinDeleteRowByColumnNameAndKeyIndex_ok3Times(){
$mock = new mockFormDinArray();
$array = $mock->generateTable();

$result = ArrayHelper::formDinDeleteRowByColumnNameAndKeyIndex($array,'IDPESSOA',3);
$result = ArrayHelper::formDinDeleteRowByColumnNameAndKeyIndex($result['formarray'],'IDPESSOA',2);
$result = ArrayHelper::formDinDeleteRowByColumnNameAndKeyIndex($result['formarray'],'IDPESSOA',1);

$expected = true;
$this->assertEquals($expected, $result['result']);
$expected = 1;
$resultQtd = CountHelper::count($result['formarray']['IDPESSOA']);
$this->assertEquals($expected, $resultQtd);

$this->assertEquals(1, $result['formarray']['IDPESSOA'][0]);
$this->assertEquals('Joao Silva', $result['formarray']['NMPESSOA'][0]);
$this->assertEquals('F', $result['formarray']['TPPESSOA'][0]);
$this->assertEquals('123456789', $result['formarray']['NMCPF'][0]);
}

}

0 comments on commit 5a7b735

Please sign in to comment.