2016-04-04 09:47:17 +00:00
|
|
|
<?php namespace phpunit;
|
|
|
|
|
|
|
|
class Database_check extends \PHPUnit_Framework_TestCase{
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] AUTO_INCREMENT
|
|
|
|
=========================================================*/
|
2016-04-17 10:34:24 +00:00
|
|
|
/* (1) Taille inferieure correcte */
|
|
|
|
public function testIdSizeInfCorrect(){
|
|
|
|
$this->assertTrue( \manager\Database::check('id', 0) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testIdSizeInfStringCorrect(){
|
|
|
|
$this->assertTrue( \manager\Database::check('id', '0') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* (2) Taille inferieure depassement */
|
|
|
|
public function testIdSizeInfIncorrect(){
|
|
|
|
$this->assertFalse( \manager\Database::check('id', -1) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testIdSizeInfStringIncorrect(){
|
|
|
|
$this->assertFalse( \manager\Database::check('id', '-1') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* (3) Taille superieure correcte */
|
|
|
|
public function testIdSizeSupCorrect(){
|
|
|
|
$this->assertTrue( \manager\Database::check('id', 2147483647) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testIdSizeSupStringCorrect(){
|
|
|
|
$this->assertTrue( \manager\Database::check('id', '2147483647') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* (3) Taille superieure depassement */
|
|
|
|
public function testIdSizeSupIncorrect(){
|
|
|
|
$this->assertFalse( \manager\Database::check('id', 2147483648) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testIdSizeSupStringIncorrect(){
|
|
|
|
$this->assertFalse( \manager\Database::check('id', '2147483648') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* [2] Varchar
|
2016-04-04 09:47:17 +00:00
|
|
|
=========================================================*/
|
|
|
|
/* (1) Type */
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testVarcharTypeCorrect(){
|
|
|
|
$this->assertTrue( \manager\Database::check('varchar(0,10)', 'string') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testVarcharTypeIncorrect(){
|
|
|
|
$this->assertFalse( \manager\Database::check('varchar(0,10)', 10 ) );
|
|
|
|
$this->assertFalse( \manager\Database::check('varchar(0,10)', array() ) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* (2) Borne inferieure */
|
|
|
|
public function testVarcharLtMin(){
|
|
|
|
$min = rand(1, 50);
|
|
|
|
$string = str_repeat('a', $min-1);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check("varchar($min, 255)", $string) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testVarcharEqMin(){
|
|
|
|
$min = rand(1, 50);
|
|
|
|
$string = str_repeat('a', $min);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertTrue( \manager\Database::check("varchar($min, 255)", $string) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testVarcharGtMin(){
|
|
|
|
$min = rand(1, 50);
|
|
|
|
$string = str_repeat('a', $min+1);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertTrue( \manager\Database::check("varchar($min, 255)", $string) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* (3) Borne superieure */
|
|
|
|
public function testVarcharLtMax(){
|
|
|
|
$max = rand(1, 255);
|
|
|
|
$string = str_repeat('a', $max-1);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertTrue( \manager\Database::check("varchar(0, $max)", $string) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testVarcharEqMax(){
|
|
|
|
$max = rand(1, 255);
|
|
|
|
$string = str_repeat('a', $max);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertTrue( \manager\Database::check("varchar(0, $max)", $string) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
2016-04-17 10:34:24 +00:00
|
|
|
public function testVarcharGtMax(){
|
|
|
|
$max = rand(1, 255);
|
|
|
|
$string = str_repeat('a', $max+1);
|
2016-04-04 09:47:17 +00:00
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check("varchar(0, $max)", $string) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* [3] Test des tableaux avec type des elements
|
|
|
|
=========================================================*/
|
|
|
|
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] Adresse mail
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Size */
|
|
|
|
public function testMailSizeEqCorrect(){
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertLessThanOrEqual( 50, strlen('nom-prenom.mot@domaine-d.gouv') );
|
|
|
|
$this->assertTrue( \manager\Database::check('mail', 'nom-prenom.mot@domaine-d.gouv') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMailSizeSupCorrect(){
|
|
|
|
$this->assertGreaterThan( 50, strlen('ab12345678901234567890nom-prenom.mot@domaine-d.gouv') );
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check('mail', 'ab12345678901234567890nom-prenom.mot@domaine-d.gouv') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Content */
|
|
|
|
public function testMailContentCorrect(){
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertTrue( \manager\Database::check('mail', '0nom-prenom.mot@domaine-d.gouv') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMailContentIncorrect1(){
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check('mail', '0nom-prenom.mot@domaine-d.gouve') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testMailContentIncorrect2(){
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check('mail', '0nom-prenom.mot@domaine-d.g') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-04-17 10:34:24 +00:00
|
|
|
/* [5] SHA1 hash
|
2016-04-04 09:47:17 +00:00
|
|
|
=========================================================*/
|
|
|
|
public function testPasswordSizeEqCorrect(){
|
2016-04-13 11:36:49 +00:00
|
|
|
$password_hash = \manager\sessionManager::sha1('monmotdepasse');
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
$this->assertEquals( 40, strlen($password_hash) );
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertTrue( \manager\Database::check('sha1', $password_hash) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPasswordSizeInfIncorrect(){
|
|
|
|
$password_hash = 'a';
|
|
|
|
|
|
|
|
$this->assertLessThan( 40, strlen($password_hash) );
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check('sha1', $password_hash) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPasswordSizeSupIncorrect(){
|
2016-04-13 11:36:49 +00:00
|
|
|
$password_hash = \manager\sessionManager::sha1('monmotdepasse').'a';
|
2016-04-04 09:47:17 +00:00
|
|
|
|
|
|
|
$this->assertGreaterThan( 40, strlen($password_hash) );
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check('sha1', $password_hash) );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testPasswordContentCorrect(){
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertTrue( \manager\Database::check('sha1', 'dd629d39c4576731a2bef003c72ff89d6fc2a99a') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testPasswordContentIncorrect(){
|
|
|
|
$this->assertContains( 'g', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g' );
|
2016-04-17 10:34:24 +00:00
|
|
|
$this->assertFalse( \manager\Database::check('sha1', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g') );
|
2016-04-04 09:47:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|