Tests are now compliant with php-cs-fixer (CamelCase for method, phpdoc valid)

This commit is contained in:
2023-04-13 22:22:46 +02:00
parent b017700d0a
commit 273db5f183
51 changed files with 3926 additions and 3637 deletions

View File

@@ -12,6 +12,7 @@ return $config->setRules([
//'strict_param' => true, //'strict_param' => true,
'array_syntax' => ['syntax' => 'short'], 'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'], 'concat_space' => ['spacing' => 'one'],
'php_unit_method_casing' => true,
]) ])
->setFinder($finder) ->setFinder($finder)
; ;

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,31 +11,33 @@ namespace Domframework\Tests;
use Domframework\Auth; use Domframework\Auth;
/** Test the authentication */ /**
* Test the authentication
*/
class AuthTest extends \PHPUnit_Framework_TestCase class AuthTest extends \PHPUnit_Framework_TestCase
{ {
public function test_page_1() public function testPage1()
{ {
$auth = new Auth(); $auth = new Auth();
$res = $auth->pageHTML("http://localhost"); $res = $auth->pageHTML("http://localhost");
$this->assertSame(!! strpos($res, "<form "), true); $this->assertSame(!! strpos($res, "<form "), true);
} }
public function test_Message() public function testMessage()
{ {
$auth = new Auth(); $auth = new Auth();
$res = $auth->pageHTML("http://localhost", "MESSAGE"); $res = $auth->pageHTML("http://localhost", "MESSAGE");
$this->assertSame(!! strpos($res, "MESSAGE"), true); $this->assertSame(!! strpos($res, "MESSAGE"), true);
} }
public function test_URL_1() public function testURL1()
{ {
$auth = new Auth(); $auth = new Auth();
$res = $auth->pageHTML("http://localhost", "MESSAGE", "URL/TEST"); $res = $auth->pageHTML("http://localhost", "MESSAGE", "URL/TEST");
$this->assertSame(!! strpos($res, "URL/TEST"), true); $this->assertSame(!! strpos($res, "URL/TEST"), true);
} }
public function test_alreadyAuth_1() public function testAlreadyAuth1()
{ {
// Not Authenticated // Not Authenticated
$auth = new Auth(); $auth = new Auth();
@@ -42,7 +45,7 @@ class AuthTest extends \PHPUnit_Framework_TestCase
$this->assertSame(!! strpos($res, "Please sign in"), true); $this->assertSame(!! strpos($res, "Please sign in"), true);
} }
public function test_alreadyAuth_2() public function testAlreadyAuth2()
{ {
// Authenticated // Authenticated
$auth = new Auth(); $auth = new Auth();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Authhtpasswd; use Domframework\Authhtpasswd;
/** Test the Authhtpasswd.php file */ /**
* Test the Authhtpasswd.php file
*/
class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
{ {
public function test_clean() public function testClean()
{ {
if (file_exists("/tmp/htpasswd.file")) { if (file_exists("/tmp/htpasswd.file")) {
unlink("/tmp/htpasswd.file"); unlink("/tmp/htpasswd.file");
@@ -27,7 +30,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_connect() public function testConnect()
{ {
$authhtpasswd = new Authhtpasswd(); $authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file"; $authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
@@ -35,7 +38,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, null); $this->assertSame($res, null);
} }
public function test_authentication1() public function testAuthentication1()
{ {
$authhtpasswd = new Authhtpasswd(); $authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file"; $authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
@@ -43,7 +46,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_authentication2() public function testAuthentication2()
{ {
$authhtpasswd = new Authhtpasswd(); $authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file"; $authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
@@ -51,7 +54,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
$res = $authhtpasswd->authentication("UNKNOWN@toto.com", "toto123"); $res = $authhtpasswd->authentication("UNKNOWN@toto.com", "toto123");
} }
public function test_authentication3() public function testAuthentication3()
{ {
$authhtpasswd = new Authhtpasswd(); $authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file"; $authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
@@ -59,7 +62,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
$res = $authhtpasswd->authentication("toto@toto.com", "BAD PASSWD"); $res = $authhtpasswd->authentication("toto@toto.com", "BAD PASSWD");
} }
public function test_authentication4() public function testAuthentication4()
{ {
$authhtpasswd = new Authhtpasswd(); $authhtpasswd = new Authhtpasswd();
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file"; $authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,16 +11,26 @@ namespace Domframework\Tests;
use Domframework\Authjwt; use Domframework\Authjwt;
/** Test the Authjwt.php file */ /**
* Test the Authjwt.php file
*/
class AuthjwtTest extends \PHPUnit_Framework_TestCase class AuthjwtTest extends \PHPUnit_Framework_TestCase
{ {
/** @var string */ /**
* @var string
*/
private $cacheDir; private $cacheDir;
/** @var string */ /**
* @var string
*/
private $serverKey; private $serverKey;
/** @var string */ /**
* @var string
*/
private $cipherKey; private $cipherKey;
/** @var string */ /**
* @var string
*/
private $token; private $token;
public function __construct() public function __construct()

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Authsympa; use Domframework\Authsympa;
/** Test the authentication on Sympa Service */ /**
* Test the authentication on Sympa Service
*/
class AuthsympaTest extends \PHPUnit_Framework_TestCase class AuthsympaTest extends \PHPUnit_Framework_TestCase
{ {
public function test_connect_1() public function testConnect1()
{ {
// Empty // Empty
$authsympa = new Authsympa(); $authsympa = new Authsympa();
@@ -21,7 +24,7 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
$authsympa->connect(); $authsympa->connect();
} }
public function test_connect_2() public function testConnect2()
{ {
$authsympa = new Authsympa(); $authsympa = new Authsympa();
$authsympa->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl"; $authsympa->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl";
@@ -30,7 +33,7 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, null); $this->assertSame($res, null);
} }
public function test_auth_1() public function testAuth1()
{ {
// Invalid password // Invalid password
$authsympa = new Authsympa(); $authsympa = new Authsympa();
@@ -41,7 +44,7 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
$res = $authsympa->authentication("richard.heral@grenoble.cnrs.fr", "XXXX"); $res = $authsympa->authentication("richard.heral@grenoble.cnrs.fr", "XXXX");
} }
public function test_auth_2() public function testAuth2()
{ {
// Unknown user // Unknown user
$authsympa = new Authsympa(); $authsympa = new Authsympa();
@@ -52,7 +55,7 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
$res = $authsympa->authentication("Unknown@grenoble.cnrs.fr", "XXXX"); $res = $authsympa->authentication("Unknown@grenoble.cnrs.fr", "XXXX");
} }
public function test_auth_3() public function testAuth3()
{ {
// OK ! // OK !
$authsympa = new Authsympa(); $authsympa = new Authsympa();
@@ -63,7 +66,7 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_auth_4() public function testAuth4()
{ {
// Unknown list // Unknown list
$authsympa = new Authsympa(); $authsympa = new Authsympa();
@@ -74,7 +77,7 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
$res = $authsympa->authentication("richard.heral@grenoble.cnrs.fr", "Lavchdn8!"); $res = $authsympa->authentication("richard.heral@grenoble.cnrs.fr", "Lavchdn8!");
} }
public function test_auth_5() public function testAuth5()
{ {
// User not in list // User not in list
$authsympa = new Authsympa(); $authsympa = new Authsympa();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,31 +11,33 @@ namespace Domframework\Tests;
use Domframework\Authzgroups; use Domframework\Authzgroups;
/** Test the Authzgroups.php file */ /**
* Test the Authzgroups.php file
*/
class AuthzgroupsTest extends \PHPUnit_Framework_TestCase class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
{ {
private $dbconfig = array ( private $dbconfig = [
"dsn" => "sqlite:/tmp/databaseAuthzGroups.db", "dsn" => "sqlite:/tmp/databaseAuthzGroups.db",
"username" => null, "username" => null,
"password" => null, "password" => null,
"driver_options" => null, "driver_options" => null,
"tableprefix" => "", "tableprefix" => "",
); ];
public function test_Initialization() public function testInitialization()
{ {
if (file_exists("/tmp/databaseAuthzGroups.db")) { if (file_exists("/tmp/databaseAuthzGroups.db")) {
unlink("/tmp/databaseAuthzGroups.db"); unlink("/tmp/databaseAuthzGroups.db");
} }
} }
public function test_createTables1() public function testCreateTables1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$authz->createTables(); $authz->createTables();
} }
public function test_connect() public function testConnect()
{ {
// Must use the model to create the database structure as there is no // Must use the model to create the database structure as there is no
// creation of tables in controller // creation of tables in controller
@@ -48,7 +51,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_createTables2() public function testCreateTables2()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -64,7 +67,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
//////////////// ////////////////
// OBJECT // // OBJECT //
//////////////// ////////////////
public function test_objectCreate1() public function testObjectCreate1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -77,7 +80,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("1", $res); $this->assertSame("1", $res);
} }
public function test_objectUpdate1() public function testObjectUpdate1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -90,7 +93,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_objectDelete1() public function testObjectDelete1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -107,7 +110,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
//////////////// ////////////////
// GROUPS // // GROUPS //
//////////////// ////////////////
public function test_groupCreate1() public function testGroupCreate1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -120,7 +123,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("1", $res); $this->assertSame("1", $res);
} }
public function test_groupUpdate1() public function testGroupUpdate1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -133,7 +136,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_groupDelete1() public function testGroupDelete1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -150,7 +153,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
///////////////////// /////////////////////
// GROUPMEMBER // // GROUPMEMBER //
///////////////////// /////////////////////
public function test_groupmemberCreate1() public function testGroupmemberCreate1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -164,7 +167,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$res = $authz->groupmemberAdd("MODULE", "group", "userKnown"); $res = $authz->groupmemberAdd("MODULE", "group", "userKnown");
} }
public function test_groupmemberCreate2() public function testGroupmemberCreate2()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -177,7 +180,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("1", $res); $this->assertSame("1", $res);
} }
public function test_groupmemberDelete1() public function testGroupmemberDelete1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -191,7 +194,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$res = $authz->groupmemberDel("MODULE", "group", "userKnown"); $res = $authz->groupmemberDel("MODULE", "group", "userKnown");
} }
public function test_groupmemberReadGroup1() public function testGroupmemberReadGroup1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -205,7 +208,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$res = $authz->groupmemberReadGroup("MODULE", "group"); $res = $authz->groupmemberReadGroup("MODULE", "group");
} }
public function test_groupmemberReadGroup2() public function testGroupmemberReadGroup2()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -215,10 +218,10 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->dbconfig["driver_options"] $this->dbconfig["driver_options"]
); );
$res = $authz->groupmemberReadGroup("MODULE", "group2"); $res = $authz->groupmemberReadGroup("MODULE", "group2");
$this->assertSame(array (array ("user" => "userKnown")), $res); $this->assertSame([["user" => "userKnown"]], $res);
} }
public function test_groupmemberReadUser1() public function testGroupmemberReadUser1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -228,13 +231,13 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->dbconfig["driver_options"] $this->dbconfig["driver_options"]
); );
$res = $authz->groupmemberReadUser("MODULE", "userKnown"); $res = $authz->groupmemberReadUser("MODULE", "userKnown");
$this->assertSame(array (1 => "group2"), $res); $this->assertSame([1 => "group2"], $res);
} }
//////////////// ////////////////
// RIGHTS // // RIGHTS //
//////////////// ////////////////
public function test_rightCreate1() public function testRightCreate1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -247,7 +250,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("1", $res); $this->assertSame("1", $res);
} }
public function test_rightUpdate1() public function testRightUpdate1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -260,7 +263,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_rightDelete1() public function testRightDelete1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -278,7 +281,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
////////////////////////////////////////////// //////////////////////////////////////////////
// CLEANING DATABASE : REMOVING ENTRIES // // CLEANING DATABASE : REMOVING ENTRIES //
////////////////////////////////////////////// //////////////////////////////////////////////
public function test_deleteGroupmember2() public function testDeleteGroupmember2()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -291,7 +294,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_deleteObject2() public function testDeleteObject2()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -304,7 +307,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_deleteGroup2() public function testDeleteGroup2()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -320,7 +323,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
///////////////////// /////////////////////
// USER RIGHTS // // USER RIGHTS //
///////////////////// /////////////////////
public function test_userrightsget1() public function testUserrightsget1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -349,10 +352,10 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$authz->rightAdd("MODULE1", "group3", "/rep1/rep2", "RO"); $authz->rightAdd("MODULE1", "group3", "/rep1/rep2", "RO");
$res = $authz->userrightsget("MODULE1", "userKnown"); $res = $authz->userrightsget("MODULE1", "userKnown");
$this->assertSame(array ("/rep1/rep2" => "RW"), $res); $this->assertSame(["/rep1/rep2" => "RW"], $res);
} }
public function test_allow1() public function testAllow1()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -365,7 +368,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("RW", $res); $this->assertSame("RW", $res);
} }
public function test_allow2() public function testAllow2()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -379,7 +382,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("RW", $res); $this->assertSame("RW", $res);
} }
public function test_allow3() public function testAllow3()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(
@@ -393,7 +396,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("RW", $res); $this->assertSame("RW", $res);
} }
public function test_allow4() public function testAllow4()
{ {
$authz = new Authzgroups(); $authz = new Authzgroups();
$authz->connect( $authz->connect(

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,16 +11,18 @@ namespace Domframework\Tests;
use Domframework\Authzgroupsoo; use Domframework\Authzgroupsoo;
/** Test the Authzgroupsoo.php file */ /**
* Test the Authzgroupsoo.php file
*/
class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
{ {
private $dbconfig = array ( private $dbconfig = [
"dsn" => "sqlite:/tmp/databaseAuthzGroupsoo.db", "dsn" => "sqlite:/tmp/databaseAuthzGroupsoo.db",
"username" => null, "username" => null,
"password" => null, "password" => null,
"driver_options" => null, "driver_options" => null,
"tableprefix" => "", "tableprefix" => "",
); ];
public function testInitialization() public function testInitialization()
{ {
if (file_exists("/tmp/databaseAuthzGroupsoo.db")) { if (file_exists("/tmp/databaseAuthzGroupsoo.db")) {
@@ -215,7 +218,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
$this->dbconfig["driver_options"] $this->dbconfig["driver_options"]
); );
$res = $authz->groupmemberReadGroup("MODULE", "group2"); $res = $authz->groupmemberReadGroup("MODULE", "group2");
$this->assertSame(array (array ("user" => "userKnown")), $res); $this->assertSame([["user" => "userKnown"]], $res);
} }
public function testGroupmemberReadUser1() public function testGroupmemberReadUser1()
@@ -228,7 +231,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
$this->dbconfig["driver_options"] $this->dbconfig["driver_options"]
); );
$res = $authz->groupmemberReadUser("MODULE", "userKnown"); $res = $authz->groupmemberReadUser("MODULE", "userKnown");
$this->assertSame(array (1 => "group2"), $res); $this->assertSame([1 => "group2"], $res);
} }
//////////////// ////////////////
@@ -349,7 +352,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
$authz->rightAdd("MODULE1", "group3", "/rep1/rep2", "RO"); $authz->rightAdd("MODULE1", "group3", "/rep1/rep2", "RO");
$res = $authz->userrightsget("MODULE1", "userKnown"); $res = $authz->userrightsget("MODULE1", "userKnown");
$this->assertSame(array ("/rep1/rep2" => "RW"), $res); $this->assertSame(["/rep1/rep2" => "RW"], $res);
} }
public function testAllow1() public function testAllow1()

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Cachefile; use Domframework\Cachefile;
/** Test the Cachefile.php file */ /**
* Test the Cachefile.php file
*/
class CachefileTest extends \PHPUnit_Framework_TestCase class CachefileTest extends \PHPUnit_Framework_TestCase
{ {
public function testInit() public function testInit()

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,11 +11,12 @@ namespace Domframework\Tests;
use Domframework\Certificationauthority; use Domframework\Certificationauthority;
/** Test the certification Authority /**
* Test the certification Authority
*/ */
class CertificationauthorityTest extends \PHPUnit_Framework_TestCase class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
{ {
public function test_createCA_1() public function testCreateCA1()
{ {
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST"); $certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
@@ -27,7 +29,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_createCA_2() public function testCreateCA2()
{ {
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST"); $certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
@@ -42,7 +44,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_createPK_1() public function testCreatePK1()
{ {
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
$privateKey = $certificationauthority->createPrivateKey() -> privateKey(); $privateKey = $certificationauthority->createPrivateKey() -> privateKey();
@@ -50,7 +52,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($privateKey[0], "-----BEGIN PRIVATE KEY-----"); $this->assertSame($privateKey[0], "-----BEGIN PRIVATE KEY-----");
} }
public function test_createCSR_1() public function testCreateCSR1()
{ {
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
$csr = $certificationauthority->createCSR("FR", "FOURNIER38", "CSR"); $csr = $certificationauthority->createCSR("FR", "FOURNIER38", "CSR");
@@ -58,7 +60,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($csr[0], "-----BEGIN CERTIFICATE REQUEST-----"); $this->assertSame($csr[0], "-----BEGIN CERTIFICATE REQUEST-----");
} }
public function test_signCSR_1() public function testSignCSR1()
{ {
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST"); $certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
@@ -70,7 +72,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($cert[0], "-----BEGIN CERTIFICATE-----"); $this->assertSame($cert[0], "-----BEGIN CERTIFICATE-----");
} }
public function test_signCSR_2() public function testSignCSR2()
{ {
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST"); $certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
@@ -88,7 +90,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_signCSR_3() public function testSignCSR3()
{ {
// Check if generated cert X509v3 Extended Key Usage are valid // Check if generated cert X509v3 Extended Key Usage are valid
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
@@ -107,7 +109,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_signCSR_4() public function testSignCSR4()
{ {
// Check if generated cert issuer name is valid // Check if generated cert issuer name is valid
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
@@ -126,7 +128,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_signCSR_5() public function testSignCSR5()
{ {
// Check if generated cert is not tagged CA // Check if generated cert is not tagged CA
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();
@@ -145,7 +147,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_signCSR_6() public function testSignCSR6()
{ {
// Check if generated cert has Alternative Names // Check if generated cert has Alternative Names
$certificationauthority = new Certificationauthority(); $certificationauthority = new Certificationauthority();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Config; use Domframework\Config;
/** Test the Config.php file */ /**
* Test the Config.php file
*/
class ConfigTest extends \PHPUnit_Framework_TestCase class ConfigTest extends \PHPUnit_Framework_TestCase
{ {
public function testExternFile() public function testExternFile()
@@ -24,38 +27,38 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
{ {
$c = new Config(); $c = new Config();
$res = $c->params(); $res = $c->params();
$this->assertSame(array (), $res); $this->assertSame([], $res);
} }
public function testGet1() public function testGet1()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"username" => null, "username" => null,
"password" => null, "password" => null,
"driver_options" => null, "driver_options" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$res = $c->get("database"); $res = $c->get("database");
$this->assertSame(array ( $this->assertSame([
"dsn" => null, "dsn" => null,
"username" => null, "username" => null,
"password" => null, "password" => null,
"driver_options" => null, "driver_options" => null,
"tableprefix" => ""), $res); "tableprefix" => ""], $res);
} }
public function testSet1() public function testSet1()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$res = $c->set("database", array ("dsn" => 1,"tableprefix" => 3)); $res = $c->set("database", ["dsn" => 1,"tableprefix" => 3]);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
@@ -63,99 +66,111 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$res = $c->get("database"); $res = $c->get("database");
$this->assertSame(array ( $this->assertSame([
"dsn" => 1, "dsn" => 1,
"tableprefix" => 3), $res); "tableprefix" => 3], $res);
} }
/** Can't create file */ /**
* Can't create file
*/
public function testGet3() public function testGet3()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/1/2.3/dd/testconf.php"; $c->confFile = "/tmp/1/2.3/dd/testconf.php";
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $c->get("database"); $res = $c->get("database");
} }
/** Can't read the file */ /**
* Can't read the file
*/
public function testGet4() public function testGet4()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0222); chmod("/tmp/testconf.php", 0222);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $c->get("database"); $res = $c->get("database");
} }
/** File non exists and can not be created */ /**
* File non exists and can not be created
*/
public function testSet2() public function testSet2()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/1/2.3/dd/testconf.php"; $c->confFile = "/tmp/1/2.3/dd/testconf.php";
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $c->set("database", array ("dsn" => 1,"tableprefix" => 3)); $res = $c->set("database", ["dsn" => 1,"tableprefix" => 3]);
} }
/** Can't read the file */ /**
* Can't read the file
*/
public function testSet3() public function testSet3()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0222); chmod("/tmp/testconf.php", 0222);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $c->set("database", array ("dsn" => 1,"tableprefix" => 3)); $res = $c->set("database", ["dsn" => 1,"tableprefix" => 3]);
} }
/** Can't write the file */ /**
* Can't write the file
*/
public function testSet4() public function testSet4()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0444); chmod("/tmp/testconf.php", 0444);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $c->set("database", array ("dsn" => 1,"tableprefix" => 3)); $res = $c->set("database", ["dsn" => 1,"tableprefix" => 3]);
} }
/** Save TRUE/FALSE/NULL/String values */ /**
* Save TRUE/FALSE/NULL/String values
*/
public function testSet5() public function testSet5()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0666); chmod("/tmp/testconf.php", 0666);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"user" => null, "user" => null,
"password" => null, "password" => null,
"tableprefix" => "")); "tableprefix" => ""]];
$res = $c->set("database", array ("dsn" => true, "user" => null, $res = $c->set("database", ["dsn" => true, "user" => null,
"password" => "text", "password" => "text",
"tableprefix" => false)); "tableprefix" => false]);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
@@ -164,24 +179,24 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0666); chmod("/tmp/testconf.php", 0666);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"user" => null, "user" => null,
"password" => null, "password" => null,
"tableprefix" => ""), "tableprefix" => ""],
"servers" => array ( "servers" => [
"not configured" => array ( "not configured" => [
"type" => "bind", "type" => "bind",
"username" => "", "username" => "",
), ],
) ]
); ];
$res = $c->get("servers"); $res = $c->get("servers");
$this->assertSame($res, array ("not configured" => array ( $this->assertSame($res, ["not configured" => [
"type" => "bind", "type" => "bind",
"username" => "", "username" => "",
))); ]]);
} }
public function testSet7() public function testSet7()
@@ -189,49 +204,49 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0666); chmod("/tmp/testconf.php", 0666);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"user" => null, "user" => null,
"password" => null, "password" => null,
"tableprefix" => ""), "tableprefix" => ""],
"servers" => array ( "servers" => [
"not configured" => array ( "not configured" => [
"type" => "bind", "type" => "bind",
"username" => "", "username" => "",
), ],
) ]
); ];
$res = $c->set("servers", array ( $res = $c->set("servers", [
"127.0.0.1" => array ( "127.0.0.1" => [
"type" => "BIND", "type" => "BIND",
"username" => "toto", "username" => "toto",
))); ]]);
} }
public function testGet7() public function testGet7()
{ {
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0666); chmod("/tmp/testconf.php", 0666);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"user" => null, "user" => null,
"password" => null, "password" => null,
"tableprefix" => ""), "tableprefix" => ""],
"servers" => array ( "servers" => [
"not configured" => array ( "not configured" => [
"type" => "bind", "type" => "bind",
"username" => "", "username" => "",
), ],
) ]
); ];
$res = $c->get("servers"); $res = $c->get("servers");
$this->assertSame($res, array ( $this->assertSame($res, [
"127.0.0.1" => array ( "127.0.0.1" => [
"type" => "BIND", "type" => "BIND",
"username" => "toto", "username" => "toto",
))); ]]);
} }
public function testGet8() public function testGet8()
@@ -239,26 +254,26 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
$c = new Config(); $c = new Config();
$c->confFile = "/tmp/testconf.php"; $c->confFile = "/tmp/testconf.php";
chmod("/tmp/testconf.php", 0666); chmod("/tmp/testconf.php", 0666);
$c->default = array ( $c->default = [
"database" => array ( "database" => [
"dsn" => null, "dsn" => null,
"user" => null, "user" => null,
"password" => null, "password" => null,
"tableprefix" => ""), "tableprefix" => ""],
"servers" => array ( "servers" => [
"not configured" => array ( "not configured" => [
"type" => "bind", "type" => "bind",
"username" => "", "username" => "",
"password" => "", "password" => "",
), ],
) ]
); ];
$res = $c->get("servers"); $res = $c->get("servers");
$this->assertSame($res, array ( $this->assertSame($res, [
"127.0.0.1" => array ( "127.0.0.1" => [
"type" => "BIND", "type" => "BIND",
"username" => "toto", "username" => "toto",
"password" => "", "password" => "",
))); ]]);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,58 +11,60 @@ namespace Domframework\Tests;
use Domframework\Convert; use Domframework\Convert;
/** Test the Conversion of format */ /**
* Test the Conversion of format
*/
class ConvertTest extends \PHPUnit_Framework_TestCase class ConvertTest extends \PHPUnit_Framework_TestCase
{ {
public function test_convertDate1() public function testConvertDate1()
{ {
$res = Convert::convertDate("2017-04-13", "Y-m-d", "d/m/Y"); $res = Convert::convertDate("2017-04-13", "Y-m-d", "d/m/Y");
$this->assertSame($res, "13/04/2017"); $this->assertSame($res, "13/04/2017");
} }
public function test_convertDate2() public function testConvertDate2()
{ {
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = Convert::convertDate("2017-13-33", "Y-m-d", "d/m/Y"); $res = Convert::convertDate("2017-13-33", "Y-m-d", "d/m/Y");
} }
public function test_convertDate3() public function testConvertDate3()
{ {
$res = Convert::convertDate("2017-13-33", "Y-m-d", "d/m/Y", false); $res = Convert::convertDate("2017-13-33", "Y-m-d", "d/m/Y", false);
$this->assertSame($res, "2017-13-33"); $this->assertSame($res, "2017-13-33");
} }
public function test_ucwords_1() public function testUcwords1()
{ {
$res = Convert::ucwords(" test yuyu "); $res = Convert::ucwords(" test yuyu ");
$this->assertSame($res, " Test Yuyu "); $this->assertSame($res, " Test Yuyu ");
} }
public function test_ucwords_2() public function testUcwords2()
{ {
$res = Convert::ucwords(""); $res = Convert::ucwords("");
$this->assertSame($res, ""); $this->assertSame($res, "");
} }
public function test_ucwords_3() public function testUcwords3()
{ {
$res = Convert::ucwords("test"); $res = Convert::ucwords("test");
$this->assertSame($res, "Test"); $this->assertSame($res, "Test");
} }
public function test_ucwords_4() public function testUcwords4()
{ {
$res = Convert::ucwords("TEST"); $res = Convert::ucwords("TEST");
$this->assertSame($res, "Test"); $this->assertSame($res, "Test");
} }
public function test_ucwords_5() public function testUcwords5()
{ {
$res = Convert::ucwords("édouard étienne"); $res = Convert::ucwords("édouard étienne");
$this->assertSame($res, "Édouard Étienne"); $this->assertSame($res, "Édouard Étienne");
} }
public function test_ucwords_6() public function testUcwords6()
{ {
$res = Convert::ucwords("édou-ard d'étienne", " -'"); $res = Convert::ucwords("édou-ard d'étienne", " -'");
$this->assertSame($res, "Édou-Ard D'Étienne"); $this->assertSame($res, "Édou-Ard D'Étienne");
@@ -70,7 +73,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
///////////////////// /////////////////////
// humanSize // // humanSize //
///////////////////// /////////////////////
public function test_humanSize_1() public function testHumanSize1()
{ {
$res = ""; $res = "";
for ($i = -8; $i <= 8; $i++) { for ($i = -8; $i <= 8; $i++) {
@@ -81,47 +84,47 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
"1.44ZB\n1.44YB\n"); "1.44ZB\n1.44YB\n");
} }
public function test_humanSize_2() public function testHumanSize2()
{ {
$res = Convert::humanSize(1441234); $res = Convert::humanSize(1441234);
$this->assertSame($res, "1.44MB"); $this->assertSame($res, "1.44MB");
} }
public function test_humanSize_3() public function testHumanSize3()
{ {
$res = Convert::humanSize(10441234); $res = Convert::humanSize(10441234);
$this->assertSame($res, "10.44MB"); $this->assertSame($res, "10.44MB");
} }
public function test_humanSize_4() public function testHumanSize4()
{ {
$res = Convert::humanSize(0.123, 0); $res = Convert::humanSize(0.123, 0);
$this->assertSame($res, "123mB"); $this->assertSame($res, "123mB");
} }
public function test_humanSize_5() public function testHumanSize5()
{ {
$res = Convert::humanSize(0.12345, 2); $res = Convert::humanSize(0.12345, 2);
$this->assertSame($res, "123.45mB"); $this->assertSame($res, "123.45mB");
} }
public function test_humanSize_6() public function testHumanSize6()
{ {
$res = Convert::humanSize(-0.12345, 2); $res = Convert::humanSize(-0.12345, 2);
$this->assertSame($res, "-123.45mB"); $this->assertSame($res, "-123.45mB");
} }
public function test_humanSize_7() public function testHumanSize7()
{ {
$res = Convert::humanSize(-12345, 2); $res = Convert::humanSize(-12345, 2);
$this->assertSame($res, "-12.35kB"); $this->assertSame($res, "-12.35kB");
} }
public function test_humanSize_8() public function testHumanSize8()
{ {
$res = Convert::humanSize(0, 2); $res = Convert::humanSize(0, 2);
$this->assertSame($res, "0.00B"); $this->assertSame($res, "0.00B");
} }
public function test_humanSize_error1() public function testHumanSizeError1()
{ {
$this->expectException( $this->expectException(
"Exception", "Exception",
@@ -131,7 +134,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
$res = Convert::humanSize("1441234"); $res = Convert::humanSize("1441234");
} }
public function test_humanSize_error2() public function testHumanSizeError2()
{ {
$this->expectException( $this->expectException(
"Exception", "Exception",
@@ -141,7 +144,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
$res = Convert::humanSize(1441234, 0.1); $res = Convert::humanSize(1441234, 0.1);
} }
public function test_humanSize_error3() public function testHumanSizeError3()
{ {
$this->expectException( $this->expectException(
"Exception", "Exception",
@@ -151,7 +154,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
$res = Convert::humanSize(1441234, -1); $res = Convert::humanSize(1441234, -1);
} }
public function test_humanSize_error4() public function testHumanSizeError4()
{ {
$this->expectException( $this->expectException(
"Exception", "Exception",

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Csrf; use Domframework\Csrf;
/** Test the Csrf.php file */ /**
* Test the Csrf.php file
*/
class CsrfTest extends \PHPUnit_Framework_TestCase class CsrfTest extends \PHPUnit_Framework_TestCase
{ {
public function test_csrf1() public function testCsrf1()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$res = $csrf->createToken(); $res = $csrf->createToken();
@@ -21,7 +24,7 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
$this->assertSame(30, strlen($res)); $this->assertSame(30, strlen($res));
} }
public function test_csrf2() public function testCsrf2()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$res = $csrf->createToken(); $res = $csrf->createToken();
@@ -34,14 +37,14 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_csrf3() public function testCsrf3()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $csrf->checkToken("NOT VALID TOKEN"); $res = $csrf->checkToken("NOT VALID TOKEN");
} }
public function test_csrf4() public function testCsrf4()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$token = $csrf->createToken(); $token = $csrf->createToken();
@@ -49,7 +52,7 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_csrf5() public function testCsrf5()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$token = $csrf->createToken(); $token = $csrf->createToken();
@@ -57,7 +60,7 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_csrf6() public function testCsrf6()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$token = $csrf->createToken(); $token = $csrf->createToken();
@@ -65,14 +68,14 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
$this->assertSame($token, $res); $this->assertSame($token, $res);
} }
public function test_csrf7() public function testCsrf7()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$res = $csrf->getToken(); $res = $csrf->getToken();
$this->assertSame(30, strlen($res)); $this->assertSame(30, strlen($res));
} }
public function test_csrf_multiple_1() public function testCsrfMultiple1()
{ {
$csrf1 = new Csrf(); $csrf1 = new Csrf();
$token1 = $csrf1->createToken(); $token1 = $csrf1->createToken();
@@ -84,14 +87,14 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_csrf_multiple_extend_2() public function testCsrfMultipleExtend2()
{ {
$csrf = new Csrf(); $csrf = new Csrf();
$res = $csrf->extendToken($GLOBALS["CSRFTEST-Token"]); $res = $csrf->extendToken($GLOBALS["CSRFTEST-Token"]);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_csrf_multiple_get() public function testCsrfMultipleGet()
{ {
$csrf1 = new Csrf(); $csrf1 = new Csrf();
$token1 = $csrf1->createToken(); $token1 = $csrf1->createToken();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,407 +11,409 @@ namespace Domframework\Tests;
use Domframework\Dbjson; use Domframework\Dbjson;
/** Test the Dbjson database */ /**
* Test the Dbjson database
*/
class DbjsonTest extends \PHPUnit_Framework_TestCase class DbjsonTest extends \PHPUnit_Framework_TestCase
{ {
public function test_insertOne1() public function testInsertOne1()
{ {
// Document #0 // Document #0
define("dbfile", "/tmp/dbjson-" . time()); define("dbfile", "/tmp/dbjson-" . time());
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->insertOne( $res = $dbjson->insertOne(
"collection", "collection",
array ("key1" => "val1", "key2" => "val2") ["key1" => "val1", "key2" => "val2"]
); );
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_insertOne2() public function testInsertOne2()
{ {
// Document #1 // Document #1
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->insertOne( $res = $dbjson->insertOne(
"collection", "collection",
array ("key1" => "val1", "key2" => "val2") ["key1" => "val1", "key2" => "val2"]
); );
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_insertMany1() public function testInsertMany1()
{ {
// Error : Invalid array provided (not array of array) // Error : Invalid array provided (not array of array)
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->insertMany( $res = $dbjson->insertMany(
"collection", "collection",
array ("key1" => "val1", "key2" => "val2") ["key1" => "val1", "key2" => "val2"]
); );
} }
public function test_insertMany2() public function testInsertMany2()
{ {
// Document #2 and #3 // Document #2 and #3
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->insertMany( $res = $dbjson->insertMany(
"collection", "collection",
array (array ("key1" => "val3", "key2" => "val2"), [["key1" => "val3", "key2" => "val2"],
array ("key1" => "val3", "key2" => "val4")) ["key1" => "val3", "key2" => "val4"]]
); );
$this->assertSame($res, 2); $this->assertSame($res, 2);
} }
public function test_filter1() public function testFilter1()
{ {
// Return all the keys (filter = array ()) // Return all the keys (filter = array ())
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->filter("collection", array ()); $res = $dbjson->filter("collection", []);
$this->assertSame(array_keys($res), array (0,1,2,3)); $this->assertSame(array_keys($res), [0,1,2,3]);
} }
public function test_filter2() public function testFilter2()
{ {
// Return the keys where filter = array ("key2"=>"val2")) // Return the keys where filter = array ("key2"=>"val2"))
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->filter("collection", array ("key2" => "val2")); $res = $dbjson->filter("collection", ["key2" => "val2"]);
$this->assertSame(array_keys($res), array (0,1,2)); $this->assertSame(array_keys($res), [0,1,2]);
} }
public function test_filter3() public function testFilter3()
{ {
// Return the keys where filter = array ("key1"=>"val3","key2"=>"val2")) // Return the keys where filter = array ("key1"=>"val3","key2"=>"val2"))
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->filter("collection", array ("key1" => "val3", $res = $dbjson->filter("collection", ["key1" => "val3",
"key2" => "val2")); "key2" => "val2"]);
$this->assertSame(count($res), 1); $this->assertSame(count($res), 1);
} }
public function test_filter4() public function testFilter4()
{ {
// Return the keys where filter = array ("key1"=>array ("val3", "=="), // Return the keys where filter = array ("key1"=>array ("val3", "=="),
// "key2"=>array ("val2", "==")) // "key2"=>array ("val2", "=="))
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->filter("collection", array ("key1" => array ("val3", "=="), $res = $dbjson->filter("collection", ["key1" => ["val3", "=="],
"key2" => array ("val2", "=="))); "key2" => ["val2", "=="]]);
$this->assertSame(count($res), 1); $this->assertSame(count($res), 1);
} }
public function test_filter5() public function testFilter5()
{ {
// Return the keys where filter = array ("key1"=>array ("val3", "<="), // Return the keys where filter = array ("key1"=>array ("val3", "<="),
// "key2"=>array ("val2", "==")) // "key2"=>array ("val2", "=="))
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->filter("collection", array ("key1" => array ("val3", "<="), $res = $dbjson->filter("collection", ["key1" => ["val3", "<="],
"key2" => array ("val2", "=="))); "key2" => ["val2", "=="]]);
$this->assertSame(array_keys($res), array (0,1,2)); $this->assertSame(array_keys($res), [0,1,2]);
} }
public function test_filter6() public function testFilter6()
{ {
// Return the keys where filter = array ("key1"=>array ("val3", "<="), // Return the keys where filter = array ("key1"=>array ("val3", "<="),
// "key2"=>array ("val2", ">")) // "key2"=>array ("val2", ">"))
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->filter("collection", array ("key1" => array ("val3", "<="), $res = $dbjson->filter("collection", ["key1" => ["val3", "<="],
"key2" => array ("val2", ">"))); "key2" => ["val2", ">"]]);
$this->assertSame(count($res), 1); $this->assertSame(count($res), 1);
} }
public function test_find1() public function testFind1()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find("collection", array ("key1" => array ("val3", "<="), $res = $dbjson->find("collection", ["key1" => ["val3", "<="],
"key2" => array ("val2", ">"))); "key2" => ["val2", ">"]]);
$res = array_values($res); $res = array_values($res);
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key1" => "val3", $this->assertSame($res, [0 => ["key1" => "val3",
"key2" => "val4"))); "key2" => "val4"]]);
} }
public function test_find2() public function testFind2()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", ">")), "key2" => ["val2", ">"]],
"*" "*"
); );
$res = array_values($res); $res = array_values($res);
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key1" => "val3", $this->assertSame($res, [0 => ["key1" => "val3",
"key2" => "val4"))); "key2" => "val4"]]);
} }
public function test_find3() public function testFind3()
{ {
// Exception : fields not an array // Exception : fields not an array
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", ">")), "key2" => ["val2", ">"]],
"key1" "key1"
); );
} }
public function test_find4() public function testFind4()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", ">")), "key2" => ["val2", ">"]],
array ("key1") ["key1"]
); );
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
$res = array_values($res); $res = array_values($res);
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key1" => "val3"))); $this->assertSame($res, [0 => ["key1" => "val3"]]);
} }
public function test_find5() public function testFind5()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", ">")), "key2" => ["val2", ">"]],
array ("key1", "key2") ["key1", "key2"]
); );
$res = array_values($res); $res = array_values($res);
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key1" => "val3", $this->assertSame($res, [0 => ["key1" => "val3",
"key2" => "val4"))); "key2" => "val4"]]);
} }
public function test_find6() public function testFind6()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", "==")), "key2" => ["val2", "=="]],
array ("key1", "key2") ["key1", "key2"]
); );
$res = array_values($res); $res = array_values($res);
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
unset($res[1]["_id"]); unset($res[1]["_id"]);
unset($res[2]["_id"]); unset($res[2]["_id"]);
$this->assertSame($res, array (0 => array ("key1" => "val1", $this->assertSame($res, [0 => ["key1" => "val1",
"key2" => "val2"), "key2" => "val2"],
1 => array ("key1" => "val1", 1 => ["key1" => "val1",
"key2" => "val2"), "key2" => "val2"],
2 => array ("key1" => "val3", 2 => ["key1" => "val3",
"key2" => "val2"))); "key2" => "val2"]]);
} }
public function test_find7() public function testFind7()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", "==")), "key2" => ["val2", "=="]],
array ("key2") ["key2"]
); );
$res = array_values($res); $res = array_values($res);
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
unset($res[1]["_id"]); unset($res[1]["_id"]);
unset($res[2]["_id"]); unset($res[2]["_id"]);
$this->assertSame($res, array (0 => array ("key2" => "val2"), $this->assertSame($res, [0 => ["key2" => "val2"],
1 => array ("key2" => "val2"), 1 => ["key2" => "val2"],
2 => array ("key2" => "val2"))); 2 => ["key2" => "val2"]]);
} }
public function test_find8() public function testFind8()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", "==")), "key2" => ["val2", "=="]],
array ("key2"), ["key2"],
1 1
); );
$res = array_values($res); $res = array_values($res);
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key2" => "val2"))); $this->assertSame($res, [0 => ["key2" => "val2"]]);
} }
public function test_deleteOne1() public function testDeleteOne1()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->deleteOne( $res = $dbjson->deleteOne(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", "key2" => ["val2",
"==")) "=="]]
); );
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_find9() public function testFind9()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", "==")), "key2" => ["val2", "=="]],
array ("key2") ["key2"]
); );
$res = array_values($res); $res = array_values($res);
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
unset($res[1]["_id"]); unset($res[1]["_id"]);
$this->assertSame($res, array (0 => array ("key2" => "val2"), $this->assertSame($res, [0 => ["key2" => "val2"],
1 => array ("key2" => "val2"))); 1 => ["key2" => "val2"]]);
} }
public function test_deleteMany1() public function testDeleteMany1()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->deleteMany( $res = $dbjson->deleteMany(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", "key2" => ["val2",
"==")) "=="]]
); );
$this->assertSame($res, 2); $this->assertSame($res, 2);
} }
public function test_find10() public function testFind10()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->find( $res = $dbjson->find(
"collection", "collection",
array ("key1" => array ("val3", "<="), ["key1" => ["val3", "<="],
"key2" => array ("val2", "==")), "key2" => ["val2", "=="]],
array ("key2") ["key2"]
); );
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[1]["_id"]); unset($res[1]["_id"]);
unset($res[2]["_id"]); unset($res[2]["_id"]);
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
public function test_find11() public function testFind11()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = array_values($dbjson->find("collection")); $res = array_values($dbjson->find("collection"));
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key1" => "val3", "key2" => "val4"))); $this->assertSame($res, [0 => ["key1" => "val3", "key2" => "val4"]]);
} }
public function test_replace1() public function testReplace1()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->replace("collection", array (), array ("key2" => "val5")); $res = $dbjson->replace("collection", [], ["key2" => "val5"]);
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_find12() public function testFind12()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = array_values($dbjson->find("collection")); $res = array_values($dbjson->find("collection"));
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key2" => "val5"))); $this->assertSame($res, [0 => ["key2" => "val5"]]);
} }
public function test_update1() public function testUpdate1()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->update("collection", array (), array ("key2" => "val6", $res = $dbjson->update("collection", [], ["key2" => "val6",
"key5" => "val5")); "key5" => "val5"]);
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_find13() public function testFind13()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = array_values($dbjson->find("collection")); $res = array_values($dbjson->find("collection"));
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
$this->assertSame($res, array (0 => array ("key2" => "val6", $this->assertSame($res, [0 => ["key2" => "val6",
"key5" => "val5"))); "key5" => "val5"]]);
} }
public function test_insertOne3() public function testInsertOne3()
{ {
// Document #4 // Document #4
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->insertOne( $res = $dbjson->insertOne(
"collection", "collection",
array ("key1" => "val1", "key2" => "val2") ["key1" => "val1", "key2" => "val2"]
); );
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_find14() public function testFind14()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = array_values($dbjson->find("collection")); $res = array_values($dbjson->find("collection"));
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
unset($res[1]["_id"]); unset($res[1]["_id"]);
$this->assertSame($res, array (0 => array ("key2" => "val6", $this->assertSame($res, [0 => ["key2" => "val6",
"key5" => "val5"), "key5" => "val5"],
1 => array ("key1" => "val1", 1 => ["key1" => "val1",
"key2" => "val2"))); "key2" => "val2"]]);
} }
public function test_update2() public function testUpdate2()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->update("collection", array (), array ("key2" => "val7", $res = $dbjson->update("collection", [], ["key2" => "val7",
"key5" => "val8")); "key5" => "val8"]);
$this->assertSame($res, 2); $this->assertSame($res, 2);
} }
public function test_find15() public function testFind15()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = array_values($dbjson->find("collection")); $res = array_values($dbjson->find("collection"));
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
unset($res[1]["_id"]); unset($res[1]["_id"]);
$this->assertSame($res, array (0 => array ("key2" => "val7", $this->assertSame($res, [0 => ["key2" => "val7",
"key5" => "val8"), "key5" => "val8"],
1 => array ("key1" => "val1", 1 => ["key1" => "val1",
"key2" => "val7", "key2" => "val7",
"key5" => "val8"))); "key5" => "val8"]]);
} }
public function test_update3() public function testUpdate3()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = $dbjson->update( $res = $dbjson->update(
"collection", "collection",
array (), [],
array ("key2" => "val9", ["key2" => "val9",
"key5" => "val7", "key5" => "val7",
"_unset" => array ("key2")) "_unset" => ["key2"]]
); );
$this->assertSame($res, 2); $this->assertSame($res, 2);
} }
public function test_find16() public function testFind16()
{ {
$dbjson = new Dbjson("dbjson://" . dbfile); $dbjson = new Dbjson("dbjson://" . dbfile);
$res = array_values($dbjson->find("collection")); $res = array_values($dbjson->find("collection"));
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
unset($res[1]["_id"]); unset($res[1]["_id"]);
$this->assertSame($res, array (0 => array ("key5" => "val7"), $this->assertSame($res, [0 => ["key5" => "val7"],
1 => array ("key1" => "val1", 1 => ["key1" => "val1",
"key5" => "val7"))); "key5" => "val7"]]);
} }
// Concurrency tests // Concurrency tests
public function test_concurrency1() public function testConcurrency1()
{ {
$dbjson1 = new Dbjson("dbjson://" . dbfile); $dbjson1 = new Dbjson("dbjson://" . dbfile);
$dbjson2 = new Dbjson("dbjson://" . dbfile); $dbjson2 = new Dbjson("dbjson://" . dbfile);
$dbjson1->insertOne( $dbjson1->insertOne(
"collection", "collection",
array ("key1" => "val1", "key2" => "val2") ["key1" => "val1", "key2" => "val2"]
); );
$res = array_values($dbjson2->find("collection")); $res = array_values($dbjson2->find("collection"));
// ["_id"] is random : skip the test // ["_id"] is random : skip the test
unset($res[0]["_id"]); unset($res[0]["_id"]);
unset($res[1]["_id"]); unset($res[1]["_id"]);
unset($res[2]["_id"]); unset($res[2]["_id"]);
$this->assertSame($res, array (0 => array ("key5" => "val7"), $this->assertSame($res, [0 => ["key5" => "val7"],
1 => array ("key1" => "val1", 1 => ["key1" => "val1",
"key5" => "val7"), "key5" => "val7"],
2 => array ("key1" => "val1", 2 => ["key1" => "val1",
"key2" => "val2"))); "key2" => "val2"]]);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -12,37 +13,39 @@ use Domframework\Dblayer;
class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
{ {
// Test with column name 'group', 'object', 'where', 'with space' // Test with column name 'group', 'object', 'where', 'with space'
// Test with table name 'group', 'object', 'where', 'with space' // Test with table name 'group', 'object', 'where', 'with space'
// For the 3 DB engines // For the 3 DB engines
public $engine = "{ENGINE}"; public $engine = "{ENGINE}";
public $confs = array ( public $confs = [
"sqlite" => array ( "sqlite" => [
"dsn" => "sqlite:/tmp/databaseDBLayer.db", "dsn" => "sqlite:/tmp/databaseDBLayer.db",
"username" => null, "username" => null,
"password" => null, "password" => null,
"driver_options" => null, "driver_options" => null,
"tableprefix" => "", "tableprefix" => "",
), ],
"mysql" => array ( "mysql" => [
"dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test", "dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test",
"username" => "root", "username" => "root",
"password" => "lqsym", "password" => "lqsym",
"driver_options" => null, "driver_options" => null,
"tableprefix" => "", "tableprefix" => "",
), ],
"pgsql" => array ( "pgsql" => [
"dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname", "dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname",
"username" => "root", "username" => "root",
"password" => "root", "password" => "root",
"driver_options" => null, "driver_options" => null,
"tableprefix" => "", "tableprefix" => "",
), ],
); ];
/** @group singleton */ /**
public function test_dropTable() * @group singleton
*/
public function testDropTable()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -52,8 +55,8 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
foreach ( foreach (
array ("users", "grouped", "multiple", "multiple2", "users3", ["users", "grouped", "multiple", "multiple2", "users3",
"readOR") as $table "readOR"] as $table
) { ) {
$db->table = $table; $db->table = $table;
try { try {
@@ -66,8 +69,10 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
// if it doesn't exists // if it doesn't exists
} }
/** @group singleton */ /**
public function test_createTable1() * @group singleton
*/
public function testCreateTable1()
{ {
// Create a table named grouped // Create a table named grouped
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
@@ -78,19 +83,21 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array (); $db->unique = [];
$db->primary = "group"; $db->primary = "group";
$res = $db->createTable(); $res = $db->createTable();
$db->disconnect(); $db->disconnect();
$this->assertSame(0, $res); $this->assertSame(0, $res);
} }
/** @group singleton */ /**
public function test_insert1() * @group singleton
*/
public function testInsert1()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -100,21 +107,21 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array (); $db->unique = [];
$db->primary = "group"; $db->primary = "group";
$res = $db->insert(array ("group" => "gr ou\"p", $res = $db->insert(["group" => "gr ou\"p",
"object" => "/éobj%", "object" => "/éobj%",
"where" => "\$'\"", "where" => "\$'\"",
"with space" => "with space")); "with space" => "with space"]);
// SQLite start at 1, MySQL start at 0... // SQLite start at 1, MySQL start at 0...
$this->assertSame($res, "gr ou\"p"); $this->assertSame($res, "gr ou\"p");
} }
public function test_read1() public function testRead1()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -124,22 +131,22 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array (); $db->unique = [];
$res = $db->read(array (array ("group", "gr ou\"p"), $res = $db->read([["group", "gr ou\"p"],
array ("object","/éobj%"), ["object","/éobj%"],
array ("where","\$'\""), ["where","\$'\""],
array ("with space","with space"))); ["with space","with space"]]);
$this->assertSame(array (0 => array ("group" => "gr ou\"p", $this->assertSame([0 => ["group" => "gr ou\"p",
"object" => "/éobj%", "object" => "/éobj%",
"where" => "\$'\"", "where" => "\$'\"",
"with space" => "with space")), $res); "with space" => "with space"]], $res);
} }
public function test_update1() public function testUpdate1()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -149,19 +156,19 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array (); $db->unique = [];
$db->primary = "group"; $db->primary = "group";
// Don't update primary key // Don't update primary key
$res = $db->update("gr ou\"p", array ("object" => "%éàoppp", $res = $db->update("gr ou\"p", ["object" => "%éàoppp",
"with space" => "WITH SPACE")); "with space" => "WITH SPACE"]);
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_read2() public function testRead2()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -171,22 +178,22 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array (); $db->unique = [];
$res = $db->read(array (array ("group", "gr ou\"p"), $res = $db->read([["group", "gr ou\"p"],
array ("object","%éàoppp"), ["object","%éàoppp"],
array ("where","\$'\""), ["where","\$'\""],
array ("with space","WITH SPACE"))); ["with space","WITH SPACE"]]);
$this->assertSame(array (0 => array ("group" => "gr ou\"p", $this->assertSame([0 => ["group" => "gr ou\"p",
"object" => "%éàoppp", "object" => "%éàoppp",
"where" => "\$'\"", "where" => "\$'\"",
"with space" => "WITH SPACE")), $res); "with space" => "WITH SPACE"]], $res);
} }
public function test_update2() public function testUpdate2()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -196,20 +203,20 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array (array ("group","object")); $db->unique = [["group","object"]];
$db->primary = "group"; $db->primary = "group";
// Update primary key // Update primary key
$res = $db->update("gr ou\"p", array ("group" => "NEW GROUP", $res = $db->update("gr ou\"p", ["group" => "NEW GROUP",
"object" => "%éàoppp", "object" => "%éàoppp",
"with space" => "WITH SPACE")); "with space" => "WITH SPACE"]);
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_read3() public function testRead3()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -219,22 +226,22 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array (); $db->unique = [];
$res = $db->read(array (array ("group", "NEW GROUP"), $res = $db->read([["group", "NEW GROUP"],
array ("object","%éàoppp"), ["object","%éàoppp"],
array ("where","\$'\""), ["where","\$'\""],
array ("with space","WITH SPACE"))); ["with space","WITH SPACE"]]);
$this->assertSame(array (0 => array ("group" => "NEW GROUP", $this->assertSame([0 => ["group" => "NEW GROUP",
"object" => "%éàoppp", "object" => "%éàoppp",
"where" => "\$'\"", "where" => "\$'\"",
"with space" => "WITH SPACE")), $res); "with space" => "WITH SPACE"]], $res);
} }
public function test_update3() public function testUpdate3()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -244,17 +251,17 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "grouped"; $db->table = "grouped";
$db->fields = array ("group" => array ("varchar", "255", "not null"), $db->fields = ["group" => ["varchar", "255", "not null"],
"object" => array ("varchar", "255", "not null"), "object" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array ("group"); $db->unique = ["group"];
$db->primary = "group"; $db->primary = "group";
// Update primary key with primary key in unique with same values to test if // Update primary key with primary key in unique with same values to test if
// the exception is NOT raised // the exception is NOT raised
$res = $db->update("NEW GROUP", array ("group" => "NEW GROUP", $res = $db->update("NEW GROUP", ["group" => "NEW GROUP",
"object" => "%éàoppp", "object" => "%éàoppp",
"with space" => "WITH SPACE")); "with space" => "WITH SPACE"]);
// SQLite and PostgreSQL return 1 line modified // SQLite and PostgreSQL return 1 line modified
// MySQL return 0 by default because there is no modification on the line // MySQL return 0 by default because there is no modification on the line
// http://fr2.php.net/manual/en/pdostatement.rowcount.php#104930 // http://fr2.php.net/manual/en/pdostatement.rowcount.php#104930
@@ -263,9 +270,11 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
/** @group singleton */ /**
* @group singleton
*/
// Part to test the foreign keys // Part to test the foreign keys
public function test_createTable2() public function testCreateTable2()
{ {
// Create a table named group // Create a table named group
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
@@ -283,19 +292,19 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "users"; $db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"), $db->fields = ["user" => ["varchar", "255", "not null"],
"groupmember" => array ("varchar", "255", "not null"), "groupmember" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->foreign = array ( $db->foreign = [
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"), "groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
); ];
$res = $db->createTable(); $res = $db->createTable();
$this->assertSame(0, $res); $this->assertSame(0, $res);
} }
public function test_insert2() public function testInsert2()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -305,26 +314,26 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "users"; $db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"), $db->fields = ["user" => ["varchar", "255", "not null"],
"groupmember" => array ("varchar", "255", "not null"), "groupmember" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->unique = array ("user"); $db->unique = ["user"];
$db->primary = "user"; $db->primary = "user";
$db->foreign = array ( $db->foreign = [
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"), "groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
); ];
$res = $db->insert(array ("user" => "Us ou\"r", $res = $db->insert(["user" => "Us ou\"r",
"groupmember" => "NEW GROUP", "groupmember" => "NEW GROUP",
"where" => "\$'\"", "where" => "\$'\"",
"with space" => "with space")); "with space" => "with space"]);
$db->disconnect(); $db->disconnect();
// SQLite start at 1, MySQL start at 0... // SQLite start at 1, MySQL start at 0...
$this->assertSame($res <= 2 || $res === "Us ou\"r", true); $this->assertSame($res <= 2 || $res === "Us ou\"r", true);
} }
// Test the unique feature // Test the unique feature
public function test_insert3() public function testInsert3()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -334,24 +343,24 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "users"; $db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"), $db->fields = ["user" => ["varchar", "255", "not null"],
"groupmember" => array ("varchar", "255", "not null"), "groupmember" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
// Unique simple in insert // Unique simple in insert
$db->unique = array ("user"); $db->unique = ["user"];
$db->primary = "user"; $db->primary = "user";
$db->foreign = array ( $db->foreign = [
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"), "groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
); ];
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $db->insert(array ("user" => "Us ou\"r", $res = $db->insert(["user" => "Us ou\"r",
"groupmember" => "NEW GROUP", "groupmember" => "NEW GROUP",
"where" => "\$'\"", "where" => "\$'\"",
"with space" => "with space")); "with space" => "with space"]);
} }
public function test_insert4() public function testInsert4()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -361,26 +370,28 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "users"; $db->table = "users";
$db->fields = array ("user" => array ("varchar", "255", "not null"), $db->fields = ["user" => ["varchar", "255", "not null"],
"groupmember" => array ("varchar", "255", "not null"), "groupmember" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
// Unique multiple in insert // Unique multiple in insert
$db->unique = array (array ("user", "groupmember")); $db->unique = [["user", "groupmember"]];
$db->primary = "user"; $db->primary = "user";
$db->foreign = array ( $db->foreign = [
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"), "groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
); ];
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $db->insert(array ("user" => "Us ou\"r", $res = $db->insert(["user" => "Us ou\"r",
"groupmember" => "NEW GROUP", "groupmember" => "NEW GROUP",
"where" => "\$'\"", "where" => "\$'\"",
"with space" => "with space")); "with space" => "with space"]);
} }
/** @group singleton */ /**
* @group singleton
*/
// Test multiple actions in one single connection // Test multiple actions in one single connection
public function test_multiple1() public function testMultiple1()
{ {
// Create a table named group // Create a table named group
@@ -392,10 +403,10 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "multiple"; $db->table = "multiple";
$db->fields = array ("user" => array ("varchar", "255", "not null"), $db->fields = ["user" => ["varchar", "255", "not null"],
"groupmember" => array ("varchar", "255", "not null"), "groupmember" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db->createTable(); $db->createTable();
$db2 = new Dblayer( $db2 = new Dblayer(
$dbconfig["dsn"], $dbconfig["dsn"],
@@ -404,19 +415,21 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db2->table = "multiple2"; $db2->table = "multiple2";
$db2->fields = array ("user" => array ("varchar", "255", "not null"), $db2->fields = ["user" => ["varchar", "255", "not null"],
"groupmember" => array ("varchar", "255", "not null"), "groupmember" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$db2->createTable(); $db2->createTable();
$res = $db2->read(array (array ("user", "toto"))); $res = $db2->read([["user", "toto"]]);
$res = $db->read(array (array ("user", "toto"))); $res = $db->read([["user", "toto"]]);
$db->disconnect(); $db->disconnect();
$this->assertSame(array (), $res); $this->assertSame([], $res);
} }
/** @group singleton */ /**
public function test_createTable3() * @group singleton
*/
public function testCreateTable3()
{ {
// Create a table named group // Create a table named group
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
@@ -427,17 +440,19 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "users3"; $db->table = "users3";
$db->fields = array ("user" => array ("varchar", "255", "not null"), $db->fields = ["user" => ["varchar", "255", "not null"],
"groupmember" => array ("varchar", "255", "not null"), "groupmember" => ["varchar", "255", "not null"],
"where" => array ("varchar", "255", "not null"), "where" => ["varchar", "255", "not null"],
"with space" => array ("varchar", "255", "not null")); "with space" => ["varchar", "255", "not null"]];
$res = $db->createTable(); $res = $db->createTable();
$db->disconnect(); $db->disconnect();
$this->assertSame(0, $res); $this->assertSame(0, $res);
} }
/** Check the OR feature on the same column with different value */ /**
public function test_readOR1() * Check the OR feature on the same column with different value
*/
public function testReadOR1()
{ {
$dbconfig = $this->confs["{ENGINE}"]; $dbconfig = $this->confs["{ENGINE}"];
$db = new Dblayer( $db = new Dblayer(
@@ -447,21 +462,21 @@ class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$db->table = "readOR"; $db->table = "readOR";
$db->fields = array ("id" => array ("integer"), $db->fields = ["id" => ["integer"],
"user" => array ("varchar", "255", "not null")); "user" => ["varchar", "255", "not null"]];
$db->primary = "id"; $db->primary = "id";
$db->unique = array ("id"); $db->unique = ["id"];
$db->createTable(); $db->createTable();
$db->insert(array ("id" => "0", "user" => "test0")); $db->insert(["id" => "0", "user" => "test0"]);
$db->insert(array ("id" => "1", "user" => "test1")); $db->insert(["id" => "1", "user" => "test1"]);
$res = $db->read( $res = $db->read(
array (array ("id", 0), array ("id", 1)), [["id", 0], ["id", 1]],
array ("user"), ["user"],
null, null,
true true
); );
$db->disconnect(); $db->disconnect();
$this->assertSame(array (0 => array ("user" => "test0"), $this->assertSame([0 => ["user" => "test0"],
1 => array ("user" => "test1")), $res); 1 => ["user" => "test1"]], $res);
}
} }
}

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -13,23 +14,23 @@ use Domframework\Authzgroups;
class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
{ {
public $confs = array ( public $confs = [
"sqlite" => array ( "sqlite" => [
"dsn" => "sqlite:/tmp/databaseAuthz.db", "dsn" => "sqlite:/tmp/databaseAuthz.db",
"username" => null, "username" => null,
"password" => null, "password" => null,
"driver_options" => null, "driver_options" => null,
"tableprefix" => "", "tableprefix" => "",
)); ]];
public function test_delDB() public function testDelDB()
{ {
if (file_exists("/tmp/databaseAuthz.db")) { if (file_exists("/tmp/databaseAuthz.db")) {
unlink("/tmp/databaseAuthz.db"); unlink("/tmp/databaseAuthz.db");
} }
} }
public function test_createTablesAuthzgroups() public function testCreateTablesAuthzgroups()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -54,7 +55,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("4", $res); $this->assertSame("4", $res);
} }
public function test_createTable() public function testCreateTable()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$n = new Dblayerauthzgroups( $n = new Dblayerauthzgroups(
@@ -71,21 +72,21 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))); ->uniqueSet(["id", ["zo ne", "vie wname"]]);
$res = $n->createTable(); $res = $n->createTable();
$this->assertSame(0, $res); $this->assertSame(0, $res);
} }
public function test_insert1() public function testInsert1()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -102,29 +103,29 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
->createGroupSet("group") ->createGroupSet("group")
->pathSet("/article/base/poub"); ->pathSet("/article/base/poub");
$res = $n->insert(array ("zo ne" => "zone1", $res = $n->insert(["zo ne" => "zone1",
"opendate" => "2015-05-04 00:11:22")); "opendate" => "2015-05-04 00:11:22"]);
$n->disconnect(); $n->disconnect();
$this->assertSame("1", $res); $this->assertSame("1", $res);
} }
// Check if the update of the authzgroups database is OK // Check if the update of the authzgroups database is OK
public function test_addAuthzgroups() public function testAddAuthzgroups()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -138,7 +139,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$this->assertSame("RW", $res); $this->assertSame("RW", $res);
} }
public function test_insert2() public function testInsert2()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -155,32 +156,32 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
->createGroupSet("group") ->createGroupSet("group")
->pathSet("/article/base/poub"); ->pathSet("/article/base/poub");
$n->insert(array ("zo ne" => "zone2", "opendate" => "2015-05-04 00:11:22")); $n->insert(["zo ne" => "zone2", "opendate" => "2015-05-04 00:11:22"]);
$n->insert(array ("zo ne" => "zone3", "opendate" => "2015-05-04 00:11:22")); $n->insert(["zo ne" => "zone3", "opendate" => "2015-05-04 00:11:22"]);
$n->insert(array ("zo ne" => "zone4", "opendate" => "2015-05-04 00:11:22")); $n->insert(["zo ne" => "zone4", "opendate" => "2015-05-04 00:11:22"]);
$res = $n->insert(array ("zo ne" => "zone5", $res = $n->insert(["zo ne" => "zone5",
"opendate" => "2015-05-04 00:11:22")); "opendate" => "2015-05-04 00:11:22"]);
$n->disconnect(); $n->disconnect();
$this->assertSame("5", $res); $this->assertSame("5", $res);
} }
// Access to all the tuples // Access to all the tuples
public function test_read1() public function testRead1()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -197,16 +198,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
@@ -218,7 +219,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Remove the right access to 2 and 4 // Remove the right access to 2 and 4
public function test_rightDel() public function testRightDel()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -235,7 +236,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Access to 3 of the tuples (2 are blacklisted for the user) // Access to 3 of the tuples (2 are blacklisted for the user)
public function test_read2() public function testRead2()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -252,16 +253,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
@@ -273,7 +274,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Del an entry without right -> exception // Del an entry without right -> exception
public function test_delEntry1() public function testDelEntry1()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -290,16 +291,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
@@ -310,7 +311,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Update a right to RO // Update a right to RO
public function test_rightRO() public function testRightRO()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -326,7 +327,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Update an entry with RO right -> exception // Update an entry with RO right -> exception
public function test_updateEntry2() public function testUpdateEntry2()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -343,27 +344,27 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
->createGroupSet("group") ->createGroupSet("group")
->pathSet("/article/base/poub"); ->pathSet("/article/base/poub");
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$res = $n->update(1, array ("zo ne" => "NOT ALLOWED")); $res = $n->update(1, ["zo ne" => "NOT ALLOWED"]);
} }
// Del an entry with the RO right -> exception // Del an entry with the RO right -> exception
public function test_delEntry2() public function testDelEntry2()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -380,16 +381,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
@@ -400,7 +401,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Update a right to RW // Update a right to RW
public function test_rightRW() public function testRightRW()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -416,7 +417,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Update an entry with RW right // Update an entry with RW right
public function test_updateEntry3() public function testUpdateEntry3()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -433,27 +434,27 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
->createGroupSet("group") ->createGroupSet("group")
->pathSet("/article/base/poub"); ->pathSet("/article/base/poub");
$res = $n->update(1, array ("zo ne" => "ALLOWED")); $res = $n->update(1, ["zo ne" => "ALLOWED"]);
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
// Del an entry with the RW right // Del an entry with the RW right
public function test_delEntry3() public function testDelEntry3()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -470,16 +471,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
@@ -490,7 +491,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
} }
// Check if the update of the authzgroups database is OK after deletion // Check if the update of the authzgroups database is OK after deletion
public function test_delAuthzgroups() public function testDelAuthzgroups()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -501,12 +502,12 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$res = $a->objectRead("modTest", "/article/base/poub/1"); $res = $a->objectRead("modTest", "/article/base/poub/1");
$this->assertSame(array (), $res); $this->assertSame([], $res);
} }
// Read the zone without id // Read the zone without id
public function test_read3() public function testRead3()
{ {
$dbconfig = $this->confs["sqlite"]; $dbconfig = $this->confs["sqlite"];
$a = new Authzgroups(); $a = new Authzgroups();
@@ -523,25 +524,25 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
$dbconfig["driver_options"] $dbconfig["driver_options"]
); );
$n->tableSet("dns zones") $n->tableSet("dns zones")
->fieldsSet(array ( ->fieldsSet([
"id" => array ("integer", "not null", "autoincrement"), "id" => ["integer", "not null", "autoincrement"],
"zo ne" => array ("varchar", "255", "not null"), "zo ne" => ["varchar", "255", "not null"],
"vie wname" => array ("varchar", "255"), "vie wname" => ["varchar", "255"],
"view clients" => array ("varchar", "255"), "view clients" => ["varchar", "255"],
"comme nt" => array ("varchar", "1024"), "comme nt" => ["varchar", "1024"],
"opendate" => array ("datetime", "not null"), "opendate" => ["datetime", "not null"],
"closedate" => array ("datetime"))) "closedate" => ["datetime"]])
->primarySet("id") ->primarySet("id")
->uniqueSet(array ("id", array ("zo ne", "vie wname"))) ->uniqueSet(["id", ["zo ne", "vie wname"]])
->authzgroupsSet($a) ->authzgroupsSet($a)
->moduleSet("modTest") ->moduleSet("modTest")
->userSet("user") ->userSet("user")
->createGroupSet("group") ->createGroupSet("group")
->pathSet("/article/base/poub"); ->pathSet("/article/base/poub");
$res = $n->read(null, array ("zo ne", "vie wname")); $res = $n->read(null, ["zo ne", "vie wname"]);
$this->assertSame( $this->assertSame(
array (1 => array ("zo ne" => "zone3", "vie wname" => null), [1 => ["zo ne" => "zone3", "vie wname" => null],
3 => array ("zo ne" => "zone5", "vie wname" => null)), 3 => ["zo ne" => "zone5", "vie wname" => null]],
$res $res
); );
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
*/ */
@@ -9,10 +10,13 @@ namespace Domframework\Tests;
use Domframework\Encrypt; use Domframework\Encrypt;
/** Test the Encrypt.php file */ /**
* Test the Encrypt.php file
*/
class EncryptTest extends \PHPUnit_Framework_TestCase class EncryptTest extends \PHPUnit_Framework_TestCase
{ {
/** Check the length of the otken with cipher /**
* Check the length of the otken with cipher
*/ */
public function testEncrypt1() public function testEncrypt1()
{ {
@@ -24,7 +28,8 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
$this->assertSame(strlen($res), 24); $this->assertSame(strlen($res), 24);
} }
/** Check if the encrypt/decrypt process return the same result /**
* Check if the encrypt/decrypt process return the same result
*/ */
public function testEncrypt2() public function testEncrypt2()
{ {
@@ -36,7 +41,8 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, $payload); $this->assertSame($res, $payload);
} }
/** Check if the encrypted part is well unreadable /**
* Check if the encrypted part is well unreadable
*/ */
public function testEncrypt3() public function testEncrypt3()
{ {
@@ -47,7 +53,8 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, false); $this->assertSame($res, false);
} }
/** Encrypt : Invalid Cipher method /**
* Encrypt : Invalid Cipher method
*/ */
public function testInvalidCypher1() public function testInvalidCypher1()
{ {
@@ -61,7 +68,8 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
$token = $encrypt->encrypt($payload, "123456789012345678901234", "TOTO"); $token = $encrypt->encrypt($payload, "123456789012345678901234", "TOTO");
} }
/** Encrypt : Invalid Payload to encrypt /**
* Encrypt : Invalid Payload to encrypt
*/ */
public function testInvalidPayload() public function testInvalidPayload()
{ {
@@ -71,11 +79,12 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
500 500
); );
$encrypt = new Encrypt(); $encrypt = new Encrypt();
$payload = array ("Invalid"); $payload = ["Invalid"];
$token = $encrypt->encrypt($payload, "123456789012345678901234"); $token = $encrypt->encrypt($payload, "123456789012345678901234");
} }
/** Encrypt : Invalid Cipher Key to encrypt /**
* Encrypt : Invalid Cipher Key to encrypt
*/ */
public function testInvalidCipherKey() public function testInvalidCipherKey()
{ {
@@ -90,7 +99,8 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
$token = $encrypt->encrypt($payload, "124"); $token = $encrypt->encrypt($payload, "124");
} }
/** Decrypt : invalid cipher text /**
* Decrypt : invalid cipher text
*/ */
public function testDecryptInvalidCipherKey() public function testDecryptInvalidCipherKey()
{ {
@@ -104,7 +114,8 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
$token = $encrypt->decrypt("zfz", "124"); $token = $encrypt->decrypt("zfz", "124");
} }
/** Decrypt : empty cipher string /**
* Decrypt : empty cipher string
*/ */
public function testDecryptEmptyCipherString() public function testDecryptEmptyCipherString()
{ {
@@ -117,7 +128,8 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
$token = $encrypt->decrypt("", "124"); $token = $encrypt->decrypt("", "124");
} }
/** Decrypt : Not a string cypher /**
* Decrypt : Not a string cypher
*/ */
public function testDecryptNotStringCipherString() public function testDecryptNotStringCipherString()
{ {
@@ -127,10 +139,11 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
500 500
); );
$encrypt = new Encrypt(); $encrypt = new Encrypt();
$token = $encrypt->decrypt(array (), "124"); $token = $encrypt->decrypt([], "124");
} }
/** Decrypt : Not a string cypher key /**
* Decrypt : Not a string cypher key
*/ */
public function testDecryptNotStringCipherKey() public function testDecryptNotStringCipherKey()
{ {
@@ -140,10 +153,11 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
500 500
); );
$encrypt = new Encrypt(); $encrypt = new Encrypt();
$token = $encrypt->decrypt("1224", array ()); $token = $encrypt->decrypt("1224", []);
} }
/** Decrypt : Not a cipher method string /**
* Decrypt : Not a cipher method string
*/ */
public function testDecryptNotStringCipherMethod() public function testDecryptNotStringCipherMethod()
{ {
@@ -153,10 +167,11 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
500 500
); );
$encrypt = new Encrypt(); $encrypt = new Encrypt();
$token = $encrypt->decrypt("1224", "1234", array ()); $token = $encrypt->decrypt("1224", "1234", []);
} }
/** Decrypt : Not a known cipher method /**
* Decrypt : Not a known cipher method
*/ */
public function testDecryptUnknownCipherMethod() public function testDecryptUnknownCipherMethod()
{ {

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\File; use Domframework\File;
/** Test the domframework File part */ /**
* Test the domframework File part
*/
class FileTest extends \PHPUnit_Framework_TestCase class FileTest extends \PHPUnit_Framework_TestCase
{ {
public function testinit() public function testinit()
@@ -303,7 +306,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
$file->chdir("/tmp/testDFFileDir"); $file->chdir("/tmp/testDFFileDir");
} }
public function testFile_get_contents1() public function testFileGetContents1()
{ {
$this->setExpectedException( $this->setExpectedException(
"Exception", "Exception",
@@ -318,7 +321,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
$res = $file->file_get_contents("/testDFFileDir"); $res = $file->file_get_contents("/testDFFileDir");
} }
public function testFile_get_contents2() public function testFileGetContents2()
{ {
if (file_exists("/tmp/testDFFileDir")) { if (file_exists("/tmp/testDFFileDir")) {
rmdir("/tmp/testDFFileDir"); rmdir("/tmp/testDFFileDir");
@@ -331,7 +334,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, ""); $this->assertSame($res, "");
} }
public function testFile_put_contents1() public function testFilePutContents1()
{ {
$file = new File(); $file = new File();
$file->chroot("/tmp"); $file->chroot("/tmp");
@@ -340,7 +343,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, "content"); $this->assertSame($res, "content");
} }
public function testFile_put_contents2() public function testFilePutContents2()
{ {
$this->setExpectedException( $this->setExpectedException(
"Exception", "Exception",
@@ -350,7 +353,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
$file->file_put_contents("/tmp/testDFFileDir", "content"); $file->file_put_contents("/tmp/testDFFileDir", "content");
} }
public function testFile_put_contents3() public function testFilePutContents3()
{ {
$file = new File(); $file = new File();
$file->chroot("/tmp"); $file->chroot("/tmp");
@@ -362,7 +365,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
{ {
$file = new File(); $file = new File();
$res = $file->scandir("/tmp/testDFFileDir"); $res = $file->scandir("/tmp/testDFFileDir");
$this->assertSame($res, array ("toto")); $this->assertSame($res, ["toto"]);
} }
public function testscandir2() public function testscandir2()
@@ -370,7 +373,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
$file = new File(); $file = new File();
$file->chroot("/tmp"); $file->chroot("/tmp");
$res = $file->scandir("/testDFFileDir"); $res = $file->scandir("/testDFFileDir");
$this->assertSame($res, array ("toto")); $this->assertSame($res, ["toto"]);
} }
public function testscandir3() public function testscandir3()
@@ -378,7 +381,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
$file = new File(); $file = new File();
$file->chroot("/tmp"); $file->chroot("/tmp");
$res = $file->scandir("/testDFFileDir/"); $res = $file->scandir("/testDFFileDir/");
$this->assertSame($res, array ("toto")); $this->assertSame($res, ["toto"]);
} }
public function testrmdir1() public function testrmdir1()
@@ -472,58 +475,58 @@ class FileTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_glob_1() public function testGlob1()
{ {
$file = new File(); $file = new File();
$file->chroot("/tmp"); $file->chroot("/tmp");
$res = $file->glob("/testDFFileDir/*"); $res = $file->glob("/testDFFileDir/*");
$this->assertSame($res, array ("/testDFFileDir/toto", $this->assertSame($res, ["/testDFFileDir/toto",
"/testDFFileDir/tptp")); "/testDFFileDir/tptp"]);
} }
public function test_glob_2() public function testGlob2()
{ {
$file = new File(); $file = new File();
$file->chroot("/tmp"); $file->chroot("/tmp");
$file->chdir("/testDFFileDir"); $file->chdir("/testDFFileDir");
$res = $file->glob("*"); $res = $file->glob("*");
$this->assertSame($res, array ("toto", $this->assertSame($res, ["toto",
"tptp")); "tptp"]);
} }
public function test_glob_3() public function testGlob3()
{ {
$file = new File(); $file = new File();
$file->chroot("/tmp"); $file->chroot("/tmp");
$file->chdir("/testDFFileDir"); $file->chdir("/testDFFileDir");
$res = $file->glob("/testDFFileDir/*"); $res = $file->glob("/testDFFileDir/*");
$this->assertSame($res, array ("/testDFFileDir/toto", $this->assertSame($res, ["/testDFFileDir/toto",
"/testDFFileDir/tptp")); "/testDFFileDir/tptp"]);
} }
public function test_glob_4() public function testGlob4()
{ {
$file = new File(); $file = new File();
$res = $file->glob("/tmp/testDFFileDir/*"); $res = $file->glob("/tmp/testDFFileDir/*");
$this->assertSame($res, array ("/tmp/testDFFileDir/toto", $this->assertSame($res, ["/tmp/testDFFileDir/toto",
"/tmp/testDFFileDir/tptp")); "/tmp/testDFFileDir/tptp"]);
} }
public function test_glob_5() public function testGlob5()
{ {
$file = new File(); $file = new File();
$file->chdir("/tmp/testDFFileDir"); $file->chdir("/tmp/testDFFileDir");
$res = $file->glob("*"); $res = $file->glob("*");
$this->assertSame($res, array ("toto", $this->assertSame($res, ["toto",
"tptp")); "tptp"]);
} }
public function test_glob_6() public function testGlob6()
{ {
$file = new File(); $file = new File();
$file->chdir("/tmp/testDFFileDir"); $file->chdir("/tmp/testDFFileDir");
$res = $file->glob("/tmp/testDFFileDir/*"); $res = $file->glob("/tmp/testDFFileDir/*");
$this->assertSame($res, array ("/tmp/testDFFileDir/toto", $this->assertSame($res, ["/tmp/testDFFileDir/toto",
"/tmp/testDFFileDir/tptp")); "/tmp/testDFFileDir/tptp"]);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Fts; use Domframework\Fts;
/** Test the FTS */ /**
* Test the FTS
*/
class FtsTest extends \PHPUnit_Framework_TestCase class FtsTest extends \PHPUnit_Framework_TestCase
{ {
public function testTokenizerSearch0() public function testTokenizerSearch0()
@@ -19,8 +22,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search(""); $fts->search("");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array (), $this->assertSame($res, ["tokens" => [],
"minuses" => array ())); "minuses" => []]);
} }
public function testTokenizerSearch1() public function testTokenizerSearch1()
@@ -29,8 +32,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("X"); $fts->search("X");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array (), $this->assertSame($res, ["tokens" => [],
"minuses" => array ())); "minuses" => []]);
} }
public function testTokenizerSearch2() public function testTokenizerSearch2()
@@ -39,8 +42,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("XYZ"); $fts->search("XYZ");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ"), $this->assertSame($res, ["tokens" => ["XYZ"],
"minuses" => array (""))); "minuses" => [""]]);
} }
public function testTokenizerSearch3() public function testTokenizerSearch3()
@@ -49,8 +52,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("XYZ 123"); $fts->search("XYZ 123");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ", "123"), $this->assertSame($res, ["tokens" => ["XYZ", "123"],
"minuses" => array ("", ""))); "minuses" => ["", ""]]);
} }
public function testTokenizerSearch4() public function testTokenizerSearch4()
@@ -59,8 +62,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("XYZ 123 ABC"); $fts->search("XYZ 123 ABC");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ", "123", "ABC"), $this->assertSame($res, ["tokens" => ["XYZ", "123", "ABC"],
"minuses" => array ("", "", ""))); "minuses" => ["", "", ""]]);
} }
public function testTokenizerSearch5() public function testTokenizerSearch5()
@@ -69,9 +72,9 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("XYZ 123 ABC KLM"); $fts->search("XYZ 123 ABC KLM");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ", "123", $this->assertSame($res, ["tokens" => ["XYZ", "123",
"ABC", "KLM"), "ABC", "KLM"],
"minuses" => array ("", "", "", ""))); "minuses" => ["", "", "", ""]]);
} }
public function testTokenizerSearch6() public function testTokenizerSearch6()
@@ -80,9 +83,9 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("Louis-XYZ 123 -AéBCé KLM"); $fts->search("Louis-XYZ 123 -AéBCé KLM");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("Louis-XYZ", "123", $this->assertSame($res, ["tokens" => ["Louis-XYZ", "123",
"AéBCé", "KLM"), "AéBCé", "KLM"],
"minuses" => array ("", "", "-", ""))); "minuses" => ["", "", "-", ""]]);
} }
@@ -92,8 +95,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("\"\""); $fts->search("\"\"");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array (), $this->assertSame($res, ["tokens" => [],
"minuses" => array ())); "minuses" => []]);
} }
public function testTokenizerSentence1() public function testTokenizerSentence1()
@@ -102,8 +105,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("\"XYZ 123\""); $fts->search("\"XYZ 123\"");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ 123"), $this->assertSame($res, ["tokens" => ["XYZ 123"],
"minuses" => array (""))); "minuses" => [""]]);
} }
public function testTokenizerSentence2() public function testTokenizerSentence2()
@@ -112,8 +115,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("\"XYZ 123\" \"ABC KLM\""); $fts->search("\"XYZ 123\" \"ABC KLM\"");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ 123", "ABC KLM"), $this->assertSame($res, ["tokens" => ["XYZ 123", "ABC KLM"],
"minuses" => array ("", ""))); "minuses" => ["", ""]]);
} }
public function testTokenizerSentence3() public function testTokenizerSentence3()
@@ -122,9 +125,9 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("\"XYZ 123\" -\"ABC KLM\" \"RPO YUI\""); $fts->search("\"XYZ 123\" -\"ABC KLM\" \"RPO YUI\"");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ 123", "ABC KLM", $this->assertSame($res, ["tokens" => ["XYZ 123", "ABC KLM",
"RPO YUI"), "RPO YUI"],
"minuses" => array ("", "-", ""))); "minuses" => ["", "-", ""]]);
} }
public function testTokenizerMixed1() public function testTokenizerMixed1()
@@ -133,8 +136,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("XYZ \"ABC KLM\""); $fts->search("XYZ \"ABC KLM\"");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("XYZ", "ABC KLM"), $this->assertSame($res, ["tokens" => ["XYZ", "ABC KLM"],
"minuses" => array ("", ""))); "minuses" => ["", ""]]);
} }
public function testTokenizerMixed2() public function testTokenizerMixed2()
@@ -143,8 +146,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("\"ABC KLM\" XYZ"); $fts->search("\"ABC KLM\" XYZ");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("ABC KLM", "XYZ"), $this->assertSame($res, ["tokens" => ["ABC KLM", "XYZ"],
"minuses" => array ("", ""))); "minuses" => ["", ""]]);
} }
public function testTokenizerMixed3() public function testTokenizerMixed3()
@@ -153,9 +156,9 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("\"ABC KLM\" XYZ \"RPO YUI\""); $fts->search("\"ABC KLM\" XYZ \"RPO YUI\"");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("ABC KLM", "XYZ", $this->assertSame($res, ["tokens" => ["ABC KLM", "XYZ",
"RPO YUI"), "RPO YUI"],
"minuses" => array ("", "", ""))); "minuses" => ["", "", ""]]);
} }
public function testTokenizerMixed4() public function testTokenizerMixed4()
@@ -164,9 +167,9 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("\"ABC KLM\" XYZ \"RPO YUI\" 123"); $fts->search("\"ABC KLM\" XYZ \"RPO YUI\" 123");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("ABC KLM", "XYZ", $this->assertSame($res, ["tokens" => ["ABC KLM", "XYZ",
"RPO YUI", "123"), "RPO YUI", "123"],
"minuses" => array ("", "", "", ""))); "minuses" => ["", "", "", ""]]);
} }
public function testTokenizerMixed5() public function testTokenizerMixed5()
@@ -175,8 +178,8 @@ class FtsTest extends \PHPUnit_Framework_TestCase
$fts = new Fts(); $fts = new Fts();
$fts->search("123 \"ABC KLM\" XYZ \"RPO YUI\""); $fts->search("123 \"ABC KLM\" XYZ \"RPO YUI\"");
$res = $fts->getTokensMin(); $res = $fts->getTokensMin();
$this->assertSame($res, array ("tokens" => array ("123", "ABC KLM", $this->assertSame($res, ["tokens" => ["123", "ABC KLM",
"XYZ", "RPO YUI"), "XYZ", "RPO YUI"],
"minuses" => array ("", "", "", ""))); "minuses" => ["", "", "", ""]]);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Getopts; use Domframework\Getopts;
/** Test the GetOpts */ /**
* Test the GetOpts
*/
class GetoptsTest extends \PHPUnit_Framework_TestCase class GetoptsTest extends \PHPUnit_Framework_TestCase
{ {
public function test_empty1() public function testEmpty1()
{ {
// Empty // Empty
$getopts = new Getopts(); $getopts = new Getopts();
@@ -21,163 +24,163 @@ class GetoptsTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, "No option defined\n"); $this->assertSame($res, "No option defined\n");
} }
public function test_simu1() public function testSimu1()
{ {
$getopts = new Getopts(); $getopts = new Getopts();
$res = $getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final"); $res = $getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$this->assertSame(is_object($res), true); $this->assertSame(is_object($res), true);
} }
public function test_add1() public function testAdd1()
{ {
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final"); $getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$res = $getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $res = $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$this->assertSame(is_object($res), true); $this->assertSame(is_object($res), true);
} }
public function test_add2() public function testAdd2()
{ {
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final"); $getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$res = $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $res = $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$this->assertSame(is_object($res), true); $this->assertSame(is_object($res), true);
} }
public function test_scan1() public function testScan1()
{ {
$this->expectException("Exception", "Provided tokens are not known: -f,-o,-o,-o"); $this->expectException("Exception", "Provided tokens are not known: -f,-o,-o,-o");
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final"); $getopts->simulate("sim\ ulate -h -d -d -f ii -o 1\ 2 -o \"2 2\" -o 3 -- -bla final");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->scan(); $res = $getopts->scan();
} }
public function test_getShort1() public function testGetShort1()
{ {
// One unique value (-h -> true/false) // One unique value (-h -> true/false)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d -d "); $getopts->simulate("sim\ ulate -h -d -d ");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Help"); $res = $getopts->get("Help");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_getShort2() public function testGetShort2()
{ {
// Multiple values, two set (-d -d) // Multiple values, two set (-d -d)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d -d "); $getopts->simulate("sim\ ulate -h -d -d ");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Debug"); $res = $getopts->get("Debug");
$this->assertSame($res, array (true,true)); $this->assertSame($res, [true,true]);
} }
public function test_getShort3() public function testGetShort3()
{ {
// Multiple values, one set (-d) // Multiple values, one set (-d)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d "); $getopts->simulate("sim\ ulate -h -d ");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Debug"); $res = $getopts->get("Debug");
$this->assertSame($res, array (true)); $this->assertSame($res, [true]);
} }
public function test_getShort4() public function testGetShort4()
{ {
// Multiple values, None set (-d) // Multiple values, None set (-d)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h "); $getopts->simulate("sim\ ulate -h ");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Debug"); $res = $getopts->get("Debug");
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
public function test_getLong1() public function testGetLong1()
{ {
// One unique value (--help -> true/false) // One unique value (--help -> true/false)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate --help -d -d "); $getopts->simulate("sim\ ulate --help -d -d ");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Help"); $res = $getopts->get("Help");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_getLong2() public function testGetLong2()
{ {
// Multiple values, two set (-debug --debug) // Multiple values, two set (-debug --debug)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h --debug --debug "); $getopts->simulate("sim\ ulate -h --debug --debug ");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Debug"); $res = $getopts->get("Debug");
$this->assertSame($res, array (true,true)); $this->assertSame($res, [true,true]);
} }
public function test_getLong3() public function testGetLong3()
{ {
// Multiple values, one set (-d) // Multiple values, one set (-d)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate --help -d "); $getopts->simulate("sim\ ulate --help -d ");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Debug"); $res = $getopts->get("Debug");
$this->assertSame($res, array (true)); $this->assertSame($res, [true]);
} }
public function test_getLong4() public function testGetLong4()
{ {
// Multiple values, None set (-d) // Multiple values, None set (-d)
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h"); $getopts->simulate("sim\ ulate -h");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->get("Debug"); $res = $getopts->get("Debug");
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
public function test_restOfLine1() public function testRestOfLine1()
{ {
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d -d -- -bla final"); $getopts->simulate("sim\ ulate -h -d -d -- -bla final");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->restOfLine(); $res = $getopts->restOfLine();
$this->assertSame($res, array ("-bla", "final")); $this->assertSame($res, ["-bla", "final"]);
} }
public function test_restOfLine2() public function testRestOfLine2()
{ {
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate bla final"); $getopts->simulate("sim\ ulate bla final");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->restOfLine(); $res = $getopts->restOfLine();
$this->assertSame($res, array ("bla", "final")); $this->assertSame($res, ["bla", "final"]);
} }
public function test_restOfLine3() public function testRestOfLine3()
{ {
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -- -bla final"); $getopts->simulate("sim\ ulate -- -bla final");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->restOfLine(); $res = $getopts->restOfLine();
$this->assertSame($res, array ("-bla", "final")); $this->assertSame($res, ["-bla", "final"]);
} }
public function test_programName1() public function testProgramName1()
{ {
$getopts = new Getopts(); $getopts = new Getopts();
$getopts->simulate("sim\ ulate -h -d -d -- -bla final"); $getopts->simulate("sim\ ulate -h -d -d -- -bla final");
$getopts->add("Help", "?h", array ("help","help2"), "Help of the software"); $getopts->add("Help", "?h", ["help","help2"], "Help of the software");
$getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2); $getopts->add("Debug", "d", "debug", "Debug", "DebugLevel", 2);
$res = $getopts->programName(); $res = $getopts->programName();
$this->assertSame($res, "sim ulate"); $this->assertSame($res, "sim ulate");

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,50 +11,58 @@ namespace Domframework\Tests;
use Domframework\Http; use Domframework\Http;
/** Test the Http.php file */ /**
* Test the Http.php file
*/
class HttpTest extends \PHPUnit_Framework_TestCase class HttpTest extends \PHPUnit_Framework_TestCase
{ {
/** bestChoice : exact existing entry /**
* bestChoice : exact existing entry
*/ */
public function testBestChoice1() public function testBestChoice1()
{ {
$http = new Http(); $http = new Http();
$res = $http->bestChoice( $res = $http->bestChoice(
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "text/html,application/xhtml+xml,application/xml;q=0.9,
array ("application/xml"), */*;q=0.8",
["application/xml"],
"text/html" "text/html"
); );
$this->assertSame($res, "application/xml"); $this->assertSame($res, "application/xml");
} }
/** bestChoice : Generic catch. /**
* bestChoice : Generic catch.
* Use default value * Use default value
*/ */
public function testBestChoice2() public function testBestChoice2()
{ {
$http = new Http(); $http = new Http();
$res = $http->bestChoice( $res = $http->bestChoice(
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "text/html,application/xhtml+xml,application/xml;q=0.9,
array ("text/plain"), */*;q=0.8",
["text/plain"],
"text/html" "text/html"
); );
$this->assertSame($res, "text/html"); $this->assertSame($res, "text/html");
} }
/** bestChoice : no solution : use the default value /**
* bestChoice : no solution : use the default value
*/ */
public function testBestChoice3() public function testBestChoice3()
{ {
$http = new Http(); $http = new Http();
$res = $http->bestChoice( $res = $http->bestChoice(
"text/html,application/xhtml+xml,application/xml;q=0.9", "text/html,application/xhtml+xml,application/xml;q=0.9",
array ("text/plain"), ["text/plain"],
"text/html" "text/html"
); );
$this->assertSame($res, "text/html"); $this->assertSame($res, "text/html");
} }
/** bestChoice : invalid entry (end with comma). Continue without error and /**
* bestChoice : invalid entry (end with comma). Continue without error and
* skip the bad choices * skip the bad choices
*/ */
public function testBestChoice4() public function testBestChoice4()
@@ -61,7 +70,7 @@ class HttpTest extends \PHPUnit_Framework_TestCase
$http = new Http(); $http = new Http();
$res = $http->bestChoice( $res = $http->bestChoice(
"text/html,application/xhtml+xml,application/xml;q=0.9,", "text/html,application/xhtml+xml,application/xml;q=0.9,",
array ("text/plain"), ["text/plain"],
"text/html" "text/html"
); );
$this->assertSame($res, "text/html"); $this->assertSame($res, "text/html");

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Inifile; use Domframework\Inifile;
/** Test the Inifile.php file */ /**
* Test the Inifile.php file
*/
class InifileTest extends \PHPUnit_Framework_TestCase class InifileTest extends \PHPUnit_Framework_TestCase
{ {
public function testsetString001() public function testsetString001()
@@ -23,7 +26,7 @@ class InifileTest extends \PHPUnit_Framework_TestCase
public function testsetString002() public function testsetString002()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array (), true); $res = $inifile->setString([], true);
$this->assertSame("", $res); $this->assertSame("", $res);
} }
@@ -32,34 +35,34 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1"), true); $res = $inifile->setString(["section1"], true);
} }
public function testsetString104() public function testsetString104()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array ()), true); $res = $inifile->setString(["section1" => []], true);
$this->assertSame("[section1]\n\n", $res); $this->assertSame("[section1]\n\n", $res);
} }
public function testsetString105() public function testsetString105()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array (0)), true); $res = $inifile->setString(["section1" => [0]], true);
$this->assertSame("[section1]\n0 = \"0\"\n\n", $res); $this->assertSame("[section1]\n0 = \"0\"\n\n", $res);
} }
public function testsetString106() public function testsetString106()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array (0 => 1)), true); $res = $inifile->setString(["section1" => [0 => 1]], true);
$this->assertSame("[section1]\n0 = \"1\"\n\n", $res); $this->assertSame("[section1]\n0 = \"1\"\n\n", $res);
} }
public function testsetString107() public function testsetString107()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array (0 => null)), true); $res = $inifile->setString(["section1" => [0 => null]], true);
$this->assertSame("[section1]\n0 = \"null\"\n\n", $res); $this->assertSame("[section1]\n0 = \"null\"\n\n", $res);
} }
@@ -67,7 +70,7 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, 1 => 1)), ["section1" => [0 => null, 1 => 1]],
true true
); );
$this->assertSame("[section1]\n0 = \"null\"\n1 = \"1\"\n\n", $res); $this->assertSame("[section1]\n0 = \"null\"\n1 = \"1\"\n\n", $res);
@@ -77,8 +80,8 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, ["section1" => [0 => null,
1 => 1, 2 => "str")), 1 => 1, 2 => "str"]],
true true
); );
$this->assertSame( $this->assertSame(
@@ -91,9 +94,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, ["section1" => [0 => null,
1 => 1, 2 => "str", 1 => 1, 2 => "str",
3 => array (1,2,3))), 3 => [1,2,3]]],
true true
); );
$this->assertSame( $this->assertSame(
@@ -107,9 +110,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, ["section1" => [0 => null,
1 => 1, 2 => "str", 1 => 1, 2 => "str",
3 => array ())), 3 => []]],
true true
); );
$this->assertSame( $this->assertSame(
@@ -122,9 +125,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, ["section1" => [0 => null,
1 => 1, 2 => "str", 1 => 1, 2 => "str",
"chain" => array ("key" => 1,2))), "chain" => ["key" => 1,2]]],
true true
); );
$this->assertSame( $this->assertSame(
@@ -138,35 +141,35 @@ class InifileTest extends \PHPUnit_Framework_TestCase
public function testsetString203() public function testsetString203()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1"), false); $res = $inifile->setString(["section1"], false);
$this->assertSame("0 = \"section1\"\n\n", $res); $this->assertSame("0 = \"section1\"\n\n", $res);
} }
public function testsetString204() public function testsetString204()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array ()), false); $res = $inifile->setString(["section1" => []], false);
$this->assertSame("\n", $res); $this->assertSame("\n", $res);
} }
public function testsetString205() public function testsetString205()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array (0)), false); $res = $inifile->setString(["section1" => [0]], false);
$this->assertSame("section1[0] = \"0\"\n\n", $res); $this->assertSame("section1[0] = \"0\"\n\n", $res);
} }
public function testsetString206() public function testsetString206()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array (0 => 1)), false); $res = $inifile->setString(["section1" => [0 => 1]], false);
$this->assertSame("section1[0] = \"1\"\n\n", $res); $this->assertSame("section1[0] = \"1\"\n\n", $res);
} }
public function testsetString207() public function testsetString207()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString(array ("section1" => array (0 => null)), false); $res = $inifile->setString(["section1" => [0 => null]], false);
$this->assertSame("section1[0] = \"null\"\n\n", $res); $this->assertSame("section1[0] = \"null\"\n\n", $res);
} }
@@ -174,7 +177,7 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, 1 => 1)), ["section1" => [0 => null, 1 => 1]],
false false
); );
$this->assertSame( $this->assertSame(
@@ -187,8 +190,8 @@ class InifileTest extends \PHPUnit_Framework_TestCase
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, ["section1" => [0 => null,
1 => 1, 2 => "str")), 1 => 1, 2 => "str"]],
false false
); );
$this->assertSame( $this->assertSame(
@@ -203,9 +206,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, ["section1" => [0 => null,
1 => 1, 2 => "str", 1 => 1, 2 => "str",
3 => array (1,2,3))), 3 => [1,2,3]]],
false false
); );
} }
@@ -215,9 +218,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$inifile = new Inifile(); $inifile = new Inifile();
$res = $inifile->setString( $res = $inifile->setString(
array ("section1" => array (0 => null, ["section1" => [0 => null,
1 => 1, 2 => "str", 1 => 1, 2 => "str",
3 => array ())), 3 => []]],
false false
); );
} }
@@ -227,28 +230,28 @@ class InifileTest extends \PHPUnit_Framework_TestCase
public function testLoop406() public function testLoop406()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$loop = $inifile->setString(array ("section1" => array (0 => 1)), false); $loop = $inifile->setString(["section1" => [0 => 1]], false);
var_dump($loop); var_dump($loop);
$res = $inifile->getString($loop, false); $res = $inifile->getString($loop, false);
var_dump($res); var_dump($res);
$this->assertSame(array ("section1" => array (0 => 1)), $res); $this->assertSame(["section1" => [0 => 1]], $res);
} }
public function testLoop407() public function testLoop407()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$loop = $inifile->setString(array ("section1" => array (0 => null)), false); $loop = $inifile->setString(["section1" => [0 => null]], false);
$res = $inifile->getString($loop, false); $res = $inifile->getString($loop, false);
$this->assertSame(array ("section1" => array (0 => null)), $res); $this->assertSame(["section1" => [0 => null]], $res);
} }
public function testLoop408() public function testLoop408()
{ {
$inifile = new Inifile(); $inifile = new Inifile();
$loop = $inifile->setString(array ("section1" => array (0 => "toto")), false); $loop = $inifile->setString(["section1" => [0 => "toto"]], false);
var_dump($loop); var_dump($loop);
$res = $inifile->getString($loop, false); $res = $inifile->getString($loop, false);
var_dump($res); var_dump($res);
$this->assertSame(array ("section1" => array (0 => "toto")), $res); $this->assertSame(["section1" => [0 => "toto"]], $res);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,246 +11,248 @@ namespace Domframework\Tests;
use Domframework\Ipaddresses; use Domframework\Ipaddresses;
/** Test the Ipaddresses.php file */ /**
* Test the Ipaddresses.php file
*/
class IpaddressesTest extends \PHPUnit_Framework_TestCase class IpaddressesTest extends \PHPUnit_Framework_TestCase
{ {
public function test_validIPAddress1() public function testValidIPAddress1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPAddress("::"); $res = $i->validIPAddress("::");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPAddress2() public function testValidIPAddress2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPAddress("1::"); $res = $i->validIPAddress("1::");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPAddress3() public function testValidIPAddress3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPAddress("::1"); $res = $i->validIPAddress("::1");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPAddress4() public function testValidIPAddress4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPAddress("2001::1"); $res = $i->validIPAddress("2001::1");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPAddress5() public function testValidIPAddress5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPAddress("1.2.3.4"); $res = $i->validIPAddress("1.2.3.4");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPAddress6() public function testValidIPAddress6()
{ {
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPAddress(""); $res = $i->validIPAddress("");
} }
public function test_validIPAddress7() public function testValidIPAddress7()
{ {
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPAddress(array ()); $res = $i->validIPAddress([]);
} }
public function test_validIPv4Address1() public function testValidIPv4Address1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv4Address("::"); $res = $i->validIPv4Address("::");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validIPv4Address2() public function testValidIPv4Address2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv4Address("1.2.3.4"); $res = $i->validIPv4Address("1.2.3.4");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv6Address1() public function testValidIPv6Address1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6Address("1.2.3.4"); $res = $i->validIPv6Address("1.2.3.4");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validIPv6Address2() public function testValidIPv6Address2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6Address("::"); $res = $i->validIPv6Address("::");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv6Address3() public function testValidIPv6Address3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6Address("1::"); $res = $i->validIPv6Address("1::");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv6Address4() public function testValidIPv6Address4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6Address("::1"); $res = $i->validIPv6Address("::1");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv6Address5() public function testValidIPv6Address5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6Address("1::1"); $res = $i->validIPv6Address("1::1");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv6Address6() public function testValidIPv6Address6()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6Address("1:1:1"); $res = $i->validIPv6Address("1:1:1");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validCIDR1() public function testValidCIDR1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validCIDR(-1); $res = $i->validCIDR(-1);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validCIDR2() public function testValidCIDR2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validCIDR(129); $res = $i->validCIDR(129);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validCIDR3() public function testValidCIDR3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validCIDR(128); $res = $i->validCIDR(128);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validCIDR4() public function testValidCIDR4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validCIDR(0); $res = $i->validCIDR(0);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv4CIDR1() public function testValidIPv4CIDR1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv4CIDR(-1); $res = $i->validIPv4CIDR(-1);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validIPv4CIDR2() public function testValidIPv4CIDR2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv4CIDR(33); $res = $i->validIPv4CIDR(33);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validIPv4CIDR3() public function testValidIPv4CIDR3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv4CIDR(32); $res = $i->validIPv4CIDR(32);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv4CIDR4() public function testValidIPv4CIDR4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv4CIDR(0); $res = $i->validIPv4CIDR(0);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv6CIDR1() public function testValidIPv6CIDR1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6CIDR(-1); $res = $i->validIPv6CIDR(-1);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validIPv6CIDR2() public function testValidIPv6CIDR2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6CIDR(129); $res = $i->validIPv6CIDR(129);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_validIPv6CIDR3() public function testValidIPv6CIDR3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6CIDR(128); $res = $i->validIPv6CIDR(128);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_validIPv6CIDR4() public function testValidIPv6CIDR4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->validIPv6CIDR(0); $res = $i->validIPv6CIDR(0);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_compressIP1() public function testCompressIP1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->compressIP("::"); $res = $i->compressIP("::");
$this->assertSame("::", $res); $this->assertSame("::", $res);
} }
public function test_compressIP2() public function testCompressIP2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->compressIP("::1"); $res = $i->compressIP("::1");
$this->assertSame("::1", $res); $this->assertSame("::1", $res);
} }
public function test_compressIP3() public function testCompressIP3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->compressIP("2::1"); $res = $i->compressIP("2::1");
$this->assertSame("2::1", $res); $this->assertSame("2::1", $res);
} }
public function test_compressIP4() public function testCompressIP4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->compressIP("2::"); $res = $i->compressIP("2::");
$this->assertSame("2::", $res); $this->assertSame("2::", $res);
} }
public function test_compressIP5() public function testCompressIP5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->compressIP("2:1:0:3::0:1"); $res = $i->compressIP("2:1:0:3::0:1");
$this->assertSame("2:1:0:3::1", $res); $this->assertSame("2:1:0:3::1", $res);
} }
public function test_compressIP6() public function testCompressIP6()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->compressIP("2:1:0:3:0000::1"); $res = $i->compressIP("2:1:0:3:0000::1");
$this->assertSame("2:1:0:3::1", $res); $this->assertSame("2:1:0:3::1", $res);
} }
public function test_uncompressIPv6a() public function testUncompressIPv6a()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->uncompressIPv6("1::1"); $res = $i->uncompressIPv6("1::1");
$this->assertSame("1:0:0:0:0:0:0:1", $res); $this->assertSame("1:0:0:0:0:0:0:1", $res);
} }
public function test_uncompressIPv6b() public function testUncompressIPv6b()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->uncompressIPv6("1::"); $res = $i->uncompressIPv6("1::");
$this->assertSame("1:0:0:0:0:0:0:0", $res); $this->assertSame("1:0:0:0:0:0:0:0", $res);
} }
public function test_uncompressIPv6c() public function testUncompressIPv6c()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->uncompressIPv6("::"); $res = $i->uncompressIPv6("::");
$this->assertSame("0:0:0:0:0:0:0:0", $res); $this->assertSame("0:0:0:0:0:0:0:0", $res);
} }
public function test_uncompressIPv6d() public function testUncompressIPv6d()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->uncompressIPv6("1.2.3.4"); $res = $i->uncompressIPv6("1.2.3.4");
$this->assertSame("1.2.3.4", $res); $this->assertSame("1.2.3.4", $res);
} }
public function test_groupIPv6a() public function testGroupIPv6a()
{ {
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->groupIPv6("1.2.3.4"); $res = $i->groupIPv6("1.2.3.4");
} }
public function test_groupIPv6b() public function testGroupIPv6b()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->groupIPv6("0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f." . $res = $i->groupIPv6("0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f." .
@@ -257,37 +260,37 @@ class IpaddressesTest extends \PHPUnit_Framework_TestCase
$this->assertSame("0123:4567:89ab:cdef:0123:4567:89ab:cdef", $res); $this->assertSame("0123:4567:89ab:cdef:0123:4567:89ab:cdef", $res);
} }
public function test_completeAddressWithZero1() public function testCompleteAddressWithZero1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->completeAddressWithZero("::"); $res = $i->completeAddressWithZero("::");
$this->assertSame("0000:0000:0000:0000:0000:0000:0000:0000", $res); $this->assertSame("0000:0000:0000:0000:0000:0000:0000:0000", $res);
} }
public function test_completeAddressWithZero2() public function testCompleteAddressWithZero2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->completeAddressWithZero("::1"); $res = $i->completeAddressWithZero("::1");
$this->assertSame("0000:0000:0000:0000:0000:0000:0000:0001", $res); $this->assertSame("0000:0000:0000:0000:0000:0000:0000:0001", $res);
} }
public function test_completeAddressWithZero3() public function testCompleteAddressWithZero3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->completeAddressWithZero("1::"); $res = $i->completeAddressWithZero("1::");
$this->assertSame("0001:0000:0000:0000:0000:0000:0000:0000", $res); $this->assertSame("0001:0000:0000:0000:0000:0000:0000:0000", $res);
} }
public function test_completeAddressWithZero4() public function testCompleteAddressWithZero4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->completeAddressWithZero("1::1"); $res = $i->completeAddressWithZero("1::1");
$this->assertSame("0001:0000:0000:0000:0000:0000:0000:0001", $res); $this->assertSame("0001:0000:0000:0000:0000:0000:0000:0001", $res);
} }
public function test_completeAddressWithZero5() public function testCompleteAddressWithZero5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->completeAddressWithZero("1:222::1"); $res = $i->completeAddressWithZero("1:222::1");
$this->assertSame("0001:0222:0000:0000:0000:0000:0000:0001", $res); $this->assertSame("0001:0222:0000:0000:0000:0000:0000:0001", $res);
} }
public function test_completeAddressWithZero6() public function testCompleteAddressWithZero6()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->completeAddressWithZero("1.2.3.4"); $res = $i->completeAddressWithZero("1.2.3.4");
@@ -297,274 +300,274 @@ class IpaddressesTest extends \PHPUnit_Framework_TestCase
// TODO : cidrToBin // TODO : cidrToBin
// TODO : str_base_convert // TODO : str_base_convert
public function test_reverseIPAddress1() public function testReverseIPAddress1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->reverseIPAddress("1.2.3.4"); $res = $i->reverseIPAddress("1.2.3.4");
$this->assertSame("4.3.2.1", $res); $this->assertSame("4.3.2.1", $res);
} }
public function test_reverseIPAddress2() public function testReverseIPAddress2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->reverseIPAddress("::"); $res = $i->reverseIPAddress("::");
$this->assertSame("0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", $res); $this->assertSame("0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", $res);
} }
public function test_reverseIPAddress3() public function testReverseIPAddress3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->reverseIPAddress("::1"); $res = $i->reverseIPAddress("::1");
$this->assertSame("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", $res); $this->assertSame("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0", $res);
} }
public function test_reverseIPAddress4() public function testReverseIPAddress4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->reverseIPAddress("2::1"); $res = $i->reverseIPAddress("2::1");
$this->assertSame("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0", $res); $this->assertSame("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0", $res);
} }
public function test_reverseIPAddress5() public function testReverseIPAddress5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->reverseIPAddress("2::abcd:1"); $res = $i->reverseIPAddress("2::abcd:1");
$this->assertSame("1.0.0.0.d.c.b.a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0", $res); $this->assertSame("1.0.0.0.d.c.b.a.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0", $res);
} }
public function test_netmask2cidr1() public function testNetmask2cidr1()
{ {
$this->setExpectedException("Exception"); $this->setExpectedException("Exception");
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr(0); $res = $i->netmask2cidr(0);
} }
public function test_netmask2cidr2() public function testNetmask2cidr2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("255.255.255.0"); $res = $i->netmask2cidr("255.255.255.0");
$this->assertSame(24, $res); $this->assertSame(24, $res);
} }
public function test_netmask2cidr3() public function testNetmask2cidr3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("255.255.255.255"); $res = $i->netmask2cidr("255.255.255.255");
$this->assertSame(32, $res); $this->assertSame(32, $res);
} }
public function test_netmask2cidr4() public function testNetmask2cidr4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("255.255.255.255"); $res = $i->netmask2cidr("255.255.255.255");
$this->assertSame(32, $res); $this->assertSame(32, $res);
} }
public function test_netmask2cidr5() public function testNetmask2cidr5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("255.0.0.0"); $res = $i->netmask2cidr("255.0.0.0");
$this->assertSame(8, $res); $this->assertSame(8, $res);
} }
public function test_netmask2cidr6() public function testNetmask2cidr6()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("127.0.0.0"); $res = $i->netmask2cidr("127.0.0.0");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_netmask2cidr7() public function testNetmask2cidr7()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("63.0.0.0"); $res = $i->netmask2cidr("63.0.0.0");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_netmask2cidr8() public function testNetmask2cidr8()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("155.0.0.0"); $res = $i->netmask2cidr("155.0.0.0");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_netmask2cidr9() public function testNetmask2cidr9()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("0.0.0.255"); $res = $i->netmask2cidr("0.0.0.255");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_netmask2cidrWildcard_1() public function testNetmask2cidrWildcard1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("255.255.255.0", false); $res = $i->netmask2cidr("255.255.255.0", false);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_netmask2cidrWildcard_2() public function testNetmask2cidrWildcard2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("0.0.0.0", false); $res = $i->netmask2cidr("0.0.0.0", false);
$this->assertSame(32, $res); $this->assertSame(32, $res);
} }
public function test_netmask2cidrWildcard_3() public function testNetmask2cidrWildcard3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->netmask2cidr("255.255.255.255", false); $res = $i->netmask2cidr("255.255.255.255", false);
$this->assertSame(0, $res); $this->assertSame(0, $res);
} }
public function test_cidr2netmask_1() public function testCidr2netmask1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->cidr2netmask(0, true); $res = $i->cidr2netmask(0, true);
$this->assertSame("0.0.0.0", $res); $this->assertSame("0.0.0.0", $res);
} }
public function test_cidr2netmask_2() public function testCidr2netmask2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->cidr2netmask(24, true); $res = $i->cidr2netmask(24, true);
$this->assertSame("255.255.255.0", $res); $this->assertSame("255.255.255.0", $res);
} }
public function test_cidr2netmask_3() public function testCidr2netmask3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->cidr2netmask(25, true); $res = $i->cidr2netmask(25, true);
$this->assertSame("255.255.255.128", $res); $this->assertSame("255.255.255.128", $res);
} }
public function test_cidr2netmask_4() public function testCidr2netmask4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->cidr2netmask(32, true); $res = $i->cidr2netmask(32, true);
$this->assertSame("255.255.255.255", $res); $this->assertSame("255.255.255.255", $res);
} }
public function test_cidr2netmask_5() public function testCidr2netmask5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->cidr2netmask(1, true); $res = $i->cidr2netmask(1, true);
$this->assertSame("128.0.0.0", $res); $this->assertSame("128.0.0.0", $res);
} }
public function test_ipInNetwork1() public function testIpInNetwork1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->ipInNetwork("127.0.0.1", "127.1.0.0", 8); $res = $i->ipInNetwork("127.0.0.1", "127.1.0.0", 8);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_ipInNetwork2() public function testIpInNetwork2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->ipInNetwork("192.168.1.1", "127.1.0.0", 8); $res = $i->ipInNetwork("192.168.1.1", "127.1.0.0", 8);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_ipInNetwork3() public function testIpInNetwork3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->ipInNetwork("2001:660:530d:201::1", "2001:660:530d:201::", 64); $res = $i->ipInNetwork("2001:660:530d:201::1", "2001:660:530d:201::", 64);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_ipInNetwork4() public function testIpInNetwork4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->ipInNetwork("2001:660:530d:203::1", "2001:660:530d:201::", 64); $res = $i->ipInNetwork("2001:660:530d:203::1", "2001:660:530d:201::", 64);
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_ipInNetwork5() public function testIpInNetwork5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->ipInNetwork("2001:660:530d:203::1", "2001::", 0); $res = $i->ipInNetwork("2001:660:530d:203::1", "2001::", 0);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_ipInNetwork6() public function testIpInNetwork6()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->ipInNetwork("192.168.1.1", "127.0.0.0", 0); $res = $i->ipInNetwork("192.168.1.1", "127.0.0.0", 0);
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_networkFirstIP1() public function testNetworkFirstIP1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("192.168.1.21", 24); $res = $i->networkFirstIP("192.168.1.21", 24);
$this->assertSame($res, "192.168.1.0"); $this->assertSame($res, "192.168.1.0");
} }
public function test_networkFirstIP2() public function testNetworkFirstIP2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("192.168.1.21", 0); $res = $i->networkFirstIP("192.168.1.21", 0);
$this->assertSame($res, "0.0.0.0"); $this->assertSame($res, "0.0.0.0");
} }
public function test_networkFirstIP3() public function testNetworkFirstIP3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("192.168.1.21", 32); $res = $i->networkFirstIP("192.168.1.21", 32);
$this->assertSame($res, "192.168.1.21"); $this->assertSame($res, "192.168.1.21");
} }
public function test_networkFirstIP4() public function testNetworkFirstIP4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("192.168.1.21", 31); $res = $i->networkFirstIP("192.168.1.21", 31);
$this->assertSame($res, "192.168.1.20"); $this->assertSame($res, "192.168.1.20");
} }
public function test_networkFirstIP5() public function testNetworkFirstIP5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("2001:660:530d:201::125", 64); $res = $i->networkFirstIP("2001:660:530d:201::125", 64);
$this->assertSame($res, "2001:660:530d:201::"); $this->assertSame($res, "2001:660:530d:201::");
} }
public function test_networkFirstIP6() public function testNetworkFirstIP6()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("2001:660:530d:201::125", 0); $res = $i->networkFirstIP("2001:660:530d:201::125", 0);
$this->assertSame($res, "::"); $this->assertSame($res, "::");
} }
public function test_networkFirstIP7() public function testNetworkFirstIP7()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("2001:660:530d:201::125", 128); $res = $i->networkFirstIP("2001:660:530d:201::125", 128);
$this->assertSame($res, "2001:660:530d:201::125"); $this->assertSame($res, "2001:660:530d:201::125");
} }
public function test_networkFirstIP8() public function testNetworkFirstIP8()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkFirstIP("2001:660:530d:201::125", 127); $res = $i->networkFirstIP("2001:660:530d:201::125", 127);
$this->assertSame($res, "2001:660:530d:201::124"); $this->assertSame($res, "2001:660:530d:201::124");
} }
public function test_networkLastIP1() public function testNetworkLastIP1()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("192.168.1.21", 24); $res = $i->networkLastIP("192.168.1.21", 24);
$this->assertSame($res, "192.168.1.255"); $this->assertSame($res, "192.168.1.255");
} }
public function test_networkLastIP2() public function testNetworkLastIP2()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("192.168.1.21", 0); $res = $i->networkLastIP("192.168.1.21", 0);
$this->assertSame($res, "255.255.255.255"); $this->assertSame($res, "255.255.255.255");
} }
public function test_networkLastIP3() public function testNetworkLastIP3()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("192.168.1.21", 32); $res = $i->networkLastIP("192.168.1.21", 32);
$this->assertSame($res, "192.168.1.21"); $this->assertSame($res, "192.168.1.21");
} }
public function test_networkLastIP4() public function testNetworkLastIP4()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("192.168.1.21", 31); $res = $i->networkLastIP("192.168.1.21", 31);
$this->assertSame($res, "192.168.1.21"); $this->assertSame($res, "192.168.1.21");
} }
public function test_networkLastIP5() public function testNetworkLastIP5()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("2001:660:530d:201::125", 64); $res = $i->networkLastIP("2001:660:530d:201::125", 64);
$this->assertSame($res, "2001:660:530d:201:ffff:ffff:ffff:ffff"); $this->assertSame($res, "2001:660:530d:201:ffff:ffff:ffff:ffff");
} }
public function test_networkLastIP6() public function testNetworkLastIP6()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("2001:660:530d:201::125", 0); $res = $i->networkLastIP("2001:660:530d:201::125", 0);
$this->assertSame($res, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"); $this->assertSame($res, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
} }
public function test_networkLastIP7() public function testNetworkLastIP7()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("2001:660:530d:201::125", 128); $res = $i->networkLastIP("2001:660:530d:201::125", 128);
$this->assertSame($res, "2001:660:530d:201::125"); $this->assertSame($res, "2001:660:530d:201::125");
} }
public function test_networkLastIP8() public function testNetworkLastIP8()
{ {
$i = new Ipaddresses(); $i = new Ipaddresses();
$res = $i->networkLastIP("2001:660:530d:201::125", 127); $res = $i->networkLastIP("2001:660:530d:201::125", 127);

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,17 +11,19 @@ namespace Domframework\Tests;
use Domframework\Jwt; use Domframework\Jwt;
/** Test the Jwt.php file */ /**
* Test the Jwt.php file
*/
class JwtTest extends \PHPUnit_Framework_TestCase class JwtTest extends \PHPUnit_Framework_TestCase
{ {
public function test_createKey_1() public function testCreateKey1()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$res = $jwt->createKey(); $res = $jwt->createKey();
$this->assertSame(40, strlen($res)); $this->assertSame(40, strlen($res));
} }
public function test_sign_1() public function testSign1()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$res = $this->invokeMethod( $res = $this->invokeMethod(
@@ -36,7 +39,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_sign_2() public function testSign2()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$res = $this->invokeMethod( $res = $this->invokeMethod(
@@ -52,7 +55,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_sign_3() public function testSign3()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$res = $this->invokeMethod( $res = $this->invokeMethod(
@@ -68,10 +71,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_encode_1() public function testEncode1()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$res = $jwt->encode(array ("payload" => "value"), "key to use", "HS384"); $res = $jwt->encode(["payload" => "value"], "key to use", "HS384");
$this->assertSame( $this->assertSame(
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9." . "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9." .
"eyJwYXlsb2FkIjoidmFsdWUifQ." . "eyJwYXlsb2FkIjoidmFsdWUifQ." .
@@ -80,7 +83,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_decode_1() public function testDecode1()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$res = $jwt->decode( $res = $jwt->decode(
@@ -89,10 +92,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
"0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge", "0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge",
"key to use" "key to use"
); );
$this->assertSame((object)array ("payload" => "value"), $res); $this->assertSame((object)["payload" => "value"], $res);
} }
public function test_decode_2() public function testDecode2()
{ {
$GLOBALS["hash_equals"] = false; $GLOBALS["hash_equals"] = false;
$jwt = new Jwt(); $jwt = new Jwt();
@@ -102,10 +105,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
"0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge", "0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge",
"key to use" "key to use"
); );
$this->assertSame((object)array ("payload" => "value"), $res); $this->assertSame((object)["payload" => "value"], $res);
} }
public function test_decode_3() public function testDecode3()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$this->expectException("Exception", "JWT with Empty algorithm"); $this->expectException("Exception", "JWT with Empty algorithm");
@@ -117,7 +120,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_decode_4() public function testDecode4()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$this->expectException("Exception", "JWT Payload not readable"); $this->expectException("Exception", "JWT Payload not readable");
@@ -129,7 +132,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_decode_5() public function testDecode5()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$this->expectException( $this->expectException(
@@ -144,7 +147,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_decode_6() public function testDecode6()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$this->expectException( $this->expectException(
@@ -159,7 +162,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_decode_7() public function testDecode7()
{ {
$jwt = new Jwt(); $jwt = new Jwt();
$this->expectException( $this->expectException(
@@ -176,7 +179,8 @@ class JwtTest extends \PHPUnit_Framework_TestCase
/////////////////////////////// ///////////////////////////////
// ENCRYPT THE PAYLOAD // // ENCRYPT THE PAYLOAD //
/////////////////////////////// ///////////////////////////////
/** Check the length of the otken with cipher /**
* Check the length of the otken with cipher
*/ */
public function testEncrypt1() public function testEncrypt1()
{ {
@@ -191,7 +195,8 @@ class JwtTest extends \PHPUnit_Framework_TestCase
$this->assertSame(strlen($res), 156); $this->assertSame(strlen($res), 156);
} }
/** Check if the encrypt/decrypt process return the same result /**
* Check if the encrypt/decrypt process return the same result
*/ */
public function testEncrypyt2() public function testEncrypyt2()
{ {
@@ -203,7 +208,8 @@ class JwtTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, $payload); $this->assertSame($res, $payload);
} }
/** Check if the encrypted part is well unreadable /**
* Check if the encrypted part is well unreadable
*/ */
public function testEncrypt3() public function testEncrypt3()
{ {
@@ -211,7 +217,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
$key = $jwt->createKey(); $key = $jwt->createKey();
$payload = (object)["email" => "toto@example.com", "password" => "ToTo"]; $payload = (object)["email" => "toto@example.com", "password" => "ToTo"];
$token = $jwt->encode($payload, $key, "HS256", "123456789012345678901234"); $token = $jwt->encode($payload, $key, "HS256", "123456789012345678901234");
list ($header, $payload, $signature) = explode(".", $token); list($header, $payload, $signature) = explode(".", $token);
$res = strpos(base64_decode($payload), "email"); $res = strpos(base64_decode($payload), "email");
$this->assertSame($res, false); $this->assertSame($res, false);
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,101 +11,103 @@ namespace Domframework\Tests;
use Domframework\Macaddresses; use Domframework\Macaddresses;
/** Test the Macaddresses.php file */ /**
* Test the Macaddresses.php file
*/
class MacaddressesTest extends \PHPUnit_Framework_TestCase class MacaddressesTest extends \PHPUnit_Framework_TestCase
{ {
public function test_isMACAddress_1() public function testIsMACAddress1()
{ {
$macaddresses = new Macaddresses(); $macaddresses = new Macaddresses();
$res = $macaddresses->isMACAddress(""); $res = $macaddresses->isMACAddress("");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_isMACAddress_2() public function testIsMACAddress2()
{ {
$macaddresses = new Macaddresses(); $macaddresses = new Macaddresses();
$res = $macaddresses->isMACAddress("INVALID"); $res = $macaddresses->isMACAddress("INVALID");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_isMACAddress_3() public function testIsMACAddress3()
{ {
$macaddresses = new Macaddresses(); $macaddresses = new Macaddresses();
$res = $macaddresses->isMACAddress("de:ad:be:af:aa:bb"); $res = $macaddresses->isMACAddress("de:ad:be:af:aa:bb");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_isMACAddress_4() public function testIsMACAddress4()
{ {
$macaddresses = new Macaddresses(); $macaddresses = new Macaddresses();
$res = $macaddresses->isMACAddress("de-ad-be-af-aa-bb"); $res = $macaddresses->isMACAddress("de-ad-be-af-aa-bb");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_isMACAddress_5() public function testIsMACAddress5()
{ {
$macaddresses = new Macaddresses(); $macaddresses = new Macaddresses();
$res = $macaddresses->isMACAddress("0005.313B.9080"); $res = $macaddresses->isMACAddress("0005.313B.9080");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_isMACAddress_6() public function testIsMACAddress6()
{ {
$macaddresses = new Macaddresses(); $macaddresses = new Macaddresses();
$res = $macaddresses->isMACAddress("0005313B9080"); $res = $macaddresses->isMACAddress("0005313B9080");
$this->assertSame(true, $res); $this->assertSame(true, $res);
} }
public function test_isMACAddress_7() public function testIsMACAddress7()
{ {
$macaddresses = new Macaddresses(); $macaddresses = new Macaddresses();
$res = $macaddresses->isMACAddress("a0005313B9080a"); $res = $macaddresses->isMACAddress("a0005313B9080a");
$this->assertSame(false, $res); $this->assertSame(false, $res);
} }
public function test_addSeparator_1() public function testAddSeparator1()
{ {
$res = Macaddresses::addSeparator("0005313B9080"); $res = Macaddresses::addSeparator("0005313B9080");
$this->assertSame("00:05:31:3B:90:80", $res); $this->assertSame("00:05:31:3B:90:80", $res);
} }
public function test_addSeparator_2() public function testAddSeparator2()
{ {
$res = Macaddresses::addSeparator("0005313B9080", "-"); $res = Macaddresses::addSeparator("0005313B9080", "-");
$this->assertSame("00-05-31-3B-90-80", $res); $this->assertSame("00-05-31-3B-90-80", $res);
} }
public function test_addSeparator_3() public function testAddSeparator3()
{ {
$res = Macaddresses::addSeparator("0005313B9080", ".", 4); $res = Macaddresses::addSeparator("0005313B9080", ".", 4);
$this->assertSame("0005.313B.9080", $res); $this->assertSame("0005.313B.9080", $res);
} }
public function test_addSeparator_4() public function testAddSeparator4()
{ {
$this->expectException(); $this->expectException();
$res = Macaddresses::addSeparator("INVALID", ".", 4); $res = Macaddresses::addSeparator("INVALID", ".", 4);
} }
public function test_removeSeparator_1() public function testRemoveSeparator1()
{ {
$res = Macaddresses::removeSeparator("de:ad:be:af:aa:bb"); $res = Macaddresses::removeSeparator("de:ad:be:af:aa:bb");
$this->assertSame("deadbeafaabb", $res); $this->assertSame("deadbeafaabb", $res);
} }
public function test_removeSeparator_2() public function testRemoveSeparator2()
{ {
$res = Macaddresses::removeSeparator("de-ad-be-af-aa-bb"); $res = Macaddresses::removeSeparator("de-ad-be-af-aa-bb");
$this->assertSame("deadbeafaabb", $res); $this->assertSame("deadbeafaabb", $res);
} }
public function test_removeSeparator_3() public function testRemoveSeparator3()
{ {
$res = Macaddresses::removeSeparator("dead.beaf.aabb"); $res = Macaddresses::removeSeparator("dead.beaf.aabb");
$this->assertSame("deadbeafaabb", $res); $this->assertSame("deadbeafaabb", $res);
} }
public function test_removeSeparator_4() public function testRemoveSeparator4()
{ {
$res = Macaddresses::removeSeparator("deadbeafaabb"); $res = Macaddresses::removeSeparator("deadbeafaabb");
$this->assertSame("deadbeafaabb", $res); $this->assertSame("deadbeafaabb", $res);

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Mail; use Domframework\Mail;
/** Test the Mail.php file */ /**
* Test the Mail.php file
*/
class MailTest extends \PHPUnit_Framework_TestCase class MailTest extends \PHPUnit_Framework_TestCase
{ {
public function testSetBodyText1() public function testSetBodyText1()
@@ -91,57 +94,58 @@ class MailTest extends \PHPUnit_Framework_TestCase
{ {
$mail = new Mail(); $mail = new Mail();
$res = $mail->convertPeopleToArray("toto toto <toto@toto.com>"); $res = $mail->convertPeopleToArray("toto toto <toto@toto.com>");
$this->assertSame($res, array (array ("name" => "toto toto", $this->assertSame($res, [["name" => "toto toto",
"mail" => "toto@toto.com"))); "mail" => "toto@toto.com"]]);
} }
public function testConvertPeopleToArray2() public function testConvertPeopleToArray2()
{ {
$mail = new Mail(); $mail = new Mail();
$res = $mail->convertPeopleToArray("<toto@toto.com>"); $res = $mail->convertPeopleToArray("<toto@toto.com>");
$this->assertSame($res, array (array ("name" => "", $this->assertSame($res, [["name" => "",
"mail" => "toto@toto.com"))); "mail" => "toto@toto.com"]]);
} }
public function testConvertPeopleToArray3() public function testConvertPeopleToArray3()
{ {
$mail = new Mail(); $mail = new Mail();
$res = $mail->convertPeopleToArray("toto@toto.com,titi@titi.com"); $res = $mail->convertPeopleToArray("toto@toto.com,titi@titi.com");
$this->assertSame($res, array (array ("name" => "", $this->assertSame($res, [["name" => "",
"mail" => "toto@toto.com"), "mail" => "toto@toto.com"],
array ("name" => "", ["name" => "",
"mail" => "titi@titi.com"))); "mail" => "titi@titi.com"]]);
} }
public function testConvertPeopleToArray4() public function testConvertPeopleToArray4()
{ {
$mail = new Mail(); $mail = new Mail();
$res = $mail->convertPeopleToArray("toto@toto.com"); $res = $mail->convertPeopleToArray("toto@toto.com");
$this->assertSame($res, array (array ("name" => "", $this->assertSame($res, [["name" => "",
"mail" => "toto@toto.com"))); "mail" => "toto@toto.com"]]);
} }
public function testConvertPeopleToArray5() public function testConvertPeopleToArray5()
{ {
$mail = new Mail(); $mail = new Mail();
$res = $mail->convertPeopleToArray(" <toto@toto.com> , <titi@titi.com>"); $res = $mail->convertPeopleToArray(" <toto@toto.com> , <titi@titi.com>");
$this->assertSame($res, array (array ("name" => "", $this->assertSame($res, [["name" => "",
"mail" => "toto@toto.com"), "mail" => "toto@toto.com"],
array ("name" => "", ["name" => "",
"mail" => "titi@titi.com"))); "mail" => "titi@titi.com"]]);
} }
public function testConvertPeopleToArray6() public function testConvertPeopleToArray6()
{ {
$mail = new Mail(); $mail = new Mail();
$res = $mail->convertPeopleToArray("ToTo <toto@toto.com> , <titi@titi.com>"); $res = $mail->convertPeopleToArray("ToTo <toto@toto.com> , <titi@titi.com>");
$this->assertSame($res, array (array ("name" => "ToTo", $this->assertSame($res, [["name" => "ToTo",
"mail" => "toto@toto.com"), "mail" => "toto@toto.com"],
array ("name" => "", ["name" => "",
"mail" => "titi@titi.com"))); "mail" => "titi@titi.com"]]);
} }
/** Read all the headers and return them as JSON object /**
* Read all the headers and return them as JSON object
*/ */
public function testHeadersToJSON1() public function testHeadersToJSON1()
{ {
@@ -191,7 +195,7 @@ http://www.cs.cmu.edu/~ralf/langid.html
" "
); );
// }}} // }}}
$this->assertSame($mail->getHeaders(), array ( $this->assertSame($mail->getHeaders(), [
["Return-Path" => "<dominique.fournier@grenoble.cnrs.fr>\n"], ["Return-Path" => "<dominique.fournier@grenoble.cnrs.fr>\n"],
["Delivered-To" => "dominique@fournier38.fr\n"], ["Delivered-To" => "dominique@fournier38.fr\n"],
["Received" => "from mail-postfix-mx.fournier38.fr ([192.168.1.103]) ["Received" => "from mail-postfix-mx.fournier38.fr ([192.168.1.103])
@@ -229,6 +233,6 @@ http://www.cs.cmu.edu/~ralf/langid.html
["X-Spamd-Bar" => "--------------------------------------------------------------------------------------------------\n"], ["X-Spamd-Bar" => "--------------------------------------------------------------------------------------------------\n"],
)); ]);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Markdown; use Domframework\Markdown;
/** Test the Markdown.php file */ /**
* Test the Markdown.php file
*/
class MarkdownTest extends \PHPUnit_Framework_TestCase class MarkdownTest extends \PHPUnit_Framework_TestCase
{ {
// TitleSeText // TitleSeText

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Outputdl; use Domframework\Outputdl;
/** Test the Outputdl.php file */ /**
* Test the Outputdl.php file
*/
class OutputdlTest extends \PHPUnit_Framework_TestCase class OutputdlTest extends \PHPUnit_Framework_TestCase
{ {
public function test_outputdl_init() public function testOutputdlInit()
{ {
exec("rm -f /tmp/testDFWoutputDL*"); exec("rm -f /tmp/testDFWoutputDL*");
file_put_contents( file_put_contents(
@@ -27,7 +30,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
symlink("/tmp/testDFWoutputDL", "/tmp/testDFWoutputDL3"); symlink("/tmp/testDFWoutputDL", "/tmp/testDFWoutputDL3");
} }
public function test_outputdl_1() public function testOutputdl1()
{ {
// Check the full download content // Check the full download content
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -38,7 +41,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
$outputdl->downloadFile("/tmp/testDFWoutputDL"); $outputdl->downloadFile("/tmp/testDFWoutputDL");
} }
public function test_outputdl_Announce_1() public function testOutputdlAnnounce1()
{ {
// Check the announce of Resume mode Enabled // Check the announce of Resume mode Enabled
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -47,7 +50,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
$this->assertSame(in_array("Accept-Ranges: bytes", $res), true); $this->assertSame(in_array("Accept-Ranges: bytes", $res), true);
} }
public function test_outputdl_Announce_2() public function testOutputdlAnnounce2()
{ {
// Check the announce of Resume mode Disabled // Check the announce of Resume mode Disabled
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -57,7 +60,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
$this->assertSame(in_array("Accept-Ranges: none", $res), true); $this->assertSame(in_array("Accept-Ranges: none", $res), true);
} }
public function test_outputdl_Partial_1() public function testOutputdlPartial1()
{ {
// Check the content get with provided range // Check the content get with provided range
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -67,7 +70,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
} }
public function test_outputdl_Partial_2() public function testOutputdlPartial2()
{ {
// Check the content get with provided range // Check the content get with provided range
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -80,7 +83,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
} }
public function test_outputdl_Partial_3() public function testOutputdlPartial3()
{ {
// Check the content get with provided range // Check the content get with provided range
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -93,7 +96,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
} }
public function test_outputdl_Partial_4() public function testOutputdlPartial4()
{ {
// Check the content get with provided range // Check the content get with provided range
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -103,7 +106,7 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
} }
public function test_outputdl_Partial_5() public function testOutputdlPartial5()
{ {
// Check the content get with provided range // Check the content get with provided range
$outputdl = new Outputdl(); $outputdl = new Outputdl();
@@ -124,7 +127,7 @@ Content-Type: application/octet-stream\r
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
} }
public function test_outputdl_PartialWrong_1() public function testOutputdlPartialWrong1()
{ {
// Check the invalid provided range // Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
@@ -134,7 +137,7 @@ Content-Type: application/octet-stream\r
$outputdl->downloadFile("/tmp/testDFWoutputDL"); $outputdl->downloadFile("/tmp/testDFWoutputDL");
} }
public function test_outputdl_PartialWrong_2() public function testOutputdlPartialWrong2()
{ {
// Check the invalid provided range // Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
@@ -144,7 +147,7 @@ Content-Type: application/octet-stream\r
$outputdl->downloadFile("/tmp/testDFWoutputDL"); $outputdl->downloadFile("/tmp/testDFWoutputDL");
} }
public function test_outputdl_PartialWrong_3() public function testOutputdlPartialWrong3()
{ {
// Check the invalid provided range // Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
@@ -154,7 +157,7 @@ Content-Type: application/octet-stream\r
$outputdl->downloadFile("/tmp/testDFWoutputDL"); $outputdl->downloadFile("/tmp/testDFWoutputDL");
} }
public function test_outputdl_PartialWrong_4() public function testOutputdlPartialWrong4()
{ {
// Check the invalid provided range // Check the invalid provided range
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
@@ -164,7 +167,7 @@ Content-Type: application/octet-stream\r
$outputdl->downloadFile("/tmp/testDFWoutputDL"); $outputdl->downloadFile("/tmp/testDFWoutputDL");
} }
public function test_outputdl_invalidBase_1() public function testOutputdlInvalidBase1()
{ {
// Check the base comparison : OK // Check the base comparison : OK
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
@@ -177,7 +180,7 @@ Content-Type: application/octet-stream\r
$outputdl->downloadFile("/tmp/testDFWoutputDL"); $outputdl->downloadFile("/tmp/testDFWoutputDL");
} }
public function test_outputdl_invalidBase_2() public function testOutputdlInvalidBase2()
{ {
// Check the base comparison : BAD // Check the base comparison : BAD
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
@@ -191,7 +194,7 @@ Content-Type: application/octet-stream\r
$outputdl->downloadFile("../../../../../..//etc/passwd"); $outputdl->downloadFile("../../../../../..//etc/passwd");
} }
public function test_outputdl_invalidFile_1() public function testOutputdlInvalidFile1()
{ {
// Check the base comparison : BAD Symlink // Check the base comparison : BAD Symlink
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);
@@ -205,7 +208,7 @@ Content-Type: application/octet-stream\r
$outputdl->downloadFile("/tmp/testDFWoutputDL3"); $outputdl->downloadFile("/tmp/testDFWoutputDL3");
} }
public function test_outputdl_invalidFile_2() public function testOutputdlInvalidFile2()
{ {
// Check the base comparison : Non existing // Check the base comparison : Non existing
unset($_SERVER["HTTP_RANGE"]); unset($_SERVER["HTTP_RANGE"]);

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,14 @@ namespace Domframework\Tests;
use Domframework\Outputhtml; use Domframework\Outputhtml;
/** Test the Outputhtml.php file */ /**
* Test the Outputhtml.php file
*/
class OutputhtmlTest extends \PHPUnit_Framework_TestCase class OutputhtmlTest extends \PHPUnit_Framework_TestCase
{ {
/** Entry null */ /**
* Entry null
*/
public function testlayout1() public function testlayout1()
{ {
$this->expectOutputRegex("#<body>\s+</body>#"); $this->expectOutputRegex("#<body>\s+</body>#");
@@ -58,7 +63,7 @@ class OutputhtmlTest extends \PHPUnit_Framework_TestCase
</body> </body>
</html>\n"); </html>\n");
$output = new Outputhtml(); $output = new Outputhtml();
$variable = array ("var" => "VARIABLE"); $variable = ["var" => "VARIABLE"];
$output->out( $output->out(
"data", "data",
"title", "title",

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,14 @@ namespace Domframework\Tests;
use Domframework\Outputjson; use Domframework\Outputjson;
/** Test the Outputjson.php file */ /**
* Test the Outputjson.php file
*/
class OutputjsonTest extends \PHPUnit_Framework_TestCase class OutputjsonTest extends \PHPUnit_Framework_TestCase
{ {
/** Entry null */ /**
* Entry null
*/
public function testoutputjson1() public function testoutputjson1()
{ {
$this->expectOutputString("\"\""); $this->expectOutputString("\"\"");
@@ -21,7 +26,9 @@ class OutputjsonTest extends \PHPUnit_Framework_TestCase
$output->out(""); $output->out("");
} }
/** Entry string */ /**
* Entry string
*/
public function testoutputjson2() public function testoutputjson2()
{ {
$this->expectOutputString("\"string\""); $this->expectOutputString("\"string\"");
@@ -29,11 +36,13 @@ class OutputjsonTest extends \PHPUnit_Framework_TestCase
$output->out("string"); $output->out("string");
} }
/** Entry array */ /**
* Entry array
*/
public function testoutputjson3() public function testoutputjson3()
{ {
$this->expectOutputString("[1,2,3]"); $this->expectOutputString("[1,2,3]");
$output = new Outputjson(); $output = new Outputjson();
$output->out(array (1,2,3)); $output->out([1,2,3]);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,17 +11,18 @@ namespace Domframework\Tests;
use Domframework\Password; use Domframework\Password;
/** Test the Password class /**
* Test the Password class
*/ */
class PasswordTest extends \PHPUnit_Framework_TestCase class PasswordTest extends \PHPUnit_Framework_TestCase
{ {
public function test_cryptPasswd_1() public function testCryptPasswd1()
{ {
$res = Password::cryptPasswd("AAA"); $res = Password::cryptPasswd("AAA");
$this->assertSame($res[0] == "$" && strlen($res) > 8, true); $this->assertSame($res[0] == "$" && strlen($res) > 8, true);
} }
public function test_cryptPasswd_2() public function testCryptPasswd2()
{ {
// Test the randomization of the salt : must be different each time // Test the randomization of the salt : must be different each time
$res1 = Password::cryptPasswd("AAA"); $res1 = Password::cryptPasswd("AAA");
@@ -29,38 +31,38 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
echo "RES2=$res2\n"; echo "RES2=$res2\n";
$res3 = Password::cryptPasswd("AAA"); $res3 = Password::cryptPasswd("AAA");
echo "RES3=$res3\n"; echo "RES3=$res3\n";
$this->assertSame(count(array_unique(array ($res1, $res2, $res3))), 3); $this->assertSame(count(array_unique([$res1, $res2, $res3])), 3);
// Three passwords : each must have a different result // Three passwords : each must have a different result
} }
public function test_cryptPasswd_3() public function testCryptPasswd3()
{ {
$this->expectException(); $this->expectException();
$res = Password::cryptPasswd(false); $res = Password::cryptPasswd(false);
} }
public function test_cryptPassword_MYSQL() public function testCryptPasswordMYSQL()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "MYSQL"); $res = $password->cryptPassword("AAA", "MYSQL");
$this->assertSame($res, "*5AF9D0EA5F6406FB0EDD0507F81C1D5CEBE8AC9C"); $this->assertSame($res, "*5AF9D0EA5F6406FB0EDD0507F81C1D5CEBE8AC9C");
} }
public function test_cryptPassword_CRYPT_STD_DES() public function testCryptPasswordCRYPTSTDDES()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "CRYPT_STD_DES"); $res = $password->cryptPassword("AAA", "CRYPT_STD_DES");
$this->assertSame(strlen($res), 13); $this->assertSame(strlen($res), 13);
} }
public function test_cryptPassword_CRYPT_EXT_DES() public function testCryptPasswordCRYPTEXTDES()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "CRYPT_EXT_DES"); $res = $password->cryptPassword("AAA", "CRYPT_EXT_DES");
$this->assertSame(strlen($res), 13); $this->assertSame(strlen($res), 13);
} }
public function test_cryptPassword_CRYPT_MD5() public function testCryptPasswordCRYPTMD5()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "CRYPT_MD5"); $res = $password->cryptPassword("AAA", "CRYPT_MD5");
@@ -70,7 +72,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_cryptPassword_CRYPT_BLOWFISH() public function testCryptPasswordCRYPTBLOWFISH()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "CRYPT_BLOWFISH"); $res = $password->cryptPassword("AAA", "CRYPT_BLOWFISH");
@@ -80,7 +82,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_cryptPassword_CRYPT_SHA256() public function testCryptPasswordCRYPTSHA256()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "CRYPT_SHA256"); $res = $password->cryptPassword("AAA", "CRYPT_SHA256");
@@ -90,7 +92,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_cryptPassword_CRYPT_SHA512() public function testCryptPasswordCRYPTSHA512()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "CRYPT_SHA512"); $res = $password->cryptPassword("AAA", "CRYPT_SHA512");
@@ -100,7 +102,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_cryptPassword_PASSWORD_BCRYPT() public function testCryptPasswordPASSWORDBCRYPT()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "PASSWORD_BCRYPT"); $res = $password->cryptPassword("AAA", "PASSWORD_BCRYPT");
@@ -110,7 +112,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_cryptPassword_PASSWORD_ARGON2I() public function testCryptPasswordPASSWORDARGON2I()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "PASSWORD_ARGON2I"); $res = $password->cryptPassword("AAA", "PASSWORD_ARGON2I");
@@ -120,7 +122,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_cryptPassword_PASSWORD_ARGON2ID() public function testCryptPasswordPASSWORDARGON2ID()
{ {
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "PASSWORD_ARGON2ID"); $res = $password->cryptPassword("AAA", "PASSWORD_ARGON2ID");
@@ -130,33 +132,33 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_cryptPassword_UNKNOWN() public function testCryptPasswordUNKNOWN()
{ {
$this->expectException(); $this->expectException();
$password = new password(); $password = new password();
$res = $password->cryptPassword("AAA", "UNKNOWN"); $res = $password->cryptPassword("AAA", "UNKNOWN");
} }
public function test_checkPassword_1() public function testCheckPassword1()
{ {
$res = Password::checkPassword("AAA", "AAA"); $res = Password::checkPassword("AAA", "AAA");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_checkPassword_2() public function testCheckPassword2()
{ {
$crypt = Password::cryptPasswd("AAA"); $crypt = Password::cryptPasswd("AAA");
$res = Password::checkPassword("AAA", $crypt); $res = Password::checkPassword("AAA", $crypt);
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_checkPassword_3() public function testCheckPassword3()
{ {
$res = Password::checkPassword("AAA", Password::cryptPasswd("BBB")); $res = Password::checkPassword("AAA", Password::cryptPasswd("BBB"));
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_checkPassword_4() public function testCheckPassword4()
{ {
$res = Password::checkPassword( $res = Password::checkPassword(
"AAA", "AAA",
@@ -165,7 +167,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_checkPassword_invalid1() public function testCheckPasswordInvalid1()
{ {
$this->expectException(); $this->expectException();
$res = Password::checkPassword( $res = Password::checkPassword(
@@ -174,74 +176,74 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_checkPassword_invalid2() public function testCheckPasswordInvalid2()
{ {
$this->expectException(); $this->expectException();
$res = Password::checkPassword("AAA", false); $res = Password::checkPassword("AAA", false);
} }
public function test_generateASCII_defaultsize() public function testGenerateASCIIDefaultsize()
{ {
$res = Password::generateASCII(); $res = Password::generateASCII();
$this->assertSame(strlen($res), 12); $this->assertSame(strlen($res), 12);
} }
public function test_generateASCII_toobig() public function testGenerateASCIIToobig()
{ {
$this->expectException(); $this->expectException();
$res = Password::generateASCII(112); $res = Password::generateASCII(112);
} }
public function test_generateASCII_toosmall() public function testGenerateASCIIToosmall()
{ {
$this->expectException(); $this->expectException();
$res = Password::generateASCII(0); $res = Password::generateASCII(0);
} }
public function test_generateAlphanum_defaultsize() public function testGenerateAlphanumDefaultsize()
{ {
$res = Password::generateAlphanum(); $res = Password::generateAlphanum();
$this->assertSame(strlen($res), 12); $this->assertSame(strlen($res), 12);
} }
public function test_generateAlphanum_toobig() public function testGenerateAlphanumToobig()
{ {
$this->expectException(); $this->expectException();
$res = Password::generateAlphanum(112); $res = Password::generateAlphanum(112);
} }
public function test_generateAlphanum_toosmall() public function testGenerateAlphanumToosmall()
{ {
$this->expectException(); $this->expectException();
$res = Password::generateAlphanum(0); $res = Password::generateAlphanum(0);
} }
public function test_generateAlphabetical_defaultsize() public function testGenerateAlphabeticalDefaultsize()
{ {
$res = Password::generateAlphabetical(); $res = Password::generateAlphabetical();
$this->assertSame(strlen($res), 12); $this->assertSame(strlen($res), 12);
} }
public function test_generateAlphabetical_toobig() public function testGenerateAlphabeticalToobig()
{ {
$this->expectException(); $this->expectException();
$res = Password::generateAlphabetical(112); $res = Password::generateAlphabetical(112);
} }
public function test_generateAlphabetical_toosmall() public function testGenerateAlphabeticalToosmall()
{ {
$this->expectException(); $this->expectException();
$res = Password::generateAlphabetical(0); $res = Password::generateAlphabetical(0);
} }
public function test_listMethods_1() public function testListMethods1()
{ {
$password = new password(); $password = new password();
$res = $password->listMethods(); $res = $password->listMethods();
$this->assertSame(count($res) > 7, true); $this->assertSame(count($res) > 7, true);
} }
public function test_salt_1() public function testSalt1()
{ {
$password = new password(); $password = new password();
$res = $password->salt(); $res = $password->salt();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Queue; use Domframework\Queue;
/** Test the Queue.php file */ /**
* Test the Queue.php file
*/
class QueueTest extends \PHPUnit_Framework_TestCase class QueueTest extends \PHPUnit_Framework_TestCase
{ {
public function test() public function test()

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,17 +11,19 @@ namespace Domframework\Tests;
use Domframework\Queuefile; use Domframework\Queuefile;
/** Test the Queuefile.php file */ /**
* Test the Queuefile.php file
*/
class QueuefileTest extends \PHPUnit_Framework_TestCase class QueuefileTest extends \PHPUnit_Framework_TestCase
{ {
public function test_clean() public function testClean()
{ {
if (file_exists("/tmp/queuefileTest/queuefileTest.json")) { if (file_exists("/tmp/queuefileTest/queuefileTest.json")) {
unlink("/tmp/queuefileTest/queuefileTest.json"); unlink("/tmp/queuefileTest/queuefileTest.json");
} }
} }
public function test_add1() public function testAdd1()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -28,7 +31,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(true, is_object($res)); $this->assertSame(true, is_object($res));
} }
public function test_count1() public function testCount1()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -36,7 +39,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(1, $res); $this->assertSame(1, $res);
} }
public function test_add2() public function testAdd2()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -44,7 +47,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(true, is_object($res)); $this->assertSame(true, is_object($res));
} }
public function test_count2() public function testCount2()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -52,7 +55,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(2, $res); $this->assertSame(2, $res);
} }
public function test_getFirst1() public function testGetFirst1()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -60,7 +63,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame("test1", $res); $this->assertSame("test1", $res);
} }
public function test_getLast1() public function testGetLast1()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -68,7 +71,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame("test2", $res); $this->assertSame("test2", $res);
} }
public function test_getRange1() public function testGetRange1()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -76,7 +79,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(["test2"], $res); $this->assertSame(["test2"], $res);
} }
public function test_getRange2() public function testGetRange2()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -84,7 +87,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(["test1", "test2"], $res); $this->assertSame(["test1", "test2"], $res);
} }
public function test_getRange3() public function testGetRange3()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -92,7 +95,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$res = $queuefile->getRange(0, 3); $res = $queuefile->getRange(0, 3);
} }
public function test_getAll1() public function testGetAll1()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -101,7 +104,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
} }
// AFTER THIS TEST THE FILE WILL BE EMPTY // AFTER THIS TEST THE FILE WILL BE EMPTY
public function test_getAll2() public function testGetAll2()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -109,7 +112,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(true, is_object($res)); $this->assertSame(true, is_object($res));
} }
public function test_count3() public function testCount3()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -117,7 +120,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(0, $res); $this->assertSame(0, $res);
} }
public function test_getAll3() public function testGetAll3()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -125,7 +128,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame([], $res); $this->assertSame([], $res);
} }
public function test_getFirst2() public function testGetFirst2()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
@@ -133,7 +136,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
$this->assertSame(null, $res); $this->assertSame(null, $res);
} }
public function test_getLast2() public function testGetLast2()
{ {
$queuefile = new Queuefile(); $queuefile = new Queuefile();
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json"); $queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Ratelimit; use Domframework\Ratelimit;
/** Test the Ratelimit.php file */ /**
* Test the Ratelimit.php file
*/
class RatelimitTest extends \PHPUnit_Framework_TestCase class RatelimitTest extends \PHPUnit_Framework_TestCase
{ {
public function test_ratelimit0() public function testRatelimit0()
{ {
$ratelimit = new Ratelimit(); $ratelimit = new Ratelimit();
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Ratelimitfile; use Domframework\Ratelimitfile;
/** Test the Ratelimitfile.php file */ /**
* Test the Ratelimitfile.php file
*/
class RatelimitfileTest extends \PHPUnit_Framework_TestCase class RatelimitfileTest extends \PHPUnit_Framework_TestCase
{ {
public function testRatelimitfile0() public function testRatelimitfile0()

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,13 @@ namespace Domframework\Tests;
use Domframework\Rest; use Domframework\Rest;
/** Test the domframework REST part */ /**
* Test the domframework REST part
*/
class RestTest extends \PHPUnit_Framework_TestCase class RestTest extends \PHPUnit_Framework_TestCase
{ {
/** No param, JSON by default /**
* No param, JSON by default
*/ */
public function testChooseType1() public function testChooseType1()
{ {
@@ -22,44 +26,51 @@ class RestTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, "json"); $this->assertSame($res, "json");
} }
/** If limited allowedTypes, return the first one as default /**
* If limited allowedTypes, return the first one as default
*/ */
public function testChooseType2() public function testChooseType2()
{ {
$rest = new Rest(); $rest = new Rest();
$rest->allowedtypes = array ("xml", "csv"); $rest->allowedtypes = ["xml", "csv"];
$res = $rest->chooseType(); $res = $rest->chooseType();
$this->assertSame($res, "xml"); $this->assertSame($res, "xml");
} }
/** Choose by the user specification : exact match /**
* Choose by the user specification : exact match
*/ */
public function testChooseType3() public function testChooseType3()
{ {
$rest = new Rest(); $rest = new Rest();
$_SERVER["HTTP_ACCEPT"] = "text/html,application/xml;q=0.9,*/*;q=0.8"; $_SERVER["HTTP_ACCEPT"] = "text/html,application/xml;q=0.9,
*/*;q=0.8";
$res = $rest->chooseType(); $res = $rest->chooseType();
$this->assertSame($res, "xml"); $this->assertSame($res, "xml");
} }
/** Choose by the user specification : generic match /**
* Choose by the user specification : generic match
*/ */
public function testChooseType4() public function testChooseType4()
{ {
$rest = new Rest(); $rest = new Rest();
$_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,*/*;q=0.8"; $_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,
*/*;q=0.8";
$res = $rest->chooseType(); $res = $rest->chooseType();
$this->assertSame($res, "json"); $this->assertSame($res, "json");
} }
/** Choose by the user specification : generic match with limited allowed /**
* Choose by the user specification : generic match with limited allowed
* types * types
*/ */
public function testChooseType5() public function testChooseType5()
{ {
$rest = new Rest(); $rest = new Rest();
$rest->allowedtypes = array ("xml", "csv"); $rest->allowedtypes = ["xml", "csv"];
$_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,*/*;q=0.8"; $_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,
*/*;q=0.8";
$res = $rest->chooseType(); $res = $rest->chooseType();
$this->assertSame($res, "xml"); $this->assertSame($res, "xml");
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,8 @@ namespace Domframework\Tests;
use Domframework\Robotstxt; use Domframework\Robotstxt;
/** Test the Robotstxt file /**
* Test the Robotstxt file
*/ */
class RobotstxtTest extends \PHPUnit_Framework_TestCase class RobotstxtTest extends \PHPUnit_Framework_TestCase
{ {
@@ -25,13 +27,13 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
{ {
$robotstxt = new Robotstxt("", "domsearch"); $robotstxt = new Robotstxt("", "domsearch");
$res = $robotstxt->disallow(); $res = $robotstxt->disallow();
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
public function testConstruct3() public function testConstruct3()
{ {
$robotstxt = new Robotstxt("", "domsearch"); $robotstxt = new Robotstxt("", "domsearch");
$res = $robotstxt->sitemaps(); $res = $robotstxt->sitemaps();
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
public function testConstruct4() public function testConstruct4()
{ {

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,20 +11,26 @@ namespace Domframework\Tests;
use Domframework\Route; use Domframework\Route;
/** Test the Route.php file */ /**
* Test the Route.php file
*/
class RouteTest extends \PHPUnit_Framework_TestCase class RouteTest extends \PHPUnit_Framework_TestCase
{ {
/// RELATIVE /// /// RELATIVE ///
/** Entry null */ /**
public function test_baseURL_1_relative() * Entry null
*/
public function testBaseURL1Relative()
{ {
$route = new Route(); $route = new Route();
$route->baseURL(); $route->baseURL();
$this->expectOutputString(""); $this->expectOutputString("");
} }
/** Port 80 and HTTP without module */ /**
public function test_baseURL_2_relative() * Port 80 and HTTP without module
*/
public function testBaseURL2Relative()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "80"; $_SERVER["SERVER_PORT"] = "80";
@@ -33,8 +40,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("/"); $this->expectOutputString("/");
} }
/** Port 443 and HTTPS without module */ /**
public function test_baseURL_3_relative() * Port 443 and HTTPS without module
*/
public function testBaseURL3Relative()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -46,8 +55,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("/"); $this->expectOutputString("/");
} }
/** Port 888 and HTTP without module */ /**
public function test_baseURL_4_relative() * Port 888 and HTTP without module
*/
public function testBaseURL4Relative()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -58,8 +69,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("/"); $this->expectOutputString("/");
} }
/** Port 888 and HTTPS without module */ /**
public function test_baseURL_5_relative() * Port 888 and HTTPS without module
*/
public function testBaseURL5Relative()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "888"; $_SERVER["SERVER_PORT"] = "888";
@@ -70,8 +83,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("/"); $this->expectOutputString("/");
} }
/** Port 80 and HTTP with module */ /**
public function test_baseURL_2_module_relative() * Port 80 and HTTP with module
*/
public function testBaseURL2ModuleRelative()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -82,8 +97,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("/"); $this->expectOutputString("/");
} }
/** Port 443 and HTTPS with module */ /**
public function test_baseURL_3_module_relative() * Port 443 and HTTPS with module
*/
public function testBaseURL3ModuleRelative()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "443"; $_SERVER["SERVER_PORT"] = "443";
@@ -94,8 +111,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("/"); $this->expectOutputString("/");
} }
/** Port 888 and HTTP with module */ /**
public function test_baseURL_4_module_relative() * Port 888 and HTTP with module
*/
public function testBaseURL4ModuleRelative()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -106,8 +125,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("/"); $this->expectOutputString("/");
} }
/** Port 888 and HTTPS with module */ /**
public function test_baseURL_5_module_relative() * Port 888 and HTTPS with module
*/
public function testBaseURL5ModuleRelative()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "888"; $_SERVER["SERVER_PORT"] = "888";
@@ -119,16 +140,20 @@ class RouteTest extends \PHPUnit_Framework_TestCase
} }
/// ABSOLUTE /// /// ABSOLUTE ///
/** Entry null */ /**
public function test_baseURL_1_absolute() * Entry null
*/
public function testBaseURL1Absolute()
{ {
$route = new Route(); $route = new Route();
$route->baseURL(false, true); $route->baseURL(false, true);
$this->expectOutputString(""); $this->expectOutputString("");
} }
/** Port 80 and HTTP without module */ /**
public function test_baseURL_2_absolute() * Port 80 and HTTP without module
*/
public function testBaseURL2Absolute()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "80"; $_SERVER["SERVER_PORT"] = "80";
@@ -138,8 +163,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("https://localhost:80/"); $this->expectOutputString("https://localhost:80/");
} }
/** Port 443 and HTTPS without module */ /**
public function test_baseURL_3_absolute() * Port 443 and HTTPS without module
*/
public function testBaseURL3Absolute()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -151,8 +178,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("https://localhost/"); $this->expectOutputString("https://localhost/");
} }
/** Port 888 and HTTP without module */ /**
public function test_baseURL_4_absolute() * Port 888 and HTTP without module
*/
public function testBaseURL4Absolute()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -163,8 +192,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("http://localhost:888/"); $this->expectOutputString("http://localhost:888/");
} }
/** Port 888 and HTTPS without module */ /**
public function test_baseURL_5_absolute() * Port 888 and HTTPS without module
*/
public function testBaseURL5Absolute()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "888"; $_SERVER["SERVER_PORT"] = "888";
@@ -175,8 +206,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("https://localhost:888/"); $this->expectOutputString("https://localhost:888/");
} }
/** Port 80 and HTTP with module */ /**
public function test_baseURL_2_module_absolute() * Port 80 and HTTP with module
*/
public function testBaseURL2ModuleAbsolute()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -187,8 +220,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("http://localhost/"); $this->expectOutputString("http://localhost/");
} }
/** Port 443 and HTTPS with module */ /**
public function test_baseURL_3_module_absolute() * Port 443 and HTTPS with module
*/
public function testBaseURL3ModuleAbsolute()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "443"; $_SERVER["SERVER_PORT"] = "443";
@@ -199,8 +234,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("https://localhost/"); $this->expectOutputString("https://localhost/");
} }
/** Port 888 and HTTP with module */ /**
public function test_baseURL_4_module_absolute() * Port 888 and HTTP with module
*/
public function testBaseURL4ModuleAbsolute()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -211,8 +248,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("http://localhost:888/"); $this->expectOutputString("http://localhost:888/");
} }
/** Port 888 and HTTPS with module */ /**
public function test_baseURL_5_module_absolute() * Port 888 and HTTPS with module
*/
public function testBaseURL5ModuleAbsolute()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "888"; $_SERVER["SERVER_PORT"] = "888";
@@ -224,8 +263,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
} }
/// REQUESTURL /// /// REQUESTURL ///
/** Port 80 and HTTP requestURL */ /**
public function test_requestURL_2_direct() * Port 80 and HTTP requestURL
*/
public function testRequestURL2Direct()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -237,8 +278,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("index.php?url=bla"); $this->expectOutputString("index.php?url=bla");
} }
/** Port 443 and HTTPS requestURL */ /**
public function test_requestURL_3_direct() * Port 443 and HTTPS requestURL
*/
public function testRequestURL3Direct()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "443"; $_SERVER["SERVER_PORT"] = "443";
@@ -250,8 +293,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("index.php?var=1"); $this->expectOutputString("index.php?var=1");
} }
/** Port 888 and HTTP requestURL */ /**
public function test_requestURL_4_direct() * Port 888 and HTTP requestURL
*/
public function testRequestURL4Direct()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -263,8 +308,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("index.php?var=1"); $this->expectOutputString("index.php?var=1");
} }
/** Port 888 and HTTPS requestURL */ /**
public function test_requestURL_5_direct() * Port 888 and HTTPS requestURL
*/
public function testRequestURL5Direct()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "888"; $_SERVER["SERVER_PORT"] = "888";
@@ -276,8 +323,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("index.php?var=1"); $this->expectOutputString("index.php?var=1");
} }
/** Port 80 and HTTP requestURL */ /**
public function test_requestURL_2_rewrite() * Port 80 and HTTP requestURL
*/
public function testRequestURL2Rewrite()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -289,8 +338,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("bla"); $this->expectOutputString("bla");
} }
/** Port 443 and HTTPS requestURL */ /**
public function test_requestURL_3_rewrite() * Port 443 and HTTPS requestURL
*/
public function testRequestURL3Rewrite()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "443"; $_SERVER["SERVER_PORT"] = "443";
@@ -302,8 +353,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("var=1"); $this->expectOutputString("var=1");
} }
/** Port 888 and HTTP requestURL */ /**
public function test_requestURL_4_rewrite() * Port 888 and HTTP requestURL
*/
public function testRequestURL4Rewrite()
{ {
unset($_SERVER["HTTPS"]); unset($_SERVER["HTTPS"]);
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
@@ -315,8 +368,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("var=1"); $this->expectOutputString("var=1");
} }
/** Port 888 and HTTPS requestURL */ /**
public function test_requestURL_5_rewrite() * Port 888 and HTTPS requestURL
*/
public function testRequestURL5Rewrite()
{ {
$_SERVER["SERVER_NAME"] = "localhost"; $_SERVER["SERVER_NAME"] = "localhost";
$_SERVER["SERVER_PORT"] = "888"; $_SERVER["SERVER_PORT"] = "888";
@@ -328,8 +383,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
$this->expectOutputString("var=1"); $this->expectOutputString("var=1");
} }
/** Ratelimiting in errors */ /**
public function test_errorRateLimit1() * Ratelimiting in errors
*/
public function testErrorRateLimit1()
{ {
$route = new Route(); $route = new Route();
$route->ratelimiter->storageDir = "/tmp/ratelimit-" . time(); $route->ratelimiter->storageDir = "/tmp/ratelimit-" . time();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Rss; use Domframework\Rss;
/** Test the RSS */ /**
* Test the RSS
*/
class RssTest extends \PHPUnit_Framework_TestCase class RssTest extends \PHPUnit_Framework_TestCase
{ {
public function test_empty0() public function testEmpty0()
{ {
// Empty // Empty
$this->expectException("Exception", "No title is provided for this RSS"); $this->expectException("Exception", "No title is provided for this RSS");
@@ -21,7 +24,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
$res = $rss->asXML(); $res = $rss->asXML();
} }
public function test_functional1() public function testFunctional1()
{ {
// Functionnal 1 // Functionnal 1
$rss = new Rss(); $rss = new Rss();
@@ -60,7 +63,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
"); ");
} }
public function test_error1() public function testError1()
{ {
// Missing global description // Missing global description
$this->expectException( $this->expectException(
@@ -74,7 +77,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
$res = $rss->asXML(); $res = $rss->asXML();
} }
public function test_error2() public function testError2()
{ {
// Missing global link // Missing global link
$this->expectException("Exception", "No link is provided for this RSS"); $this->expectException("Exception", "No link is provided for this RSS");
@@ -85,7 +88,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
$res = $rss->asXML(); $res = $rss->asXML();
} }
public function test_error3() public function testError3()
{ {
// Missing global title // Missing global title
$this->expectException("Exception", "No title is provided for this RSS"); $this->expectException("Exception", "No title is provided for this RSS");
@@ -96,7 +99,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
$res = $rss->asXML(); $res = $rss->asXML();
} }
public function test_error4() public function testError4()
{ {
// Invalid date provided // Invalid date provided
$this->expectException( $this->expectException(
@@ -112,7 +115,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
$res = $rss->asXML(); $res = $rss->asXML();
} }
public function test_itemError1() public function testItemError1()
{ {
// Empty Item provided // Empty Item provided
$this->expectException( $this->expectException(
@@ -129,7 +132,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
$res = $rss->asXML(); $res = $rss->asXML();
} }
public function test_itemError2() public function testItemError2()
{ {
// Item without Title and Description // Item without Title and Description
$this->expectException( $this->expectException(
@@ -146,7 +149,7 @@ class RssTest extends \PHPUnit_Framework_TestCase
$res = $rss->asXML(); $res = $rss->asXML();
} }
public function test_itemError3() public function testItemError3()
{ {
// Item with invalid date // Item with invalid date
$this->expectException( $this->expectException(

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,12 +11,13 @@ namespace Domframework\Tests;
use Domframework\Sitemap; use Domframework\Sitemap;
/** Test the Sitemap.php file /**
* Test the Sitemap.php file
*/ */
class SitemapTest extends \PHPUnit_Framework_TestCase class SitemapTest extends \PHPUnit_Framework_TestCase
{ {
// Empty Sitemap // Empty Sitemap
public function test_EmptySitemap_1() public function testEmptySitemap1()
{ {
$sitemap = new Sitemap(); $sitemap = new Sitemap();
$res = $sitemap->analyze("", "http://example.com"); $res = $sitemap->analyze("", "http://example.com");
@@ -23,7 +25,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
} }
// Empty Sitemap // Empty Sitemap
public function test_EmptySitemap_2() public function testEmptySitemap2()
{ {
$sitemap = new Sitemap(); $sitemap = new Sitemap();
$res = $sitemap->analyze(" ", "http://example.com"); $res = $sitemap->analyze(" ", "http://example.com");
@@ -31,7 +33,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
} }
// Textual Sitemap // Textual Sitemap
public function test_TextualSitemap_1() public function testTextualSitemap1()
{ {
$sitemap = new Sitemap(); $sitemap = new Sitemap();
$res = $sitemap->analyze("http://example.com", "http://example.com"); $res = $sitemap->analyze("http://example.com", "http://example.com");
@@ -41,7 +43,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
"sitemaps" => []] "sitemaps" => []]
); );
} }
public function test_TextualSitemap_2() public function testTextualSitemap2()
{ {
$sitemap = new Sitemap(); $sitemap = new Sitemap();
$res = $sitemap->analyze( $res = $sitemap->analyze(
@@ -56,7 +58,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
} }
// XML Sitemap // XML Sitemap
public function test_XMLSitemap_1() public function testXMLSitemap1()
{ {
$sitemap = new Sitemap(); $sitemap = new Sitemap();
$res = $sitemap->analyze( $res = $sitemap->analyze(
@@ -84,7 +86,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
); );
} }
public function test_XMLSitemap_2() public function testXMLSitemap2()
{ {
$sitemap = new Sitemap(); $sitemap = new Sitemap();
$res = $sitemap->analyze( $res = $sitemap->analyze(

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,11 +11,12 @@ namespace Domframework\Tests;
use Domframework\Spfcheck; use Domframework\Spfcheck;
/** Test the Spfcheck tools /**
* Test the Spfcheck tools
*/ */
class SpfcheckTest extends \PHPUnit_Framework_TestCase class SpfcheckTest extends \PHPUnit_Framework_TestCase
{ {
public function test_getRecords_NoSPF() public function testGetRecordsNoSPF()
{ {
$this->expectException( $this->expectException(
"Exception", "Exception",
@@ -26,18 +28,18 @@ class SpfcheckTest extends \PHPUnit_Framework_TestCase
$res = $spfcheck->getRecords("notfound.tester.fournier38.fr"); $res = $spfcheck->getRecords("notfound.tester.fournier38.fr");
} }
public function test_getRecords_SPFReject() public function testGetRecordsSPFReject()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("reject.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("reject.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("reject.spf.tester.fournier38.fr" => ["reject.spf.tester.fournier38.fr" =>
array ("-all" => array ())) ["-all" => []]]
); );
} }
public function test_getRecords_Loop() public function testGetRecordsLoop()
{ {
$this->expectException( $this->expectException(
"Exception", "Exception",
@@ -46,267 +48,267 @@ class SpfcheckTest extends \PHPUnit_Framework_TestCase
); );
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("loop.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("loop.spf.tester.fournier38.fr");
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
public function test_getRecords_Include_emptyInclude() public function testGetRecordsIncludeEmptyInclude()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("includeempty.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("includeempty.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("includeempty.spf.tester.fournier38.fr" => ["includeempty.spf.tester.fournier38.fr" =>
array ("include:" => array (), "-all" => array ())) ["include:" => [], "-all" => []]]
); );
} }
public function test_getRecords_Redirect_emptyRedirect() public function testGetRecordsRedirectEmptyRedirect()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("redirectempty.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("redirectempty.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("redirectempty.spf.tester.fournier38.fr" => ["redirectempty.spf.tester.fournier38.fr" =>
array ("redirect=" => array (), "-all" => array ())) ["redirect=" => [], "-all" => []]]
); );
} }
public function test_getRecords_MX_emptyMX() public function testGetRecordsMXEmptyMX()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("mx.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("mx.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("mx.spf.tester.fournier38.fr" => ["mx.spf.tester.fournier38.fr" =>
array ("mx" => array (), "-all" => array ())) ["mx" => [], "-all" => []]]
); );
} }
public function test_getRecords_MX_validMX() public function testGetRecordsMXValidMX()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("mxvalid.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("mxvalid.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("mxvalid.spf.tester.fournier38.fr" => array ( ["mxvalid.spf.tester.fournier38.fr" => [
"mx:tester.fournier38.fr" => array ( "mx:tester.fournier38.fr" => [
"2a01:e0a:2a7:9cd1::103", "2a01:e0a:2a7:9cd1::103",
"2a01:e0a:392:ab60::206", "2a01:e0a:392:ab60::206",
"82.64.75.195", "82.64.75.195",
"82.66.67.64"), "82.66.67.64"],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_A_emptyA() public function testGetRecordsAEmptyA()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("a.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("a.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("a.spf.tester.fournier38.fr" => ["a.spf.tester.fournier38.fr" =>
array ("a" => array (), "-all" => array ())) ["a" => [], "-all" => []]]
); );
} }
public function test_getRecords_A_validA() public function testGetRecordsAValidA()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("avalid.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("avalid.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("avalid.spf.tester.fournier38.fr" => array ( ["avalid.spf.tester.fournier38.fr" => [
"a:tester.fournier38.fr" => array ( "a:tester.fournier38.fr" => [
"2a01:e0a:2a7:9cd1::100", "2a01:e0a:2a7:9cd1::100",
"82.64.75.195",), "82.64.75.195",],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_IP4_emptyIP4() public function testGetRecordsIP4EmptyIP4()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("ip4empty.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("ip4empty.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("ip4empty.spf.tester.fournier38.fr" => array ( ["ip4empty.spf.tester.fournier38.fr" => [
"ip4:" => array (), "ip4:" => [],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_IP4_invalidIP4() public function testGetRecordsIP4InvalidIP4()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("ip4invalid.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("ip4invalid.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("ip4invalid.spf.tester.fournier38.fr" => array ( ["ip4invalid.spf.tester.fournier38.fr" => [
"ip4:0::1" => array (), "ip4:0::1" => [],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_IP4_validIP4() public function testGetRecordsIP4ValidIP4()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("ip4valid.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("ip4valid.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("ip4valid.spf.tester.fournier38.fr" => array ( ["ip4valid.spf.tester.fournier38.fr" => [
"ip4:192.168.1.1" => array ("192.168.1.1"), "ip4:192.168.1.1" => ["192.168.1.1"],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_IP6_emptyIP6() public function testGetRecordsIP6EmptyIP6()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("ip6empty.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("ip6empty.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("ip6empty.spf.tester.fournier38.fr" => array ( ["ip6empty.spf.tester.fournier38.fr" => [
"ip6:" => array (), "ip6:" => [],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_IP6_invalidIP6() public function testGetRecordsIP6InvalidIP6()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("ip6invalid.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("ip6invalid.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("ip6invalid.spf.tester.fournier38.fr" => array ( ["ip6invalid.spf.tester.fournier38.fr" => [
"ip6:192.168.1.1" => array (), "ip6:192.168.1.1" => [],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_IP6_validIP6() public function testGetRecordsIP6ValidIP6()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("ip6valid.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("ip6valid.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("ip6valid.spf.tester.fournier38.fr" => array ( ["ip6valid.spf.tester.fournier38.fr" => [
"ip6:0::1" => array ("0::1"), "ip6:0::1" => ["0::1"],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_PTR() public function testGetRecordsPTR()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("ptrvalid.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("ptrvalid.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("ptrvalid.spf.tester.fournier38.fr" => array ( ["ptrvalid.spf.tester.fournier38.fr" => [
"ptr" => array (), "ptr" => [],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_All_Multiple() public function testGetRecordsAllMultiple()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("allmultiple.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("allmultiple.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("allmultiple.spf.tester.fournier38.fr" => array ( ["allmultiple.spf.tester.fournier38.fr" => [
"+all" => array (), "+all" => [],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_getRecords_All_NotEnd() public function testGetRecordsAllNotEnd()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("allnotend.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("allnotend.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("allnotend.spf.tester.fournier38.fr" => array ( ["allnotend.spf.tester.fournier38.fr" => [
"+all" => array (), "+all" => [],
"mx" => array ())) "mx" => []]]
); );
} }
public function test_getRecords_All_NotSet() public function testGetRecordsAllNotSet()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("allnotset.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("allnotset.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("allnotset.spf.tester.fournier38.fr" => array ( ["allnotset.spf.tester.fournier38.fr" => [
"mx" => array ())) "mx" => []]]
); );
} }
public function test_wideIPRange() public function testWideIPRange()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$spfcheck->getRecords("wide.spf.tester.fournier38.fr"); $spfcheck->getRecords("wide.spf.tester.fournier38.fr");
$res = $spfcheck->getErrors(); $res = $spfcheck->getErrors();
$this->assertSame( $this->assertSame(
$res, $res,
array ("wide.spf.tester.fournier38.fr" => array ( ["wide.spf.tester.fournier38.fr" => [
"ip4:213.131.32.0/2" => "Invalid ip4 set for domain 'wide.spf.tester.fournier38.fr' : Mask '/2' too wide", "ip4:213.131.32.0/2" => "Invalid ip4 set for domain 'wide.spf.tester.fournier38.fr' : Mask '/2' too wide",
"ip6:2001::/20" => "Invalid ip6 set for domain 'wide.spf.tester.fournier38.fr' : Mask '/20' too wide" "ip6:2001::/20" => "Invalid ip6 set for domain 'wide.spf.tester.fournier38.fr' : Mask '/20' too wide"
)) ]]
); );
} }
public function test_recordsWithPlus() public function testRecordsWithPlus()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("plus.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("plus.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("plus.spf.tester.fournier38.fr" => array ( ["plus.spf.tester.fournier38.fr" => [
"+a" => array (), "+a" => [],
"+mx" => array (), "+mx" => [],
"+ip4:178.33.236.5" => array ("178.33.236.5"), "+ip4:178.33.236.5" => ["178.33.236.5"],
"-ip4:137.74.69.64" => array ("137.74.69.64"), "-ip4:137.74.69.64" => ["137.74.69.64"],
"+ip4:51.254.45.81" => array ("51.254.45.81"), "+ip4:51.254.45.81" => ["51.254.45.81"],
"-all" => array (), "-all" => [],
)) ]]
); );
} }
public function test_getRecords_Unknown() public function testGetRecordsUnknown()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->getRecords("unknown.spf.tester.fournier38.fr"); $res = $spfcheck->getRecords("unknown.spf.tester.fournier38.fr");
$this->assertSame( $this->assertSame(
$res, $res,
array ("unknown.spf.tester.fournier38.fr" => array ( ["unknown.spf.tester.fournier38.fr" => [
"unknown" => array (), "unknown" => [],
"-all" => array ())) "-all" => []]]
); );
} }
public function test_ipCheckToSPF_OK_inA() public function testIpCheckToSPFOKInA()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "178.33.236.5"); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "178.33.236.5");
$this->assertSame($res, "PASS"); $this->assertSame($res, "PASS");
} }
public function test_ipCheckToSPF_FAIL_inALL() public function testIpCheckToSPFFAILInALL()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5"); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5");
$this->assertSame($res, "FAIL"); $this->assertSame($res, "FAIL");
} }
public function test_ipCheckToSPF_OK_inALL() public function testIpCheckToSPFOKInALL()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5"); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5");
$this->assertSame($res, "FAIL"); $this->assertSame($res, "FAIL");
} }
public function test_ipCheckToSPF_FAIL_inIP4() public function testIpCheckToSPFFAILInIP4()
{ {
$spfcheck = new Spfcheck(); $spfcheck = new Spfcheck();
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "137.74.69.64"); $res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "137.74.69.64");

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,17 +11,19 @@ namespace Domframework\Tests;
use Domframework\Sse; use Domframework\Sse;
/** Test the domframework Server-Sent Events part */ /**
* Test the domframework Server-Sent Events part
*/
class SseTest extends \PHPUnit_Framework_TestCase class SseTest extends \PHPUnit_Framework_TestCase
{ {
public function test_loop_NOTDEFINED() public function testLoopNOTDEFINED()
{ {
$this->expectException("Exception"); $this->expectException("Exception");
$sse = new Sse(); $sse = new Sse();
$res = $sse->loop(); $res = $sse->loop();
} }
public function test_loop_JUSTPING() public function testLoopJUSTPING()
{ {
$this->expectOutputString(str_repeat(": ping\n\n", 5)); $this->expectOutputString(str_repeat(": ping\n\n", 5));
$sse = new Sse(); $sse = new Sse();
@@ -32,7 +35,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
$sse->loop(); $sse->loop();
} }
public function test_loop_SKIP_START() public function testLoopSKIPSTART()
{ {
$this->expectOutputString(str_repeat(": ping\n\n", 5)); $this->expectOutputString(str_repeat(": ping\n\n", 5));
$sse = new Sse(); $sse = new Sse();
@@ -45,7 +48,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
$sse->loop(); $sse->loop();
} }
public function test_loop_DATA() public function testLoopDATA()
{ {
$this->expectOutputString(str_repeat(": ping\n\n", 4) . $this->expectOutputString(str_repeat(": ping\n\n", 4) .
"data: WILL BE SEEN\n\n: ping\n\n"); "data: WILL BE SEEN\n\n: ping\n\n");
@@ -62,7 +65,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
$sse->loop(); $sse->loop();
} }
public function test_loop_EVENTS() public function testLoopEVENTS()
{ {
$this->expectOutputString(str_repeat(": ping\n\n", 4) . $this->expectOutputString(str_repeat(": ping\n\n", 4) .
"event: event1\ndata: WILL BE SEEN 1\n\n" . "event: event1\ndata: WILL BE SEEN 1\n\n" .
@@ -86,7 +89,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
$sse->loop(); $sse->loop();
} }
public function test_loop_HandlersEvent() public function testLoopHandlersEvent()
{ {
$this->expectOutputString(str_repeat(": ping\n\n", 4) . $this->expectOutputString(str_repeat(": ping\n\n", 4) .
"event: event1\ndata: will be seen 1\n\n" . "event: event1\ndata: will be seen 1\n\n" .
@@ -116,7 +119,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
$sse->loop(); $sse->loop();
} }
public function test_loop_HandlerDataonly() public function testLoopHandlerDataonly()
{ {
$this->expectOutputString(str_repeat(": ping\n\n", 4) . $this->expectOutputString(str_repeat(": ping\n\n", 4) .
"data: will be seen 1\n\n" . "data: will be seen 1\n\n" .
@@ -139,7 +142,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
$sse->loop(); $sse->loop();
} }
public function test_loop_HandlerDataonlyWithParams() public function testLoopHandlerDataonlyWithParams()
{ {
$this->expectOutputString(str_repeat(": ping\n\n", 4) . $this->expectOutputString(str_repeat(": ping\n\n", 4) .
"data: PREwill be seen 1POST\n\n" . "data: PREwill be seen 1POST\n\n" .

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,10 +11,12 @@ namespace Domframework\Tests;
use Domframework\Tcpclient; use Domframework\Tcpclient;
/** Test the TCP client */ /**
* Test the TCP client
*/
class TcpclientTest extends \PHPUnit_Framework_TestCase class TcpclientTest extends \PHPUnit_Framework_TestCase
{ {
public function test_GoogleIPv4() public function testGoogleIPv4()
{ {
$tcpclient = new Tcpclient("www.google.fr", 80); $tcpclient = new Tcpclient("www.google.fr", 80);
$tcpclient->preferIPv4(true); $tcpclient->preferIPv4(true);
@@ -31,7 +34,7 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK"); $this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
} }
public function test_GoogleIPv4orIpv6() public function testGoogleIPv4orIpv6()
{ {
$tcpclient = new Tcpclient("www.google.fr", 80); $tcpclient = new Tcpclient("www.google.fr", 80);
$tcpclient->connect(); $tcpclient->connect();
@@ -48,7 +51,7 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK"); $this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
} }
public function test_GoogleSSL() public function testGoogleSSL()
{ {
$tcpclient = new Tcpclient("www.google.fr", 443); $tcpclient = new Tcpclient("www.google.fr", 443);
$tcpclient->connect(); $tcpclient->connect();
@@ -66,7 +69,7 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK"); $this->assertSame(substr($res, 0, 15), "HTTP/1.1 200 OK");
} }
public function test_GoogleSSLIPv6() public function testGoogleSSLIPv6()
{ {
$tcpclient = new Tcpclient("ipv6.google.com", 443); $tcpclient = new Tcpclient("ipv6.google.com", 443);
$tcpclient->connect(); $tcpclient->connect();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,87 +11,89 @@ namespace Domframework\Tests;
use Domframework\Userssql; use Domframework\Userssql;
/** Test the Userssql.php file */ /**
* Test the Userssql.php file
*/
class UserssqlTest extends \PHPUnit_Framework_TestCase class UserssqlTest extends \PHPUnit_Framework_TestCase
{ {
public function test_clean() public function testClean()
{ {
@unlink("/tmp/database.db"); @unlink("/tmp/database.db");
} }
public function test_initStorage() public function testInitStorage()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->initStorage(); $res = $userssql->initStorage();
$this->assertSame($res, 0); $this->assertSame($res, 0);
} }
public function test_listusers1() public function testListusers1()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->listusers(); $res = $userssql->listusers();
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
public function test_adduser1() public function testAdduser1()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->adduser("toto@toto.com", "Toto", "Toto2"); $res = $userssql->adduser("toto@toto.com", "Toto", "Toto2");
$this->assertSame($res, "toto@toto.com"); $this->assertSame($res, "toto@toto.com");
} }
public function test_listusers2() public function testListusers2()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->listusers(); $res = $userssql->listusers();
$this->assertSame($res, array (array ("email" => "toto@toto.com", $this->assertSame($res, [["email" => "toto@toto.com",
"firstname" => "Toto", "firstname" => "Toto",
"lastname" => "Toto2"))); "lastname" => "Toto2"]]);
} }
public function test_overwritepassword1() public function testOverwritepassword1()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->overwritepassword("toto@toto.com", "PassW0rd"); $res = $userssql->overwritepassword("toto@toto.com", "PassW0rd");
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_checkValidPassword1() public function testCheckValidPassword1()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd"); $res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_checkValidPassword2() public function testCheckValidPassword2()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->checkValidPassword("toto@toto.com", "BAD PASSWD"); $res = $userssql->checkValidPassword("toto@toto.com", "BAD PASSWD");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_changepassword1() public function testChangepassword1()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->changepassword("toto@toto.com", "PassW0rd", "NEW PASS!"); $res = $userssql->changepassword("toto@toto.com", "PassW0rd", "NEW PASS!");
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_checkValidPassword3() public function testCheckValidPassword3()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd"); $res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_checkValidPassword4() public function testCheckValidPassword4()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->checkValidPassword("toto@toto.com", "NEW PASS!"); $res = $userssql->checkValidPassword("toto@toto.com", "NEW PASS!");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_updateuser() public function testUpdateuser()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->updateuser( $res = $userssql->updateuser(
@@ -102,33 +105,33 @@ class UserssqlTest extends \PHPUnit_Framework_TestCase
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_listusers3() public function testListusers3()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->listusers(); $res = $userssql->listusers();
$this->assertSame($res, array (array ("email" => "titi@titi.com", $this->assertSame($res, [["email" => "titi@titi.com",
"firstname" => "titi", "firstname" => "titi",
"lastname" => "titi2"))); "lastname" => "titi2"]]);
} }
public function test_checkValidPassword5() public function testCheckValidPassword5()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->checkValidPassword("titi@titi.com", "NEW PASS!"); $res = $userssql->checkValidPassword("titi@titi.com", "NEW PASS!");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_deluser() public function testDeluser()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->deluser("titi@titi.com"); $res = $userssql->deluser("titi@titi.com");
$this->assertSame($res, 1); $this->assertSame($res, 1);
} }
public function test_listusers4() public function testListusers4()
{ {
$userssql = new Userssql("sqlite:///tmp/database.db"); $userssql = new Userssql("sqlite:///tmp/database.db");
$res = $userssql->listusers(); $res = $userssql->listusers();
$this->assertSame($res, array ()); $this->assertSame($res, []);
} }
} }

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,16 +11,18 @@ namespace Domframework\Tests;
use Domframework\Uuid; use Domframework\Uuid;
/** Test the Uuid.php file */ /**
* Test the Uuid.php file
*/
class UuidTest extends \PHPUnit_Framework_TestCase class UuidTest extends \PHPUnit_Framework_TestCase
{ {
public function test_uuid1() public function testUuid1()
{ {
$res = Uuid::uuid4(); $res = Uuid::uuid4();
$this->assertRegExp(36, strlen($res)); $this->assertRegExp(36, strlen($res));
} }
public function test_uuid2() public function testUuid2()
{ {
$res = Uuid::uuid4(); $res = Uuid::uuid4();
$this->assertRegExp(true, strspn("0123456789abcdef-", $res) == $this->assertRegExp(true, strspn("0123456789abcdef-", $res) ==

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,58 +11,60 @@ namespace Domframework\Tests;
use Domframework\Verify; use Domframework\Verify;
/** Test the Verify */ /**
* Test the Verify
*/
class VerifyTest extends \PHPUnit_Framework_TestCase class VerifyTest extends \PHPUnit_Framework_TestCase
{ {
/////////////// ///////////////
// DATES // // DATES //
/////////////// ///////////////
public function test_is_datetimeSQL1() public function testIsDatetimeSQL1()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_datetimeSQL("2017-04-13 22:55:17"); $res = $verify->is_datetimeSQL("2017-04-13 22:55:17");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_is_datetimeSQL2() public function testIsDatetimeSQL2()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_datetimeSQL("2017-13-55 22:55:17"); $res = $verify->is_datetimeSQL("2017-13-55 22:55:17");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_staticIs_datetimeSQL1() public function testStaticIsDatetimeSQL1()
{ {
$res = Verify::staticIs_datetimeSQL("2017-04-13 22:55:17"); $res = Verify::staticIs_datetimeSQL("2017-04-13 22:55:17");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_staticIs_datetimeSQL2() public function testStaticIsDatetimeSQL2()
{ {
$res = Verify::staticIs_datetimeSQL("2017-13-55 22:55:17"); $res = Verify::staticIs_datetimeSQL("2017-13-55 22:55:17");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_is_dateSQL1() public function testIsDateSQL1()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_dateSQL("2017-04-13"); $res = $verify->is_dateSQL("2017-04-13");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_is_dateSQL2() public function testIsDateSQL2()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_dateSQL("2017-13-55"); $res = $verify->is_dateSQL("2017-13-55");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_staticIs_dateSQL1() public function testStaticIsDateSQL1()
{ {
$res = Verify::staticIs_dateSQL("2017-04-13"); $res = Verify::staticIs_dateSQL("2017-04-13");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_staticIs_dateSQL2() public function testStaticIsDateSQL2()
{ {
$res = Verify::staticIs_dateSQL("2017-13-55"); $res = Verify::staticIs_dateSQL("2017-13-55");
$this->assertSame($res, false); $this->assertSame($res, false);
@@ -71,13 +74,13 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
///////////////// /////////////////
// STRINGS // // STRINGS //
///////////////// /////////////////
public function test_staticIsAllowedChars_1() public function testStaticIsAllowedChars1()
{ {
$res = Verify::staticIsAllowedChars("éléphant", "abcd"); $res = Verify::staticIsAllowedChars("éléphant", "abcd");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_staticIsAllowedChars_2() public function testStaticIsAllowedChars2()
{ {
$res = Verify::staticIsAllowedChars("éléphant", "anhplté"); $res = Verify::staticIsAllowedChars("éléphant", "anhplté");
$this->assertSame($res, true); $this->assertSame($res, true);
@@ -86,25 +89,25 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
///////////////// /////////////////
// NUMBERS // // NUMBERS //
///////////////// /////////////////
public function test_staticIs_integer1() public function testStaticIsInteger1()
{ {
$res = Verify::staticIs_integer("2017-04-13 22:55:17"); $res = Verify::staticIs_integer("2017-04-13 22:55:17");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_staticIs_integer2() public function testStaticIsInteger2()
{ {
$res = Verify::staticIs_integer("01234"); $res = Verify::staticIs_integer("01234");
$this->assertSame($res, true); $this->assertSame($res, true);
} }
public function test_staticIs_integer3() public function testStaticIsInteger3()
{ {
$res = Verify::staticIs_integer("0x1234"); $res = Verify::staticIs_integer("0x1234");
$this->assertSame($res, false); $this->assertSame($res, false);
} }
public function test_staticIs_integer4() public function testStaticIsInteger4()
{ {
$res = Verify::staticIs_integer(""); $res = Verify::staticIs_integer("");
$this->assertSame($res, false); $this->assertSame($res, false);
@@ -117,27 +120,27 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
///////////// /////////////
// URL // // URL //
///////////// /////////////
public function test_is_url1() public function testIsUrl1()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_url("invalid"); $res = $verify->is_url("invalid");
$this->assertsame($res, false); $this->assertsame($res, false);
} }
public function test_is_url2() public function testIsUrl2()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_url("http://valid"); $res = $verify->is_url("http://valid");
$this->assertsame($res, true); $this->assertsame($res, true);
} }
public function test_staticIs_url1() public function testStaticIsUrl1()
{ {
$res = Verify::staticIs_url("invalid"); $res = Verify::staticIs_url("invalid");
$this->assertsame($res, false); $this->assertsame($res, false);
} }
public function test_staticIs_url2() public function testStaticIsUrl2()
{ {
$res = Verify::staticIs_url("http://valid"); $res = Verify::staticIs_url("http://valid");
$this->assertsame($res, true); $this->assertsame($res, true);
@@ -146,40 +149,40 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
//////////////// ////////////////
// OTHERS // // OTHERS //
//////////////// ////////////////
public function test_is_UUID1() public function testIsUUID1()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_UUID("ca39275f-9224-425f-ba94-efce2aa5b52c"); $res = $verify->is_UUID("ca39275f-9224-425f-ba94-efce2aa5b52c");
$this->assertsame($res, true); $this->assertsame($res, true);
} }
public function test_is_UUID2() public function testIsUUID2()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_UUID("zz39275f-9224-425f-ba94-efce2aa5b52c"); $res = $verify->is_UUID("zz39275f-9224-425f-ba94-efce2aa5b52c");
$this->assertsame($res, false); $this->assertsame($res, false);
} }
public function test_is_UUID3() public function testIsUUID3()
{ {
$verify = new Verify(); $verify = new Verify();
$res = $verify->is_UUID("2c"); $res = $verify->is_UUID("2c");
$this->assertsame($res, false); $this->assertsame($res, false);
} }
public function test_staticis_UUID1() public function testStaticisUUID1()
{ {
$res = Verify::staticis_UUID("ca39275f-9224-425f-ba94-efce2aa5b52c"); $res = Verify::staticis_UUID("ca39275f-9224-425f-ba94-efce2aa5b52c");
$this->assertsame($res, true); $this->assertsame($res, true);
} }
public function test_staticis_UUID2() public function testStaticisUUID2()
{ {
$res = Verify::staticis_UUID("zz39275f-9224-425f-ba94-efce2aa5b52c"); $res = Verify::staticis_UUID("zz39275f-9224-425f-ba94-efce2aa5b52c");
$this->assertsame($res, false); $this->assertsame($res, false);
} }
public function test_staticis_UUID3() public function testStaticisUUID3()
{ {
$res = Verify::staticis_UUID("2c"); $res = Verify::staticis_UUID("2c");
$this->assertsame($res, false); $this->assertsame($res, false);

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,7 +11,9 @@ namespace Domframework\Tests;
use Domframework\Xdiff; use Domframework\Xdiff;
/** Test the domframework xdiff part */ /**
* Test the domframework xdiff part
*/
class XdiffTest extends \PHPUnit_Framework_TestCase class XdiffTest extends \PHPUnit_Framework_TestCase
{ {
// Declaration of $string1 and $string2 // Declaration of $string1 and $string2
@@ -134,7 +137,7 @@ to this document.
"); ");
} }
public function test_diff_normal_3() public function testDiffNormal3()
{ {
// Mode normal // Mode normal
$xdiff = new Xdiff(); $xdiff = new Xdiff();

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -10,17 +11,19 @@ namespace Domframework\Tests;
use Domframework\Xmppclient; use Domframework\Xmppclient;
/** Test the domframework xmppclient part */ /**
* Test the domframework xmppclient part
*/
class xmppclientTest extends \PHPUnit_Framework_TestCase class xmppclientTest extends \PHPUnit_Framework_TestCase
{ {
public function test_connection_BADNAME() public function testConnectionBADNAME()
{ {
$this->expectException("Exception"); $this->expectException("Exception");
$xmppclient = new Xmppclient(); $xmppclient = new Xmppclient();
$res = $xmppclient->connect("NOTFOUND.fournier38.fr", 5222, "", ""); $res = $xmppclient->connect("NOTFOUND.fournier38.fr", 5222, "", "");
} }
public function test_connection_authenticate_1() public function testConnectionAuthenticate1()
{ {
$xmppclient = new Xmppclient(); $xmppclient = new Xmppclient();
$res = $xmppclient->connect( $res = $xmppclient->connect(
@@ -32,7 +35,7 @@ class xmppclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(is_object($res), true); $this->assertSame(is_object($res), true);
} }
public function test_connection_disco_1() public function testConnectionDisco1()
{ {
$xmppclient = new Xmppclient(); $xmppclient = new Xmppclient();
$xmppclient->connect( $xmppclient->connect(
@@ -45,7 +48,7 @@ class xmppclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(is_array($res) && count($res) > 5, true); $this->assertSame(is_array($res) && count($res) > 5, true);
} }
public function test_connection_sendMessage_1() public function testConnectionSendMessage1()
{ {
$xmppclient = new Xmppclient(); $xmppclient = new Xmppclient();
$xmppclient->connect( $xmppclient->connect(
@@ -61,7 +64,7 @@ class xmppclientTest extends \PHPUnit_Framework_TestCase
$this->assertSame(is_object($res), true); $this->assertSame(is_object($res), true);
} }
public function test_connection_sendMessage_2() public function testConnectionSendMessage2()
{ {
$xmppclient = new Xmppclient(); $xmppclient = new Xmppclient();
$xmppclient->connect( $xmppclient->connect(

View File

@@ -1,45 +1,74 @@
<?php <?php
/** Autoload */ /**
* Autoload
*/
spl_autoload_register(function ($class) { spl_autoload_register(function ($class) {
$classes = array (); $classes = [];
foreach (scandir ("src") as $file) foreach (scandir("src") as $file) {
{ $fileShort = basename($file);
$fileShort = basename ($file); if ($fileShort == "." || $fileShort == "..") {
if ($fileShort == "." || $fileShort == "..")
continue; continue;
$classFile = substr ($fileShort, 0, -4);
$classes["Domframework\\".$classFile] = "src/$file";
} }
if (key_exists ($class, $classes)) $classFile = substr($fileShort, 0, -4);
{ $classes["Domframework\\" . $classFile] = "src/$file";
@include ($classes[$class]);
} }
else if (key_exists($class, $classes)) {
{ @include($classes[$class]);
} else {
echo "ERROR : $class : doesnt exists in src\n"; echo "ERROR : $class : doesnt exists in src\n";
} }
}); });
define ("PHPUNIT", "ON-GOING"); define("PHPUNIT", "ON-GOING");
file_put_contents ("Tests/DblayerooSqliteTest.php", file_put_contents(
str_replace ("{ENGINE}", "sqlite", "Tests/DblayerooSqliteTest.php",
file_get_contents ("Tests/DblayerooComplet.php"))); str_replace(
file_put_contents ("Tests/DblayerooMySQLTest.php", "{ENGINE}",
str_replace ("{ENGINE}", "mysql", "sqlite",
file_get_contents ("Tests/DblayerooComplet.php"))); file_get_contents("Tests/DblayerooComplet.php")
file_put_contents ("Tests/DblayerooPostgreSQLTest.php", )
str_replace ("{ENGINE}", "pgsql", );
file_get_contents ("Tests/DblayerooComplet.php"))); file_put_contents(
file_put_contents ("Tests/DblayerSqliteTest.php", "Tests/DblayerooMySQLTest.php",
str_replace ("{ENGINE}", "sqlite", str_replace(
file_get_contents ("Tests/DblayerComplet.php"))); "{ENGINE}",
file_put_contents ("Tests/DblayerMySQLTest.php", "mysql",
str_replace ("{ENGINE}", "mysql", file_get_contents("Tests/DblayerooComplet.php")
file_get_contents ("Tests/DblayerComplet.php"))); )
file_put_contents ("Tests/DblayerPostgreSQLTest.php", );
str_replace ("{ENGINE}", "pgsql", file_put_contents(
file_get_contents ("Tests/DblayerComplet.php"))); "Tests/DblayerooPostgreSQLTest.php",
str_replace(
"{ENGINE}",
"pgsql",
file_get_contents("Tests/DblayerooComplet.php")
)
);
file_put_contents(
"Tests/DblayerSqliteTest.php",
str_replace(
"{ENGINE}",
"sqlite",
file_get_contents("Tests/DblayerComplet.php")
)
);
file_put_contents(
"Tests/DblayerMySQLTest.php",
str_replace(
"{ENGINE}",
"mysql",
file_get_contents("Tests/DblayerComplet.php")
)
);
file_put_contents(
"Tests/DblayerPostgreSQLTest.php",
str_replace(
"{ENGINE}",
"pgsql",
file_get_contents("Tests/DblayerComplet.php")
)
);
// vim: syntax=on filetype=php // vim: syntax=on filetype=php

View File

@@ -1,6 +1,7 @@
<?php <?php
/** DomFramework - Tests /**
* DomFramework - Tests
* @package domframework * @package domframework
* @author Dominique Fournier <dominique@fournier38.fr> * @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD * @license BSD
@@ -8,12 +9,12 @@
namespace Domframework\Tests; namespace Domframework\Tests;
$conf = array ( $conf = [
"database" => array ( "database" => [
"dsn" => "sqlite:/tmp/database.db", "dsn" => "sqlite:/tmp/database.db",
"username" => null, "username" => null,
"password" => null, "password" => null,
"driver_options" => null, "driver_options" => null,
"tableprefix" => "", "tableprefix" => "",
), ],
); ];

View File

@@ -1,7 +1,9 @@
<html> <html>
<body> <body>
Text Text
<?php if (isset ($var)) echo $var; ?> <?php if (isset($var)) {
echo $var;
} ?>
</body> </body>
</html> </html>