NxTIC/subDir/test/phpunit/tests/Database_check.php

207 lines
6.2 KiB
PHP
Raw Normal View History

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