From 5dcc27cd9a12e04029fa08c53cfb48afd1451de6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 24 Sep 2011 13:44:35 +0000 Subject: [PATCH] Enhance PHPUnit tests --- test/phpunit/SecurityTest.php | 42 ++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/test/phpunit/SecurityTest.php b/test/phpunit/SecurityTest.php index d522eeeac0a..3b9756c21fc 100755 --- a/test/phpunit/SecurityTest.php +++ b/test/phpunit/SecurityTest.php @@ -178,23 +178,39 @@ class SecurityTest extends PHPUnit_Framework_TestCase /** */ -/* public function testAnalyseSqlAndScript() + public function testEncodeDecode() { - global $conf,$user,$langs,$db; - $conf=$this->savconf; - $user=$this->savuser; - $langs=$this->savlangs; - $db=$this->savdb; + $stringtotest="This is a string to test encode/decode"; - $_GET["param1"]="azert"; - $_POST["param2"]="a/b#e(pr)qq-rr\cc"; - - $result=analyse_sql_and_script($_GET); - print __METHOD__." result=".$result."\n"; - $this->assertFalse($result); // False because mail send disabled + $encodedstring=dol_encode($stringtotest); + $decodedstring=dol_decode($encodedstring); + print __METHOD__." encodedstring=".$encodedstring." ".base64_encode($stringtotest)."\n"; + $this->assertEquals($stringtotest,$decodedstring); + + return $result; + } + + /** + */ + public function testGetRandomPassword() + { + global $conf; + + $genpass1=getRandomPassword(true); // Should be a MD5 string return by dol_hash + print __METHOD__." genpass1=".$genpass1."\n"; + $this->assertEquals(strlen($genpass1),32); + + $conf->global->USER_PASSWORD_GENERATED='None'; + $genpass2=getRandomPassword(false); // Should be an empty string + print __METHOD__." genpass2=".$genpass2."\n"; + $this->assertEquals($genpass2,''); + + $conf->global->USER_PASSWORD_GENERATED='Standard'; + $genpass3=getRandomPassword(false); + print __METHOD__." genpass3=".$genpass3."\n"; + $this->assertEquals(strlen($genpass3),8); return $result; } -*/ } ?> \ No newline at end of file