207 lines
6.2 KiB
PHP
Executable File
207 lines
6.2 KiB
PHP
Executable File
<?php namespace phpunit;
|
|
|
|
class Database_check extends \PHPUnit_Framework_TestCase{
|
|
|
|
|
|
/* [1] AUTO_INCREMENT
|
|
=========================================================*/
|
|
/* (1) Taille inferieure correcte */
|
|
public function testIdSizeInfCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('id', 0) );
|
|
}
|
|
public function testIdSizeInfStringCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('id', '0') );
|
|
}
|
|
|
|
/* (2) Taille inferieure depassement */
|
|
public function testIdSizeInfIncorrect(){
|
|
$this->assertFalse( \manager\Checker::run('id', -1) );
|
|
}
|
|
public function testIdSizeInfStringIncorrect(){
|
|
$this->assertFalse( \manager\Checker::run('id', '-1') );
|
|
}
|
|
|
|
/* (3) Taille superieure correcte */
|
|
public function testIdSizeSupCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('id', 2147483647) );
|
|
}
|
|
public function testIdSizeSupStringCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('id', '2147483647') );
|
|
}
|
|
|
|
/* (3) Taille superieure depassement */
|
|
public function testIdSizeSupIncorrect(){
|
|
$this->assertFalse( \manager\Checker::run('id', 2147483648) );
|
|
}
|
|
public function testIdSizeSupStringIncorrect(){
|
|
$this->assertFalse( \manager\Checker::run('id', '2147483648') );
|
|
}
|
|
|
|
|
|
/* [2] Varchar
|
|
=========================================================*/
|
|
/* (1) Type */
|
|
public function testVarcharTypeCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('varchar(0,10)', 'string') );
|
|
}
|
|
public function testVarcharTypeIncorrect(){
|
|
$this->assertFalse( \manager\Checker::run('varchar(0,10)', 10 ) );
|
|
$this->assertFalse( \manager\Checker::run('varchar(0,10)', array() ) );
|
|
}
|
|
|
|
/* (2) Borne inferieure */
|
|
public function testVarcharLtMin(){
|
|
$min = rand(1, 50);
|
|
$string = str_repeat('a', $min-1);
|
|
|
|
$this->assertFalse( \manager\Checker::run("varchar($min, 255)", $string) );
|
|
}
|
|
public function testVarcharEqMin(){
|
|
$min = rand(1, 50);
|
|
$string = str_repeat('a', $min);
|
|
|
|
$this->assertTrue( \manager\Checker::run("varchar($min, 255)", $string) );
|
|
}
|
|
public function testVarcharGtMin(){
|
|
$min = rand(1, 50);
|
|
$string = str_repeat('a', $min+1);
|
|
|
|
$this->assertTrue( \manager\Checker::run("varchar($min, 255)", $string) );
|
|
}
|
|
|
|
/* (3) Borne superieure */
|
|
public function testVarcharLtMax(){
|
|
$max = rand(1, 255);
|
|
$string = str_repeat('a', $max-1);
|
|
|
|
$this->assertTrue( \manager\Checker::run("varchar(0, $max)", $string) );
|
|
}
|
|
public function testVarcharEqMax(){
|
|
$max = rand(1, 255);
|
|
$string = str_repeat('a', $max);
|
|
|
|
$this->assertTrue( \manager\Checker::run("varchar(0, $max)", $string) );
|
|
}
|
|
public function testVarcharGtMax(){
|
|
$max = rand(1, 255);
|
|
$string = str_repeat('a', $max+1);
|
|
|
|
$this->assertFalse( \manager\Checker::run("varchar(0, $max)", $string) );
|
|
}
|
|
|
|
|
|
/* [3] Test des tableaux avec type des elements
|
|
=========================================================*/
|
|
/* (1) Type */
|
|
public function testArrayTypeCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('array<text>', array() ) );
|
|
}
|
|
public function testArrayTypeIncorrect(){
|
|
$this->assertFalse( \manager\Checker::run('array<text>', 10 ) );
|
|
$this->assertFalse( \manager\Checker::run('array<text>', 'string' ) );
|
|
}
|
|
|
|
/* (2) Tests divers */
|
|
public function testArrayEmpty(){
|
|
$arr = array();
|
|
|
|
$this->assertTrue( \manager\Checker::run("array<text>", $arr) );
|
|
}
|
|
public function testArrayNotEmpty(){
|
|
$arr = array('a', 'b');
|
|
|
|
$this->assertTrue( \manager\Checker::run("array<text>", $arr) );
|
|
}
|
|
|
|
public function testArrayAllRight(){
|
|
$arr = array('a', 'aa', 'a', 'bb');
|
|
|
|
$this->assertTrue( \manager\Checker::run("array<varchar(1,2)>", $arr) );
|
|
}
|
|
public function testArrayOneWrong(){
|
|
$arr = array('a', 'aa', 'a', 'bb', 'aaa');
|
|
|
|
$this->assertFalse( \manager\Checker::run("array<varchar(1,2)>", $arr) );
|
|
}
|
|
|
|
|
|
public function testArrayRecursive(){
|
|
$arr = array(
|
|
array(1, 100),
|
|
array(1, 100),
|
|
array(1, 100),
|
|
array(1, 100)
|
|
);
|
|
|
|
$this->assertFalse( \manager\Checker::run("array<array<int>>", $arr) );
|
|
}
|
|
|
|
|
|
|
|
/* [4] Adresse mail
|
|
=========================================================*/
|
|
/* (1) Size */
|
|
public function testMailSizeEqCorrect(){
|
|
$this->assertLessThanOrEqual( 50, strlen('nom-prenom.mot@domaine-d.gouv') );
|
|
$this->assertTrue( \manager\Checker::run('mail', 'nom-prenom.mot@domaine-d.gouv') );
|
|
}
|
|
|
|
public function testMailSizeSupCorrect(){
|
|
$this->assertGreaterThan( 50, strlen('ab12345678901234567890nom-prenom.mot@domaine-d.gouv') );
|
|
$this->assertFalse( \manager\Checker::run('mail', 'ab12345678901234567890nom-prenom.mot@domaine-d.gouv') );
|
|
}
|
|
|
|
/* (2) Content */
|
|
public function testMailContentCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('mail', '0nom-prenom.mot@domaine-d.gouv') );
|
|
}
|
|
|
|
public function testMailContentIncorrect1(){
|
|
$this->assertFalse( \manager\Checker::run('mail', '0nom-prenom.mot@domaine-d.gouve') );
|
|
}
|
|
|
|
public function testMailContentIncorrect2(){
|
|
$this->assertFalse( \manager\Checker::run('mail', '0nom-prenom.mot@domaine-d.g') );
|
|
}
|
|
|
|
|
|
|
|
/* [5] SHA1 hash
|
|
=========================================================*/
|
|
public function testPasswordSizeEqCorrect(){
|
|
$password_hash = \manager\sessionManager::sha1('monmotdepasse');
|
|
|
|
$this->assertEquals( 40, strlen($password_hash) );
|
|
$this->assertTrue( \manager\Checker::run('sha1', $password_hash) );
|
|
}
|
|
|
|
public function testPasswordSizeInfIncorrect(){
|
|
$password_hash = 'a';
|
|
|
|
$this->assertLessThan( 40, strlen($password_hash) );
|
|
$this->assertFalse( \manager\Checker::run('sha1', $password_hash) );
|
|
}
|
|
|
|
public function testPasswordSizeSupIncorrect(){
|
|
$password_hash = \manager\sessionManager::sha1('monmotdepasse').'a';
|
|
|
|
$this->assertGreaterThan( 40, strlen($password_hash) );
|
|
$this->assertFalse( \manager\Checker::run('sha1', $password_hash) );
|
|
}
|
|
|
|
|
|
public function testPasswordContentCorrect(){
|
|
$this->assertTrue( \manager\Checker::run('sha1', 'dd629d39c4576731a2bef003c72ff89d6fc2a99a') );
|
|
}
|
|
|
|
public function testPasswordContentIncorrect(){
|
|
$this->assertContains( 'g', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g' );
|
|
$this->assertFalse( \manager\Checker::run('sha1', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g') );
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
?>
|