2016-04-04 09:47:17 +00:00
|
|
|
<?php namespace phpunit;
|
|
|
|
|
|
|
|
class Database_delNumeric extends \PHPUnit_Framework_TestCase{
|
|
|
|
|
|
|
|
/* [0] Verification du type
|
|
|
|
=========================================================*/
|
|
|
|
public function testTypeInt(){
|
2016-10-18 13:11:37 +00:00
|
|
|
$this->assertEquals( [], \database\core\Database::delNumeric(10) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testTypeString(){
|
2016-10-18 13:11:37 +00:00
|
|
|
$this->assertEquals( [], \database\core\Database::delNumeric('notarray') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* [1] Verification pour 2 dimensions
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Global */
|
|
|
|
public function testGlobal2Dim(){
|
|
|
|
$fetchData = array(array(
|
|
|
|
'id' => '000001',
|
|
|
|
0 => '000001',
|
|
|
|
'nom' => 'Jean Dupont',
|
|
|
|
1 => 'Jean Dupont',
|
|
|
|
));
|
|
|
|
|
2016-10-18 13:11:37 +00:00
|
|
|
$computed_array = \database\core\Database::delNumeric( $fetchData );
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'id', $computed_array[0] );
|
|
|
|
$this->assertArrayHasKey( 'nom', $computed_array[0] );
|
|
|
|
$this->assertArrayNotHasKey( 0, $computed_array[0] );
|
|
|
|
$this->assertArrayNotHasKey( 1, $computed_array[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Verification d'indices numeriques dans les donnees */
|
|
|
|
public function testGlobal2DimWithNumericIndexes(){
|
|
|
|
$fetchData = array(array(
|
|
|
|
'id' => '000001',
|
|
|
|
0 => '000001',
|
|
|
|
'nom' => 'Jean Dupont',
|
|
|
|
1 => 'Jean Dupont',
|
|
|
|
2 => 'Bla',
|
|
|
|
3 => 'Bla',
|
|
|
|
4 => 'Bla',
|
|
|
|
5 => 'Bla',
|
|
|
|
6 => 'Bla',
|
|
|
|
7 => 'Bla'
|
|
|
|
));
|
|
|
|
|
2016-10-18 13:11:37 +00:00
|
|
|
$computed_array = \database\core\Database::delNumeric( $fetchData );
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'id', $computed_array[0] );
|
|
|
|
$this->assertArrayHasKey( 'nom', $computed_array[0] );
|
|
|
|
$this->assertArrayNotHasKey( 0, $computed_array[0] );
|
|
|
|
$this->assertArrayNotHasKey( 1, $computed_array[0] );
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 2, $computed_array[0] );
|
|
|
|
$this->assertArrayHasKey( 3, $computed_array[0] );
|
|
|
|
$this->assertArrayHasKey( 4, $computed_array[0] );
|
|
|
|
$this->assertArrayHasKey( 5, $computed_array[0] );
|
|
|
|
$this->assertArrayHasKey( 6, $computed_array[0] );
|
|
|
|
$this->assertArrayHasKey( 7, $computed_array[0] );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Verification pour 1 dimensions
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Global */
|
|
|
|
public function testGlobal1Dim(){
|
|
|
|
$fetchData = array(
|
|
|
|
'id' => '000001',
|
|
|
|
0 => '000001',
|
|
|
|
'nom' => 'Jean Dupont',
|
|
|
|
1 => 'Jean Dupont'
|
|
|
|
);
|
|
|
|
|
2016-10-18 13:11:37 +00:00
|
|
|
$computed_array = \database\core\Database::delNumeric( $fetchData );
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'id', $computed_array );
|
|
|
|
$this->assertArrayHasKey( 'nom', $computed_array );
|
|
|
|
$this->assertArrayNotHasKey( 0, $computed_array );
|
|
|
|
$this->assertArrayNotHasKey( 1, $computed_array );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Verification d'indices numeriques dans les donnees */
|
|
|
|
public function testGlobal1DimWithNumericIndexes(){
|
|
|
|
$fetchData = array(
|
|
|
|
'id' => '000001',
|
|
|
|
0 => '000001',
|
|
|
|
'nom' => 'Jean Dupont',
|
|
|
|
1 => 'Jean Dupont',
|
|
|
|
2 => 'Bla',
|
|
|
|
3 => 'Bla',
|
|
|
|
4 => 'Bla',
|
|
|
|
5 => 'Bla',
|
|
|
|
6 => 'Bla',
|
|
|
|
7 => 'Bla'
|
|
|
|
);
|
|
|
|
|
2016-10-18 13:11:37 +00:00
|
|
|
$computed_array = \database\core\Database::delNumeric( $fetchData );
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
$this->assertArrayHasKey( 'id', $computed_array );
|
|
|
|
$this->assertArrayHasKey( 'nom', $computed_array );
|
|
|
|
$this->assertArrayNotHasKey( 0, $computed_array );
|
|
|
|
$this->assertArrayNotHasKey( 1, $computed_array );
|
|
|
|
|
|
|
|
$this->assertArrayHasKey( 2, $computed_array );
|
|
|
|
$this->assertArrayHasKey( 3, $computed_array );
|
|
|
|
$this->assertArrayHasKey( 4, $computed_array );
|
|
|
|
$this->assertArrayHasKey( 5, $computed_array );
|
|
|
|
$this->assertArrayHasKey( 6, $computed_array );
|
|
|
|
$this->assertArrayHasKey( 7, $computed_array );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|