NxTIC/phpunit/tests/Database_check.php

165 lines
5.1 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( \manager\Database::check('id', 0) );
}
public function testIdSizeInfStringCorrect(){
$this->assertTrue( \manager\Database::check('id', '0') );
}
/* (2) Taille inferieure depassement */
public function testIdSizeInfIncorrect(){
$this->assertFalse( \manager\Database::check('id', -1) );
}
public function testIdSizeInfStringIncorrect(){
$this->assertFalse( \manager\Database::check('id', '-1') );
}
/* (3) Taille superieure correcte */
public function testIdSizeSupCorrect(){
$this->assertTrue( \manager\Database::check('id', 2147483647) );
}
public function testIdSizeSupStringCorrect(){
$this->assertTrue( \manager\Database::check('id', '2147483647') );
}
/* (3) Taille superieure depassement */
public function testIdSizeSupIncorrect(){
$this->assertFalse( \manager\Database::check('id', 2147483648) );
}
public function testIdSizeSupStringIncorrect(){
$this->assertFalse( \manager\Database::check('id', '2147483648') );
}
/* [2] Varchar
=========================================================*/
/* (1) Type */
public function testVarcharTypeCorrect(){
$this->assertTrue( \manager\Database::check('varchar(0,10)', 'string') );
}
public function testVarcharTypeIncorrect(){
$this->assertFalse( \manager\Database::check('varchar(0,10)', 10 ) );
$this->assertFalse( \manager\Database::check('varchar(0,10)', array() ) );
}
/* (2) Borne inferieure */
public function testVarcharLtMin(){
$min = rand(1, 50);
$string = str_repeat('a', $min-1);
$this->assertFalse( \manager\Database::check("varchar($min, 255)", $string) );
}
public function testVarcharEqMin(){
$min = rand(1, 50);
$string = str_repeat('a', $min);
$this->assertTrue( \manager\Database::check("varchar($min, 255)", $string) );
}
public function testVarcharGtMin(){
$min = rand(1, 50);
$string = str_repeat('a', $min+1);
$this->assertTrue( \manager\Database::check("varchar($min, 255)", $string) );
}
/* (3) Borne superieure */
public function testVarcharLtMax(){
$max = rand(1, 255);
$string = str_repeat('a', $max-1);
$this->assertTrue( \manager\Database::check("varchar(0, $max)", $string) );
}
public function testVarcharEqMax(){
$max = rand(1, 255);
$string = str_repeat('a', $max);
$this->assertTrue( \manager\Database::check("varchar(0, $max)", $string) );
}
public function testVarcharGtMax(){
$max = rand(1, 255);
$string = str_repeat('a', $max+1);
$this->assertFalse( \manager\Database::check("varchar(0, $max)", $string) );
}
/* [3] Test des tableaux avec type des elements
=========================================================*/
/* [4] Adresse mail
=========================================================*/
/* (1) Size */
public function testMailSizeEqCorrect(){
$this->assertLessThanOrEqual( 50, strlen('nom-prenom.mot@domaine-d.gouv') );
$this->assertTrue( \manager\Database::check('mail', 'nom-prenom.mot@domaine-d.gouv') );
}
public function testMailSizeSupCorrect(){
$this->assertGreaterThan( 50, strlen('ab12345678901234567890nom-prenom.mot@domaine-d.gouv') );
$this->assertFalse( \manager\Database::check('mail', 'ab12345678901234567890nom-prenom.mot@domaine-d.gouv') );
}
/* (2) Content */
public function testMailContentCorrect(){
$this->assertTrue( \manager\Database::check('mail', '0nom-prenom.mot@domaine-d.gouv') );
}
public function testMailContentIncorrect1(){
$this->assertFalse( \manager\Database::check('mail', '0nom-prenom.mot@domaine-d.gouve') );
}
public function testMailContentIncorrect2(){
$this->assertFalse( \manager\Database::check('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\Database::check('sha1', $password_hash) );
}
public function testPasswordSizeInfIncorrect(){
$password_hash = 'a';
$this->assertLessThan( 40, strlen($password_hash) );
$this->assertFalse( \manager\Database::check('sha1', $password_hash) );
}
public function testPasswordSizeSupIncorrect(){
$password_hash = \manager\sessionManager::sha1('monmotdepasse').'a';
$this->assertGreaterThan( 40, strlen($password_hash) );
$this->assertFalse( \manager\Database::check('sha1', $password_hash) );
}
public function testPasswordContentCorrect(){
$this->assertTrue( \manager\Database::check('sha1', 'dd629d39c4576731a2bef003c72ff89d6fc2a99a') );
}
public function testPasswordContentIncorrect(){
$this->assertContains( 'g', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g' );
$this->assertFalse( \manager\Database::check('sha1', 'dd629d39c4576731a2bef003c72ff89d6fc2a9g') );
}
}
?>