SMMP/phpunit/tests/Database_check.php

267 lines
9.0 KiB
PHP
Executable File

<?php namespace phpunit;
class Database_check extends \PHPUnit_Framework_TestCase{
/* [1] AUTO_INCREMENT
=========================================================*/
public function testAutoIncrementSizeInfCorrect(){
$this->assertTrue( \api\core\Checker::run('auto_increment_id', -2147483647) );
}
public function testAutoIncrementSizeInfStringCorrect(){
$this->assertTrue( \api\core\Checker::run('auto_increment_id', '-2147483647') );
}
public function testAutoIncrementSizeSupCorrect(){
$this->assertTrue( \api\core\Checker::run('auto_increment_id', 2147483647) );
}
public function testAutoIncrementSizeSupStringCorrect(){
$this->assertTrue( \api\core\Checker::run('auto_increment_id', '2147483647') );
}
public function testAutoIncrementSizeLtInfIncorrect(){
$this->assertFalse( \api\core\Checker::run('auto_increment_id', -2147483647-1) );
}
public function testAutoIncrementSizeLtInfStringIncorrect(){
$this->assertFalse( \api\core\Checker::run('auto_increment_id', '-2147483648') );
}
public function testAutoIncrementSizeGtSupIncorrect(){
$this->assertFalse( \api\core\Checker::run('auto_increment_id', 2147483647+1) );
}
public function testAutoIncrementSizeGtSupStringIncorrect(){
$this->assertFalse( \api\core\Checker::run('auto_increment_id', '2147483648') );
}
/* [1] Code RFID
=========================================================*/
public function testUserCodeSize4(){
$this->assertTrue( \api\core\Checker::run('user.code', '01-23-AB-CD') );
}
public function testUserCodeSize6(){
$this->assertTrue( \api\core\Checker::run('user.code', '01-23-45-67-89-AB') );
}
public function testUserCodeSize4WrongCharacter(){
$this->assertFalse( \api\core\Checker::run('user.code', '01-23-AB-CG') );
}
public function testUserCodeSizeGreaterThan6(){
$this->assertFalse( \api\core\Checker::run('user.code', '01-23-45-67-89-AB-CD') );
}
public function testUserCodeSize6WrongCharacter(){
$this->assertFalse( \api\core\Checker::run('user.code', '01-23-45-67-89-AG') );
}
/* [2] user.username ; machine.name ; group.name
=========================================================*/
/* (1) Type */
public function testUsernameTypeStringCorrect(){
$this->assertTrue( \api\core\Checker::run('user.username', '012') );
}
public function testUsernameTypeIntIncorrect(){
$this->assertFalse( \api\core\Checker::run('user.username', 012) );
}
/* (2) Content */
public function testUsernameContentCorrect(){
$this->assertTrue( \api\core\Checker::run('user.username', '0123456789_-') );
$this->assertTrue( \api\core\Checker::run('user.username', 'abcdefghijklmnopqrstuvwxyz') );
$this->assertTrue( \api\core\Checker::run('user.username', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') );
}
public function testUsernameContentIncorrect(){
$illegal_chars = '{}[]()=+.,\'\\"/:;|!@#$%^&* ';
foreach(str_split($illegal_chars) as $char) // Teste les caracteres enonces plus haut
$this->assertFalse( \api\core\Checker::run('user.username', 'abc'.$char) );
}
/* (3) Size */
public function testUsernameSize3Correct(){
$this->assertEquals( 3, strlen('012') );
$this->assertTrue( \api\core\Checker::run('user.username', '012') );
}
public function testUsernameSize30Correct(){
$this->assertEquals( 30, strlen('0123456789abcdefghijklmno_-sda') );
$this->assertTrue( \api\core\Checker::run('user.username', '0123456789abcdefghijklmno_-sda') );
}
public function testUsernameSizeLt3Incorrect(){
$this->assertLessThan( 3, strlen('') );
$this->assertFalse( \api\core\Checker::run('user.username', '') );
}
public function testUsernameSizeGt30Incorrect(){
$this->assertGreaterThan( 30, strlen('0123456789abcdefghijklmno_-sdaa') );
$this->assertFalse( \api\core\Checker::run('user.username', '0123456789abcdefghijklmno_-sdaa') );
}
/* [3] firstname / lastname
=========================================================*/
/* (1) Type */
public function testFirstnameTypeStringCorrect(){
$this->assertTrue( \api\core\Checker::run('user.firstname', 'abc') );
}
public function testFirstnameTypeIntIncorrect(){
$this->assertFalse( \api\core\Checker::run('user.firstname', 01932) );
}
/* (2) Content */
public function testFirstnameContentCorrect(){
$this->assertTrue( \api\core\Checker::run('user.firstname', 'abcdefghijklmnopqrstuvwxyz') );
$this->assertTrue( \api\core\Checker::run('user.firstname', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ') );
}
public function testFirstnameContentIncorrect(){
$illegal_chars = '{}[]()=_+.,\'\\"/:;|!@#$%^&*0123456789';
foreach(str_split($illegal_chars) as $char) // Teste les caracteres enonces plus haut
$this->assertFalse( \api\core\Checker::run('user.firstname', 'abc'.$char) );
}
/* (3) Size */
public function testFirstnameSize3Correct(){
$this->assertEquals( 3, strlen('abc') );
$this->assertTrue( \api\core\Checker::run('user.firstname', 'abc') );
}
public function testFirstnameSize30Correct(){
$this->assertEquals( 30, strlen('abcdefghijklmnopqrstuvwxyz-k s') );
$this->assertTrue( \api\core\Checker::run('user.firstname', 'abcdefghijklmnopqrstuvwxyz-k s') );
}
public function testFirstnameSizeLt3Incorrect(){
$this->assertLessThan( 3, strlen('ab') );
$this->assertFalse( \api\core\Checker::run('user.firstname', 'ab') );
}
public function testFirstnameSizeGt30Incorrect(){
$this->assertGreaterThan( 30, strlen('abcdefghijklmnopqrstuvwxyz-k ss') );
$this->assertFalse( \api\core\Checker::run('user.firstname', 'abcdefghijklmnopqrstuvwxyz-k ss') );
}
/* [4] Adresse mail
=========================================================*/
/* (1) Size */
public function testMailSizeEqCorrect(){
$this->assertLessThanOrEqual( 50, 'nom-prenom.mot@domaine-d.gouv' );
$this->assertTrue( \api\core\Checker::run('user.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('user.mail', 'ab12345678901234567890nom-prenom.mot@domaine-d.gouv') );
}
/* (2) Content */
public function testMailContentCorrect(){
$this->assertTrue( \api\core\Checker::run('user.mail', '0nom-prenom.mot@domaine-d.gouv') );
}
public function testMailContentIncorrect1(){
$this->assertFalse( \api\core\Checker::run('user.mail', '0nom-prenom.mot@domaine-d.gouve') );
}
public function testMailContentIncorrect2(){
$this->assertFalse( \api\core\Checker::run('user.mail', '0nom-prenom.mot@domaine-d.g') );
}
/* [5] Mot de passe
=========================================================*/
public function testPasswordSizeEqCorrect(){
$password_hash = \manager\sessionManager::secure_hash('monmotdepasse');
$this->assertEquals( 40, strlen($password_hash) );
$this->assertTrue( \api\core\Checker::run('user.password', $password_hash) );
}
public function testPasswordSizeInfIncorrect(){
$password_hash = 'a';
$this->assertLessThan( 40, strlen($password_hash) );
$this->assertFalse( \api\core\Checker::run('user.password', $password_hash) );
}
public function testPasswordSizeSupIncorrect(){
$password_hash = \manager\sessionManager::secure_hash('monmotdepasse').'a';
$this->assertGreaterThan( 40, strlen($password_hash) );
$this->assertFalse( \api\core\Checker::run('user.password', $password_hash) );
}
public function testPasswordContentCorrect(){
$this->assertTrue( \api\core\Checker::run('user.password', 'dd629d39c4576731a2bef003c72ff89d6fc2a99a') );
}
public function testPasswordContentIncorrect(){
$this->assertContains( 'g', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g' );
$this->assertFalse( \api\core\Checker::run('user.password', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g') );
}
/* [6] Status de l'utilisateur
=========================================================*/
/* (1) Type */
public function testStatusTypeIntCorrect(){
$this->assertTrue( \api\core\Checker::run('user.status', 1) );
}
public function testStatusTypeStringCorrect(){
$this->assertTrue( \api\core\Checker::run('user.status', '1') );
}
public function testStatusTypeIntIncorrect(){
$this->assertFalse( \api\core\Checker::run('user.status', 1.03) );
}
public function testStatusTypeStringIncorrect(){
$this->assertFalse( \api\core\Checker::run('user.status', '1.03') );
}
/* (2) Size */
public function testStatusSizeInfCorrect(){
$this->assertGreaterThanOrEqual( 0, 0 );
$this->assertTrue( \api\core\Checker::run('user.status', 0) );
}
public function testStatusSizeSupCorrect(){
$this->assertLessThanOrEqual( 100, 100 );
$this->assertTrue( \api\core\Checker::run('user.status', 100) );
}
public function testStatusSizeInfIncorrect(){
$this->assertLessThan( 0, -1 );
$this->assertFalse( \api\core\Checker::run('user.status', -1) );
}
public function testStatusSizeSupIncorrect(){
$this->assertGreaterThan( 100, 101 );
$this->assertFalse( \api\core\Checker::run('user.status', 101) );
}
}
?>