Compare commits
2 Commits
b017700d0a
...
0e014c6829
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e014c6829 | ||
|
|
273db5f183 |
@@ -12,6 +12,7 @@ return $config->setRules([
|
||||
//'strict_param' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
'php_unit_method_casing' => true,
|
||||
])
|
||||
->setFinder($finder)
|
||||
;
|
||||
|
||||
@@ -1,50 +1,53 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Auth;
|
||||
|
||||
/** Test the authentication */
|
||||
/**
|
||||
* Test the authentication
|
||||
*/
|
||||
class AuthTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_page_1()
|
||||
public function testPage1()
|
||||
{
|
||||
$auth = new Auth();
|
||||
$res = $auth->pageHTML("http://localhost");
|
||||
$this->assertSame(!! strpos($res, "<form "), true);
|
||||
}
|
||||
|
||||
public function test_Message()
|
||||
public function testMessage()
|
||||
{
|
||||
$auth = new Auth();
|
||||
$res = $auth->pageHTML("http://localhost", "MESSAGE");
|
||||
$this->assertSame(!! strpos($res, "MESSAGE"), true);
|
||||
}
|
||||
|
||||
public function test_URL_1()
|
||||
public function testURL1()
|
||||
{
|
||||
$auth = new Auth();
|
||||
$res = $auth->pageHTML("http://localhost", "MESSAGE", "URL/TEST");
|
||||
$this->assertSame(!! strpos($res, "URL/TEST"), true);
|
||||
}
|
||||
|
||||
public function test_alreadyAuth_1()
|
||||
public function testAlreadyAuth1()
|
||||
{
|
||||
// Not Authenticated
|
||||
// Not Authenticated
|
||||
$auth = new Auth();
|
||||
$res = $auth->pageHTML("http://localhost", "MESSAGE", "URL/TEST", false);
|
||||
$this->assertSame(!! strpos($res, "Please sign in"), true);
|
||||
}
|
||||
|
||||
public function test_alreadyAuth_2()
|
||||
public function testAlreadyAuth2()
|
||||
{
|
||||
// Authenticated
|
||||
// Authenticated
|
||||
$auth = new Auth();
|
||||
$res = $auth->pageHTML("http://localhost", "", "", "AUTHENTICATED USER");
|
||||
$this->assertSame(!! strpos($res, "AUTHENTICATED USER"), true);
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Authhtpasswd;
|
||||
|
||||
/** Test the Authhtpasswd.php file */
|
||||
/**
|
||||
* Test the Authhtpasswd.php file
|
||||
*/
|
||||
class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_clean()
|
||||
public function testClean()
|
||||
{
|
||||
if (file_exists("/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->htpasswdFile = "/tmp/htpasswd.file";
|
||||
@@ -35,7 +38,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, null);
|
||||
}
|
||||
|
||||
public function test_authentication1()
|
||||
public function testAuthentication1()
|
||||
{
|
||||
$authhtpasswd = new Authhtpasswd();
|
||||
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
|
||||
@@ -43,7 +46,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_authentication2()
|
||||
public function testAuthentication2()
|
||||
{
|
||||
$authhtpasswd = new Authhtpasswd();
|
||||
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
|
||||
@@ -51,7 +54,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $authhtpasswd->authentication("UNKNOWN@toto.com", "toto123");
|
||||
}
|
||||
|
||||
public function test_authentication3()
|
||||
public function testAuthentication3()
|
||||
{
|
||||
$authhtpasswd = new Authhtpasswd();
|
||||
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
|
||||
@@ -59,7 +62,7 @@ class AuthhtpasswdTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $authhtpasswd->authentication("toto@toto.com", "BAD PASSWD");
|
||||
}
|
||||
|
||||
public function test_authentication4()
|
||||
public function testAuthentication4()
|
||||
{
|
||||
$authhtpasswd = new Authhtpasswd();
|
||||
$authhtpasswd->htpasswdFile = "/tmp/htpasswd.file";
|
||||
|
||||
@@ -1,25 +1,36 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Authjwt;
|
||||
|
||||
/** Test the Authjwt.php file */
|
||||
/**
|
||||
* Test the Authjwt.php file
|
||||
*/
|
||||
class AuthjwtTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var string */
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cacheDir;
|
||||
/** @var string */
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $serverKey;
|
||||
/** @var string */
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $cipherKey;
|
||||
/** @var string */
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $token;
|
||||
|
||||
public function __construct()
|
||||
|
||||
@@ -1,27 +1,30 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Authsympa;
|
||||
|
||||
/** Test the authentication on Sympa Service */
|
||||
/**
|
||||
* Test the authentication on Sympa Service
|
||||
*/
|
||||
class AuthsympaTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_connect_1()
|
||||
public function testConnect1()
|
||||
{
|
||||
// Empty
|
||||
// Empty
|
||||
$authsympa = new Authsympa();
|
||||
$this->expectException();
|
||||
$authsympa->connect();
|
||||
}
|
||||
|
||||
public function test_connect_2()
|
||||
public function testConnect2()
|
||||
{
|
||||
$authsympa = new Authsympa();
|
||||
$authsympa->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl";
|
||||
@@ -30,9 +33,9 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, null);
|
||||
}
|
||||
|
||||
public function test_auth_1()
|
||||
public function testAuth1()
|
||||
{
|
||||
// Invalid password
|
||||
// Invalid password
|
||||
$authsympa = new Authsympa();
|
||||
$authsympa->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl";
|
||||
$authsympa->list = "listtest@listes.grenoble.cnrs.fr";
|
||||
@@ -41,9 +44,9 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
|
||||
$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->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl";
|
||||
$authsympa->list = "listtest@listes.grenoble.cnrs.fr";
|
||||
@@ -52,9 +55,9 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $authsympa->authentication("Unknown@grenoble.cnrs.fr", "XXXX");
|
||||
}
|
||||
|
||||
public function test_auth_3()
|
||||
public function testAuth3()
|
||||
{
|
||||
// OK !
|
||||
// OK !
|
||||
$authsympa = new Authsympa();
|
||||
$authsympa->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl";
|
||||
$authsympa->list = "listtest@listes.grenoble.cnrs.fr";
|
||||
@@ -63,9 +66,9 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_auth_4()
|
||||
public function testAuth4()
|
||||
{
|
||||
// Unknown list
|
||||
// Unknown list
|
||||
$authsympa = new Authsympa();
|
||||
$authsympa->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl";
|
||||
$authsympa->list = "unknown@listes.grenoble.cnrs.fr";
|
||||
@@ -74,9 +77,9 @@ class AuthsympaTest extends \PHPUnit_Framework_TestCase
|
||||
$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->wsdl = "https://listes.grenoble.cnrs.fr/sympa/wsdl";
|
||||
$authsympa->list = "admins@listes.grenoble.cnrs.fr";
|
||||
|
||||
@@ -1,43 +1,46 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Authzgroups;
|
||||
|
||||
/** Test the Authzgroups.php file */
|
||||
/**
|
||||
* Test the Authzgroups.php file
|
||||
*/
|
||||
class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $dbconfig = array (
|
||||
private $dbconfig = [
|
||||
"dsn" => "sqlite:/tmp/databaseAuthzGroups.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
);
|
||||
public function test_Initialization()
|
||||
];
|
||||
public function testInitialization()
|
||||
{
|
||||
if (file_exists("/tmp/databaseAuthzGroups.db")) {
|
||||
unlink("/tmp/databaseAuthzGroups.db");
|
||||
}
|
||||
}
|
||||
|
||||
public function test_createTables1()
|
||||
public function testCreateTables1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$this->setExpectedException("Exception");
|
||||
$authz->createTables();
|
||||
}
|
||||
|
||||
public function test_connect()
|
||||
public function testConnect()
|
||||
{
|
||||
// Must use the model to create the database structure as there is no
|
||||
// creation of tables in controller
|
||||
// Must use the model to create the database structure as there is no
|
||||
// creation of tables in controller
|
||||
$authz = new Authzgroups();
|
||||
$res = $authz->connect(
|
||||
$this->dbconfig["dsn"],
|
||||
@@ -48,7 +51,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_createTables2()
|
||||
public function testCreateTables2()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -64,7 +67,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
////////////////
|
||||
// OBJECT //
|
||||
////////////////
|
||||
public function test_objectCreate1()
|
||||
public function testObjectCreate1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -77,7 +80,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("1", $res);
|
||||
}
|
||||
|
||||
public function test_objectUpdate1()
|
||||
public function testObjectUpdate1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -90,7 +93,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_objectDelete1()
|
||||
public function testObjectDelete1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -99,7 +102,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The object was renamed and is not available
|
||||
// The object was renamed and is not available
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->objectDel("MODULE", "/object");
|
||||
}
|
||||
@@ -107,7 +110,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
////////////////
|
||||
// GROUPS //
|
||||
////////////////
|
||||
public function test_groupCreate1()
|
||||
public function testGroupCreate1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -120,7 +123,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("1", $res);
|
||||
}
|
||||
|
||||
public function test_groupUpdate1()
|
||||
public function testGroupUpdate1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -133,7 +136,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_groupDelete1()
|
||||
public function testGroupDelete1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -142,7 +145,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupDel("MODULE", "group");
|
||||
}
|
||||
@@ -150,7 +153,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
/////////////////////
|
||||
// GROUPMEMBER //
|
||||
/////////////////////
|
||||
public function test_groupmemberCreate1()
|
||||
public function testGroupmemberCreate1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -159,12 +162,12 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupmemberAdd("MODULE", "group", "userKnown");
|
||||
}
|
||||
|
||||
public function test_groupmemberCreate2()
|
||||
public function testGroupmemberCreate2()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -177,7 +180,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("1", $res);
|
||||
}
|
||||
|
||||
public function test_groupmemberDelete1()
|
||||
public function testGroupmemberDelete1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -186,12 +189,12 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupmemberDel("MODULE", "group", "userKnown");
|
||||
}
|
||||
|
||||
public function test_groupmemberReadGroup1()
|
||||
public function testGroupmemberReadGroup1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -200,12 +203,12 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupmemberReadGroup("MODULE", "group");
|
||||
}
|
||||
|
||||
public function test_groupmemberReadGroup2()
|
||||
public function testGroupmemberReadGroup2()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -215,10 +218,10 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
$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->connect(
|
||||
@@ -228,13 +231,13 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
$res = $authz->groupmemberReadUser("MODULE", "userKnown");
|
||||
$this->assertSame(array (1 => "group2"), $res);
|
||||
$this->assertSame([1 => "group2"], $res);
|
||||
}
|
||||
|
||||
////////////////
|
||||
// RIGHTS //
|
||||
////////////////
|
||||
public function test_rightCreate1()
|
||||
public function testRightCreate1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -247,7 +250,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("1", $res);
|
||||
}
|
||||
|
||||
public function test_rightUpdate1()
|
||||
public function testRightUpdate1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -260,7 +263,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_rightDelete1()
|
||||
public function testRightDelete1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -269,7 +272,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The object doesn't exists
|
||||
// The object doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->rightDel("MODULE", "group2", "/object");
|
||||
}
|
||||
@@ -278,7 +281,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
//////////////////////////////////////////////
|
||||
// CLEANING DATABASE : REMOVING ENTRIES //
|
||||
//////////////////////////////////////////////
|
||||
public function test_deleteGroupmember2()
|
||||
public function testDeleteGroupmember2()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -291,7 +294,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_deleteObject2()
|
||||
public function testDeleteObject2()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -304,7 +307,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_deleteGroup2()
|
||||
public function testDeleteGroup2()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -320,7 +323,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
/////////////////////
|
||||
// USER RIGHTS //
|
||||
/////////////////////
|
||||
public function test_userrightsget1()
|
||||
public function testUserrightsget1()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -329,7 +332,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// Create infos to tests the userrightsget method
|
||||
// Create infos to tests the userrightsget method
|
||||
$authz->objectAdd("MODULE1", "/");
|
||||
$authz->objectAdd("MODULE1", "/rep1");
|
||||
$authz->objectAdd("MODULE1", "/rep1/rep2");
|
||||
@@ -349,10 +352,10 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$authz->rightAdd("MODULE1", "group3", "/rep1/rep2", "RO");
|
||||
|
||||
$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->connect(
|
||||
@@ -365,7 +368,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("RW", $res);
|
||||
}
|
||||
|
||||
public function test_allow2()
|
||||
public function testAllow2()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -379,7 +382,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("RW", $res);
|
||||
}
|
||||
|
||||
public function test_allow3()
|
||||
public function testAllow3()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
@@ -393,7 +396,7 @@ class AuthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("RW", $res);
|
||||
}
|
||||
|
||||
public function test_allow4()
|
||||
public function testAllow4()
|
||||
{
|
||||
$authz = new Authzgroups();
|
||||
$authz->connect(
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Authzgroupsoo;
|
||||
|
||||
/** Test the Authzgroupsoo.php file */
|
||||
/**
|
||||
* Test the Authzgroupsoo.php file
|
||||
*/
|
||||
class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private $dbconfig = array (
|
||||
private $dbconfig = [
|
||||
"dsn" => "sqlite:/tmp/databaseAuthzGroupsoo.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
);
|
||||
];
|
||||
public function testInitialization()
|
||||
{
|
||||
if (file_exists("/tmp/databaseAuthzGroupsoo.db")) {
|
||||
@@ -36,8 +39,8 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testConnect()
|
||||
{
|
||||
// Must use the model to create the database structure as there is no
|
||||
// creation of tables in controller
|
||||
// Must use the model to create the database structure as there is no
|
||||
// creation of tables in controller
|
||||
$authz = new Authzgroupsoo();
|
||||
$res = $authz->connect(
|
||||
$this->dbconfig["dsn"],
|
||||
@@ -99,7 +102,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The object was renamed and is not available
|
||||
// The object was renamed and is not available
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->objectDel("MODULE", "/object");
|
||||
}
|
||||
@@ -142,7 +145,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupDel("MODULE", "group");
|
||||
}
|
||||
@@ -159,7 +162,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupmemberAdd("MODULE", "group", "userKnown");
|
||||
}
|
||||
@@ -186,7 +189,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupmemberDel("MODULE", "group", "userKnown");
|
||||
}
|
||||
@@ -200,7 +203,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The group doesn't exists
|
||||
// The group doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->groupmemberReadGroup("MODULE", "group");
|
||||
}
|
||||
@@ -215,7 +218,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
$res = $authz->groupmemberReadGroup("MODULE", "group2");
|
||||
$this->assertSame(array (array ("user" => "userKnown")), $res);
|
||||
$this->assertSame([["user" => "userKnown"]], $res);
|
||||
}
|
||||
|
||||
public function testGroupmemberReadUser1()
|
||||
@@ -228,7 +231,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
$res = $authz->groupmemberReadUser("MODULE", "userKnown");
|
||||
$this->assertSame(array (1 => "group2"), $res);
|
||||
$this->assertSame([1 => "group2"], $res);
|
||||
}
|
||||
|
||||
////////////////
|
||||
@@ -269,7 +272,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// The object doesn't exists
|
||||
// The object doesn't exists
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $authz->rightDel("MODULE", "group2", "/object");
|
||||
}
|
||||
@@ -329,7 +332,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$this->dbconfig["password"],
|
||||
$this->dbconfig["driver_options"]
|
||||
);
|
||||
// Create infos to tests the userrightsget method
|
||||
// Create infos to tests the userrightsget method
|
||||
$authz->objectAdd("MODULE1", "/");
|
||||
$authz->objectAdd("MODULE1", "/rep1");
|
||||
$authz->objectAdd("MODULE1", "/rep1/rep2");
|
||||
@@ -349,7 +352,7 @@ class AuthzgroupsooTest extends \PHPUnit_Framework_TestCase
|
||||
$authz->rightAdd("MODULE1", "group3", "/rep1/rep2", "RO");
|
||||
|
||||
$res = $authz->userrightsget("MODULE1", "userKnown");
|
||||
$this->assertSame(array ("/rep1/rep2" => "RW"), $res);
|
||||
$this->assertSame(["/rep1/rep2" => "RW"], $res);
|
||||
}
|
||||
|
||||
public function testAllow1()
|
||||
|
||||
@@ -1,21 +1,24 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Cachefile;
|
||||
|
||||
/** Test the Cachefile.php file */
|
||||
/**
|
||||
* Test the Cachefile.php file
|
||||
*/
|
||||
class CachefileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testInit()
|
||||
{
|
||||
// Removing the cache file if it previously exists
|
||||
// Removing the cache file if it previously exists
|
||||
exec("rm -rf /tmp/cache");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Certificationauthority;
|
||||
|
||||
/** Test the certification Authority
|
||||
*/
|
||||
/**
|
||||
* Test the certification Authority
|
||||
*/
|
||||
class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_createCA_1()
|
||||
public function testCreateCA1()
|
||||
{
|
||||
$certificationauthority = new Certificationauthority();
|
||||
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
|
||||
$caCert = explode("\n", $certificationauthority->caCert());
|
||||
$caKey = explode("\n", $certificationauthority->caKey());
|
||||
$res = $caCert[0] . $caKey[0];
|
||||
$res = $caCert[0] . $caKey[0];
|
||||
$this->assertSame(
|
||||
$res,
|
||||
"-----BEGIN CERTIFICATE----------BEGIN PRIVATE KEY-----"
|
||||
);
|
||||
}
|
||||
|
||||
public function test_createCA_2()
|
||||
public function testCreateCA2()
|
||||
{
|
||||
$certificationauthority = new Certificationauthority();
|
||||
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
|
||||
@@ -42,7 +44,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
|
||||
public function test_createPK_1()
|
||||
public function testCreatePK1()
|
||||
{
|
||||
$certificationauthority = new Certificationauthority();
|
||||
$privateKey = $certificationauthority->createPrivateKey() -> privateKey();
|
||||
@@ -50,7 +52,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($privateKey[0], "-----BEGIN PRIVATE KEY-----");
|
||||
}
|
||||
|
||||
public function test_createCSR_1()
|
||||
public function testCreateCSR1()
|
||||
{
|
||||
$certificationauthority = new Certificationauthority();
|
||||
$csr = $certificationauthority->createCSR("FR", "FOURNIER38", "CSR");
|
||||
@@ -58,7 +60,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($csr[0], "-----BEGIN CERTIFICATE REQUEST-----");
|
||||
}
|
||||
|
||||
public function test_signCSR_1()
|
||||
public function testSignCSR1()
|
||||
{
|
||||
$certificationauthority = new Certificationauthority();
|
||||
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
|
||||
@@ -70,7 +72,7 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($cert[0], "-----BEGIN CERTIFICATE-----");
|
||||
}
|
||||
|
||||
public function test_signCSR_2()
|
||||
public function testSignCSR2()
|
||||
{
|
||||
$certificationauthority = new Certificationauthority();
|
||||
$certificationauthority->createCA("FR", "FOURNIER38", "CATEST");
|
||||
@@ -88,9 +90,9 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$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->createCA("FR", "FOURNIER38", "CATEST");
|
||||
$caCert = $certificationauthority->caCert();
|
||||
@@ -107,9 +109,9 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$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->createCA("FR", "FOURNIER38", "CATEST");
|
||||
$caCert = $certificationauthority->caCert();
|
||||
@@ -126,9 +128,9 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$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->createCA("FR", "FOURNIER38", "CATEST");
|
||||
$caCert = $certificationauthority->caCert();
|
||||
@@ -145,9 +147,9 @@ class CertificationauthorityTest extends \PHPUnit_Framework_TestCase
|
||||
$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->createCA("FR", "FOURNIER38", "CATEST");
|
||||
$caCert = $certificationauthority->caCert();
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Config;
|
||||
|
||||
/** Test the Config.php file */
|
||||
/**
|
||||
* Test the Config.php file
|
||||
*/
|
||||
class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testExternFile()
|
||||
@@ -24,38 +27,38 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$c = new Config();
|
||||
$res = $c->params();
|
||||
$this->assertSame(array (), $res);
|
||||
$this->assertSame([], $res);
|
||||
}
|
||||
|
||||
public function testGet1()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => ""));
|
||||
"tableprefix" => ""]];
|
||||
$res = $c->get("database");
|
||||
$this->assertSame(array (
|
||||
$this->assertSame([
|
||||
"dsn" => null,
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => ""), $res);
|
||||
"tableprefix" => ""], $res);
|
||||
}
|
||||
|
||||
public function testSet1()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"tableprefix" => ""));
|
||||
$res = $c->set("database", array ("dsn" => 1,"tableprefix" => 3));
|
||||
"tableprefix" => ""]];
|
||||
$res = $c->set("database", ["dsn" => 1,"tableprefix" => 3]);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
@@ -63,99 +66,111 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"tableprefix" => ""));
|
||||
"tableprefix" => ""]];
|
||||
$res = $c->get("database");
|
||||
$this->assertSame(array (
|
||||
$this->assertSame([
|
||||
"dsn" => 1,
|
||||
"tableprefix" => 3), $res);
|
||||
"tableprefix" => 3], $res);
|
||||
}
|
||||
|
||||
/** Can't create file */
|
||||
/**
|
||||
* Can't create file
|
||||
*/
|
||||
public function testGet3()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/1/2.3/dd/testconf.php";
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"tableprefix" => ""));
|
||||
"tableprefix" => ""]];
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $c->get("database");
|
||||
}
|
||||
|
||||
/** Can't read the file */
|
||||
/**
|
||||
* Can't read the file
|
||||
*/
|
||||
public function testGet4()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0222);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"tableprefix" => ""));
|
||||
"tableprefix" => ""]];
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $c->get("database");
|
||||
}
|
||||
|
||||
/** File non exists and can not be created */
|
||||
/**
|
||||
* File non exists and can not be created
|
||||
*/
|
||||
public function testSet2()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/1/2.3/dd/testconf.php";
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"tableprefix" => ""));
|
||||
"tableprefix" => ""]];
|
||||
$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()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0222);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"tableprefix" => ""));
|
||||
"tableprefix" => ""]];
|
||||
$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()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0444);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"tableprefix" => ""));
|
||||
"tableprefix" => ""]];
|
||||
$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()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0666);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"user" => null,
|
||||
"password" => null,
|
||||
"tableprefix" => ""));
|
||||
$res = $c->set("database", array ("dsn" => true, "user" => null,
|
||||
"tableprefix" => ""]];
|
||||
$res = $c->set("database", ["dsn" => true, "user" => null,
|
||||
"password" => "text",
|
||||
"tableprefix" => false));
|
||||
"tableprefix" => false]);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
@@ -164,24 +179,24 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0666);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"user" => null,
|
||||
"password" => null,
|
||||
"tableprefix" => ""),
|
||||
"servers" => array (
|
||||
"not configured" => array (
|
||||
"tableprefix" => ""],
|
||||
"servers" => [
|
||||
"not configured" => [
|
||||
"type" => "bind",
|
||||
"username" => "",
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
]
|
||||
];
|
||||
$res = $c->get("servers");
|
||||
$this->assertSame($res, array ("not configured" => array (
|
||||
$this->assertSame($res, ["not configured" => [
|
||||
"type" => "bind",
|
||||
"username" => "",
|
||||
)));
|
||||
]]);
|
||||
}
|
||||
|
||||
public function testSet7()
|
||||
@@ -189,49 +204,49 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0666);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"user" => null,
|
||||
"password" => null,
|
||||
"tableprefix" => ""),
|
||||
"servers" => array (
|
||||
"not configured" => array (
|
||||
"tableprefix" => ""],
|
||||
"servers" => [
|
||||
"not configured" => [
|
||||
"type" => "bind",
|
||||
"username" => "",
|
||||
),
|
||||
)
|
||||
);
|
||||
$res = $c->set("servers", array (
|
||||
"127.0.0.1" => array (
|
||||
],
|
||||
]
|
||||
];
|
||||
$res = $c->set("servers", [
|
||||
"127.0.0.1" => [
|
||||
"type" => "BIND",
|
||||
"username" => "toto",
|
||||
)));
|
||||
]]);
|
||||
}
|
||||
public function testGet7()
|
||||
{
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0666);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"user" => null,
|
||||
"password" => null,
|
||||
"tableprefix" => ""),
|
||||
"servers" => array (
|
||||
"not configured" => array (
|
||||
"tableprefix" => ""],
|
||||
"servers" => [
|
||||
"not configured" => [
|
||||
"type" => "bind",
|
||||
"username" => "",
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
]
|
||||
];
|
||||
$res = $c->get("servers");
|
||||
$this->assertSame($res, array (
|
||||
"127.0.0.1" => array (
|
||||
$this->assertSame($res, [
|
||||
"127.0.0.1" => [
|
||||
"type" => "BIND",
|
||||
"username" => "toto",
|
||||
)));
|
||||
]]);
|
||||
}
|
||||
|
||||
public function testGet8()
|
||||
@@ -239,26 +254,26 @@ class ConfigTest extends \PHPUnit_Framework_TestCase
|
||||
$c = new Config();
|
||||
$c->confFile = "/tmp/testconf.php";
|
||||
chmod("/tmp/testconf.php", 0666);
|
||||
$c->default = array (
|
||||
"database" => array (
|
||||
$c->default = [
|
||||
"database" => [
|
||||
"dsn" => null,
|
||||
"user" => null,
|
||||
"password" => null,
|
||||
"tableprefix" => ""),
|
||||
"servers" => array (
|
||||
"not configured" => array (
|
||||
"tableprefix" => ""],
|
||||
"servers" => [
|
||||
"not configured" => [
|
||||
"type" => "bind",
|
||||
"username" => "",
|
||||
"password" => "",
|
||||
),
|
||||
)
|
||||
);
|
||||
],
|
||||
]
|
||||
];
|
||||
$res = $c->get("servers");
|
||||
$this->assertSame($res, array (
|
||||
"127.0.0.1" => array (
|
||||
$this->assertSame($res, [
|
||||
"127.0.0.1" => [
|
||||
"type" => "BIND",
|
||||
"username" => "toto",
|
||||
"password" => "",
|
||||
)));
|
||||
]]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,67 +1,70 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Convert;
|
||||
|
||||
/** Test the Conversion of format */
|
||||
/**
|
||||
* Test the Conversion of format
|
||||
*/
|
||||
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");
|
||||
$this->assertSame($res, "13/04/2017");
|
||||
}
|
||||
|
||||
public function test_convertDate2()
|
||||
public function testConvertDate2()
|
||||
{
|
||||
$this->setExpectedException("Exception");
|
||||
$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);
|
||||
$this->assertSame($res, "2017-13-33");
|
||||
}
|
||||
|
||||
public function test_ucwords_1()
|
||||
public function testUcwords1()
|
||||
{
|
||||
$res = Convert::ucwords(" test yuyu ");
|
||||
$this->assertSame($res, " Test Yuyu ");
|
||||
}
|
||||
|
||||
public function test_ucwords_2()
|
||||
public function testUcwords2()
|
||||
{
|
||||
$res = Convert::ucwords("");
|
||||
$this->assertSame($res, "");
|
||||
}
|
||||
|
||||
public function test_ucwords_3()
|
||||
public function testUcwords3()
|
||||
{
|
||||
$res = Convert::ucwords("test");
|
||||
$this->assertSame($res, "Test");
|
||||
}
|
||||
|
||||
public function test_ucwords_4()
|
||||
public function testUcwords4()
|
||||
{
|
||||
$res = Convert::ucwords("TEST");
|
||||
$this->assertSame($res, "Test");
|
||||
}
|
||||
|
||||
public function test_ucwords_5()
|
||||
public function testUcwords5()
|
||||
{
|
||||
$res = Convert::ucwords("édouard étienne");
|
||||
$this->assertSame($res, "Édouard Étienne");
|
||||
}
|
||||
|
||||
public function test_ucwords_6()
|
||||
public function testUcwords6()
|
||||
{
|
||||
$res = Convert::ucwords("édou-ard d'étienne", " -'");
|
||||
$this->assertSame($res, "Édou-Ard D'Étienne");
|
||||
@@ -70,7 +73,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
|
||||
/////////////////////
|
||||
// humanSize //
|
||||
/////////////////////
|
||||
public function test_humanSize_1()
|
||||
public function testHumanSize1()
|
||||
{
|
||||
$res = "";
|
||||
for ($i = -8; $i <= 8; $i++) {
|
||||
@@ -81,47 +84,47 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
|
||||
"1.44ZB\n1.44YB\n");
|
||||
}
|
||||
|
||||
public function test_humanSize_2()
|
||||
public function testHumanSize2()
|
||||
{
|
||||
$res = Convert::humanSize(1441234);
|
||||
$this->assertSame($res, "1.44MB");
|
||||
}
|
||||
public function test_humanSize_3()
|
||||
public function testHumanSize3()
|
||||
{
|
||||
$res = Convert::humanSize(10441234);
|
||||
$this->assertSame($res, "10.44MB");
|
||||
}
|
||||
public function test_humanSize_4()
|
||||
public function testHumanSize4()
|
||||
{
|
||||
$res = Convert::humanSize(0.123, 0);
|
||||
$this->assertSame($res, "123mB");
|
||||
}
|
||||
public function test_humanSize_5()
|
||||
public function testHumanSize5()
|
||||
{
|
||||
$res = Convert::humanSize(0.12345, 2);
|
||||
$this->assertSame($res, "123.45mB");
|
||||
}
|
||||
|
||||
public function test_humanSize_6()
|
||||
public function testHumanSize6()
|
||||
{
|
||||
$res = Convert::humanSize(-0.12345, 2);
|
||||
$this->assertSame($res, "-123.45mB");
|
||||
}
|
||||
|
||||
public function test_humanSize_7()
|
||||
public function testHumanSize7()
|
||||
{
|
||||
$res = Convert::humanSize(-12345, 2);
|
||||
$this->assertSame($res, "-12.35kB");
|
||||
}
|
||||
|
||||
public function test_humanSize_8()
|
||||
public function testHumanSize8()
|
||||
{
|
||||
$res = Convert::humanSize(0, 2);
|
||||
$this->assertSame($res, "0.00B");
|
||||
}
|
||||
|
||||
|
||||
public function test_humanSize_error1()
|
||||
public function testHumanSizeError1()
|
||||
{
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
@@ -131,7 +134,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
|
||||
$res = Convert::humanSize("1441234");
|
||||
}
|
||||
|
||||
public function test_humanSize_error2()
|
||||
public function testHumanSizeError2()
|
||||
{
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
@@ -141,7 +144,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
|
||||
$res = Convert::humanSize(1441234, 0.1);
|
||||
}
|
||||
|
||||
public function test_humanSize_error3()
|
||||
public function testHumanSizeError3()
|
||||
{
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
@@ -151,7 +154,7 @@ class ConvertTest extends \PHPUnit_Framework_TestCase
|
||||
$res = Convert::humanSize(1441234, -1);
|
||||
}
|
||||
|
||||
public function test_humanSize_error4()
|
||||
public function testHumanSizeError4()
|
||||
{
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Csrf;
|
||||
|
||||
/** Test the Csrf.php file */
|
||||
/**
|
||||
* Test the Csrf.php file
|
||||
*/
|
||||
class CsrfTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_csrf1()
|
||||
public function testCsrf1()
|
||||
{
|
||||
$csrf = new Csrf();
|
||||
$res = $csrf->createToken();
|
||||
@@ -21,7 +24,7 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(30, strlen($res));
|
||||
}
|
||||
|
||||
public function test_csrf2()
|
||||
public function testCsrf2()
|
||||
{
|
||||
$csrf = new Csrf();
|
||||
$res = $csrf->createToken();
|
||||
@@ -34,14 +37,14 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_csrf3()
|
||||
public function testCsrf3()
|
||||
{
|
||||
$csrf = new Csrf();
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $csrf->checkToken("NOT VALID TOKEN");
|
||||
}
|
||||
|
||||
public function test_csrf4()
|
||||
public function testCsrf4()
|
||||
{
|
||||
$csrf = new Csrf();
|
||||
$token = $csrf->createToken();
|
||||
@@ -49,7 +52,7 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_csrf5()
|
||||
public function testCsrf5()
|
||||
{
|
||||
$csrf = new Csrf();
|
||||
$token = $csrf->createToken();
|
||||
@@ -57,7 +60,7 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_csrf6()
|
||||
public function testCsrf6()
|
||||
{
|
||||
$csrf = new Csrf();
|
||||
$token = $csrf->createToken();
|
||||
@@ -65,14 +68,14 @@ class CsrfTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($token, $res);
|
||||
}
|
||||
|
||||
public function test_csrf7()
|
||||
public function testCsrf7()
|
||||
{
|
||||
$csrf = new Csrf();
|
||||
$res = $csrf->getToken();
|
||||
$this->assertSame(30, strlen($res));
|
||||
}
|
||||
|
||||
public function test_csrf_multiple_1()
|
||||
public function testCsrfMultiple1()
|
||||
{
|
||||
$csrf1 = new Csrf();
|
||||
$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();
|
||||
$res = $csrf->extendToken($GLOBALS["CSRFTEST-Token"]);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_csrf_multiple_get()
|
||||
public function testCsrfMultipleGet()
|
||||
{
|
||||
$csrf1 = new Csrf();
|
||||
$token1 = $csrf1->createToken();
|
||||
|
||||
@@ -1,416 +1,419 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Dbjson;
|
||||
|
||||
/** Test the Dbjson database */
|
||||
/**
|
||||
* Test the Dbjson database
|
||||
*/
|
||||
class DbjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_insertOne1()
|
||||
public function testInsertOne1()
|
||||
{
|
||||
// Document #0
|
||||
// Document #0
|
||||
define("dbfile", "/tmp/dbjson-" . time());
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->insertOne(
|
||||
"collection",
|
||||
array ("key1" => "val1", "key2" => "val2")
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
);
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
|
||||
public function test_insertOne2()
|
||||
public function testInsertOne2()
|
||||
{
|
||||
// Document #1
|
||||
// Document #1
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->insertOne(
|
||||
"collection",
|
||||
array ("key1" => "val1", "key2" => "val2")
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
);
|
||||
$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");
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->insertMany(
|
||||
"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);
|
||||
$res = $dbjson->insertMany(
|
||||
"collection",
|
||||
array (array ("key1" => "val3", "key2" => "val2"),
|
||||
array ("key1" => "val3", "key2" => "val4"))
|
||||
[["key1" => "val3", "key2" => "val2"],
|
||||
["key1" => "val3", "key2" => "val4"]]
|
||||
);
|
||||
$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);
|
||||
$res = $dbjson->filter("collection", array ());
|
||||
$this->assertSame(array_keys($res), array (0,1,2,3));
|
||||
$res = $dbjson->filter("collection", []);
|
||||
$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);
|
||||
$res = $dbjson->filter("collection", array ("key2" => "val2"));
|
||||
$this->assertSame(array_keys($res), array (0,1,2));
|
||||
$res = $dbjson->filter("collection", ["key2" => "val2"]);
|
||||
$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);
|
||||
$res = $dbjson->filter("collection", array ("key1" => "val3",
|
||||
"key2" => "val2"));
|
||||
$res = $dbjson->filter("collection", ["key1" => "val3",
|
||||
"key2" => "val2"]);
|
||||
$this->assertSame(count($res), 1);
|
||||
}
|
||||
public function test_filter4()
|
||||
public function testFilter4()
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "=="),
|
||||
// "key2"=>array ("val2", "=="))
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "=="),
|
||||
// "key2"=>array ("val2", "=="))
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->filter("collection", array ("key1" => array ("val3", "=="),
|
||||
"key2" => array ("val2", "==")));
|
||||
$res = $dbjson->filter("collection", ["key1" => ["val3", "=="],
|
||||
"key2" => ["val2", "=="]]);
|
||||
$this->assertSame(count($res), 1);
|
||||
}
|
||||
public function test_filter5()
|
||||
public function testFilter5()
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "<="),
|
||||
// "key2"=>array ("val2", "=="))
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "<="),
|
||||
// "key2"=>array ("val2", "=="))
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->filter("collection", array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", "==")));
|
||||
$this->assertSame(array_keys($res), array (0,1,2));
|
||||
$res = $dbjson->filter("collection", ["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", "=="]]);
|
||||
$this->assertSame(array_keys($res), [0,1,2]);
|
||||
}
|
||||
public function test_filter6()
|
||||
public function testFilter6()
|
||||
{
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "<="),
|
||||
// "key2"=>array ("val2", ">"))
|
||||
// Return the keys where filter = array ("key1"=>array ("val3", "<="),
|
||||
// "key2"=>array ("val2", ">"))
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->filter("collection", array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", ">")));
|
||||
$res = $dbjson->filter("collection", ["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]]);
|
||||
$this->assertSame(count($res), 1);
|
||||
}
|
||||
|
||||
public function test_find1()
|
||||
public function testFind1()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find("collection", array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", ">")));
|
||||
$res = $dbjson->find("collection", ["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]]);
|
||||
$res = array_values($res);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
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_find2()
|
||||
public function testFind2()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", ">")),
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]],
|
||||
"*"
|
||||
);
|
||||
$res = array_values($res);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
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_find3()
|
||||
public function testFind3()
|
||||
{
|
||||
// Exception : fields not an array
|
||||
// Exception : fields not an array
|
||||
$this->setExpectedException("Exception");
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", ">")),
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]],
|
||||
"key1"
|
||||
);
|
||||
}
|
||||
public function test_find4()
|
||||
public function testFind4()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", ">")),
|
||||
array ("key1")
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]],
|
||||
["key1"]
|
||||
);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
$res = array_values($res);
|
||||
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);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", ">")),
|
||||
array ("key1", "key2")
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", ">"]],
|
||||
["key1", "key2"]
|
||||
);
|
||||
$res = array_values($res);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
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_find6()
|
||||
public function testFind6()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", "==")),
|
||||
array ("key1", "key2")
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", "=="]],
|
||||
["key1", "key2"]
|
||||
);
|
||||
$res = array_values($res);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
unset($res[1]["_id"]);
|
||||
unset($res[2]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key1" => "val1",
|
||||
"key2" => "val2"),
|
||||
1 => array ("key1" => "val1",
|
||||
"key2" => "val2"),
|
||||
2 => array ("key1" => "val3",
|
||||
"key2" => "val2")));
|
||||
$this->assertSame($res, [0 => ["key1" => "val1",
|
||||
"key2" => "val2"],
|
||||
1 => ["key1" => "val1",
|
||||
"key2" => "val2"],
|
||||
2 => ["key1" => "val3",
|
||||
"key2" => "val2"]]);
|
||||
}
|
||||
public function test_find7()
|
||||
public function testFind7()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", "==")),
|
||||
array ("key2")
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", "=="]],
|
||||
["key2"]
|
||||
);
|
||||
$res = array_values($res);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
unset($res[1]["_id"]);
|
||||
unset($res[2]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key2" => "val2"),
|
||||
1 => array ("key2" => "val2"),
|
||||
2 => array ("key2" => "val2")));
|
||||
$this->assertSame($res, [0 => ["key2" => "val2"],
|
||||
1 => ["key2" => "val2"],
|
||||
2 => ["key2" => "val2"]]);
|
||||
}
|
||||
public function test_find8()
|
||||
public function testFind8()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", "==")),
|
||||
array ("key2"),
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", "=="]],
|
||||
["key2"],
|
||||
1
|
||||
);
|
||||
$res = array_values($res);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
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);
|
||||
$res = $dbjson->deleteOne(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2",
|
||||
"=="))
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2",
|
||||
"=="]]
|
||||
);
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
public function test_find9()
|
||||
public function testFind9()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", "==")),
|
||||
array ("key2")
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", "=="]],
|
||||
["key2"]
|
||||
);
|
||||
$res = array_values($res);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
unset($res[1]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key2" => "val2"),
|
||||
1 => array ("key2" => "val2")));
|
||||
$this->assertSame($res, [0 => ["key2" => "val2"],
|
||||
1 => ["key2" => "val2"]]);
|
||||
}
|
||||
|
||||
public function test_deleteMany1()
|
||||
public function testDeleteMany1()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->deleteMany(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2",
|
||||
"=="))
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2",
|
||||
"=="]]
|
||||
);
|
||||
$this->assertSame($res, 2);
|
||||
}
|
||||
public function test_find10()
|
||||
public function testFind10()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->find(
|
||||
"collection",
|
||||
array ("key1" => array ("val3", "<="),
|
||||
"key2" => array ("val2", "==")),
|
||||
array ("key2")
|
||||
["key1" => ["val3", "<="],
|
||||
"key2" => ["val2", "=="]],
|
||||
["key2"]
|
||||
);
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[1]["_id"]);
|
||||
unset($res[2]["_id"]);
|
||||
$this->assertSame($res, array ());
|
||||
$this->assertSame($res, []);
|
||||
}
|
||||
|
||||
public function test_find11()
|
||||
public function testFind11()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
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);
|
||||
$res = $dbjson->replace("collection", array (), array ("key2" => "val5"));
|
||||
$res = $dbjson->replace("collection", [], ["key2" => "val5"]);
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
public function test_find12()
|
||||
public function testFind12()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
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);
|
||||
$res = $dbjson->update("collection", array (), array ("key2" => "val6",
|
||||
"key5" => "val5"));
|
||||
$res = $dbjson->update("collection", [], ["key2" => "val6",
|
||||
"key5" => "val5"]);
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
public function test_find13()
|
||||
public function testFind13()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key2" => "val6",
|
||||
"key5" => "val5")));
|
||||
$this->assertSame($res, [0 => ["key2" => "val6",
|
||||
"key5" => "val5"]]);
|
||||
}
|
||||
public function test_insertOne3()
|
||||
public function testInsertOne3()
|
||||
{
|
||||
// Document #4
|
||||
// Document #4
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->insertOne(
|
||||
"collection",
|
||||
array ("key1" => "val1", "key2" => "val2")
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
);
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
public function test_find14()
|
||||
public function testFind14()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
unset($res[1]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key2" => "val6",
|
||||
"key5" => "val5"),
|
||||
1 => array ("key1" => "val1",
|
||||
"key2" => "val2")));
|
||||
$this->assertSame($res, [0 => ["key2" => "val6",
|
||||
"key5" => "val5"],
|
||||
1 => ["key1" => "val1",
|
||||
"key2" => "val2"]]);
|
||||
}
|
||||
|
||||
public function test_update2()
|
||||
public function testUpdate2()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->update("collection", array (), array ("key2" => "val7",
|
||||
"key5" => "val8"));
|
||||
$res = $dbjson->update("collection", [], ["key2" => "val7",
|
||||
"key5" => "val8"]);
|
||||
$this->assertSame($res, 2);
|
||||
}
|
||||
public function test_find15()
|
||||
public function testFind15()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
unset($res[1]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key2" => "val7",
|
||||
"key5" => "val8"),
|
||||
1 => array ("key1" => "val1",
|
||||
$this->assertSame($res, [0 => ["key2" => "val7",
|
||||
"key5" => "val8"],
|
||||
1 => ["key1" => "val1",
|
||||
"key2" => "val7",
|
||||
"key5" => "val8")));
|
||||
"key5" => "val8"]]);
|
||||
}
|
||||
|
||||
public function test_update3()
|
||||
public function testUpdate3()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = $dbjson->update(
|
||||
"collection",
|
||||
array (),
|
||||
array ("key2" => "val9",
|
||||
[],
|
||||
["key2" => "val9",
|
||||
"key5" => "val7",
|
||||
"_unset" => array ("key2"))
|
||||
"_unset" => ["key2"]]
|
||||
);
|
||||
$this->assertSame($res, 2);
|
||||
}
|
||||
public function test_find16()
|
||||
public function testFind16()
|
||||
{
|
||||
$dbjson = new Dbjson("dbjson://" . dbfile);
|
||||
$res = array_values($dbjson->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
unset($res[1]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key5" => "val7"),
|
||||
1 => array ("key1" => "val1",
|
||||
"key5" => "val7")));
|
||||
$this->assertSame($res, [0 => ["key5" => "val7"],
|
||||
1 => ["key1" => "val1",
|
||||
"key5" => "val7"]]);
|
||||
}
|
||||
|
||||
// Concurrency tests
|
||||
public function test_concurrency1()
|
||||
public function testConcurrency1()
|
||||
{
|
||||
$dbjson1 = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson2 = new Dbjson("dbjson://" . dbfile);
|
||||
$dbjson1->insertOne(
|
||||
"collection",
|
||||
array ("key1" => "val1", "key2" => "val2")
|
||||
["key1" => "val1", "key2" => "val2"]
|
||||
);
|
||||
$res = array_values($dbjson2->find("collection"));
|
||||
// ["_id"] is random : skip the test
|
||||
// ["_id"] is random : skip the test
|
||||
unset($res[0]["_id"]);
|
||||
unset($res[1]["_id"]);
|
||||
unset($res[2]["_id"]);
|
||||
$this->assertSame($res, array (0 => array ("key5" => "val7"),
|
||||
1 => array ("key1" => "val1",
|
||||
"key5" => "val7"),
|
||||
2 => array ("key1" => "val1",
|
||||
"key2" => "val2")));
|
||||
$this->assertSame($res, [0 => ["key5" => "val7"],
|
||||
1 => ["key1" => "val1",
|
||||
"key5" => "val7"],
|
||||
2 => ["key1" => "val1",
|
||||
"key2" => "val2"]]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
@@ -12,456 +13,470 @@ use Domframework\Dblayer;
|
||||
|
||||
class DblayerTest{ENGINE} extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Test with column name 'group', 'object', 'where', 'with space'
|
||||
// Test with table name 'group', 'object', 'where', 'with space'
|
||||
// For the 3 DB engines
|
||||
// Test with column name 'group', 'object', 'where', 'with space'
|
||||
// Test with table name 'group', 'object', 'where', 'with space'
|
||||
// For the 3 DB engines
|
||||
|
||||
public $engine = "{ENGINE}";
|
||||
public $confs = array (
|
||||
"sqlite" => array (
|
||||
"dsn" => "sqlite:/tmp/databaseDBLayer.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
),
|
||||
"mysql" => array (
|
||||
"dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test",
|
||||
"username" => "root",
|
||||
"password" => "lqsym",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
),
|
||||
"pgsql" => array (
|
||||
"dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname",
|
||||
"username" => "root",
|
||||
"password" => "root",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
),
|
||||
);
|
||||
public $engine = "{ENGINE}";
|
||||
public $confs = [
|
||||
"sqlite" => [
|
||||
"dsn" => "sqlite:/tmp/databaseDBLayer.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
],
|
||||
"mysql" => [
|
||||
"dsn" => "mysql:host=127.0.0.1;port=3306;dbname=test",
|
||||
"username" => "root",
|
||||
"password" => "lqsym",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
],
|
||||
"pgsql" => [
|
||||
"dsn" => "pgsql:host=127.0.0.1;port=5432;dbname=dbname",
|
||||
"username" => "root",
|
||||
"password" => "root",
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
],
|
||||
];
|
||||
|
||||
/** @group singleton */
|
||||
public function test_dropTable()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
foreach (
|
||||
array ("users", "grouped", "multiple", "multiple2", "users3",
|
||||
"readOR") as $table
|
||||
) {
|
||||
$db->table = $table;
|
||||
try {
|
||||
$res = $db->dropTable();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$db->disconnect();
|
||||
// Never generate an error, just drop the table if it exists, and do noting
|
||||
// if it doesn't exists
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testDropTable()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
foreach (
|
||||
["users", "grouped", "multiple", "multiple2", "users3",
|
||||
"readOR"] as $table
|
||||
) {
|
||||
$db->table = $table;
|
||||
try {
|
||||
$res = $db->dropTable();
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
}
|
||||
$db->disconnect();
|
||||
// Never generate an error, just drop the table if it exists, and do noting
|
||||
// if it doesn't exists
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
public function test_createTable1()
|
||||
{
|
||||
// Create a table named grouped
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$db->primary = "group";
|
||||
$res = $db->createTable();
|
||||
$db->disconnect();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testCreateTable1()
|
||||
{
|
||||
// Create a table named grouped
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$db->primary = "group";
|
||||
$res = $db->createTable();
|
||||
$db->disconnect();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
public function test_insert1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$db->primary = "group";
|
||||
$res = $db->insert(array ("group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"));
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res, "gr ou\"p");
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testInsert1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$db->primary = "group";
|
||||
$res = $db->insert(["group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res, "gr ou\"p");
|
||||
}
|
||||
|
||||
public function test_read1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read(array (array ("group", "gr ou\"p"),
|
||||
array ("object","/éobj%"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","with space")));
|
||||
$this->assertSame(array (0 => array ("group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space")), $res);
|
||||
}
|
||||
public function testRead1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$res = $db->read([["group", "gr ou\"p"],
|
||||
["object","/éobj%"],
|
||||
["where","\$'\""],
|
||||
["with space","with space"]]);
|
||||
$this->assertSame([0 => ["group" => "gr ou\"p",
|
||||
"object" => "/éobj%",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]], $res);
|
||||
}
|
||||
|
||||
public function test_update1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$db->primary = "group";
|
||||
// Don't update primary key
|
||||
$res = $db->update("gr ou\"p", array ("object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"));
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
public function testUpdate1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$db->primary = "group";
|
||||
// Don't update primary key
|
||||
$res = $db->update("gr ou\"p", ["object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"]);
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_read2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read(array (array ("group", "gr ou\"p"),
|
||||
array ("object","%éàoppp"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","WITH SPACE")));
|
||||
$this->assertSame(array (0 => array ("group" => "gr ou\"p",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE")), $res);
|
||||
}
|
||||
public function testRead2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$res = $db->read([["group", "gr ou\"p"],
|
||||
["object","%éàoppp"],
|
||||
["where","\$'\""],
|
||||
["with space","WITH SPACE"]]);
|
||||
$this->assertSame([0 => ["group" => "gr ou\"p",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE"]], $res);
|
||||
}
|
||||
|
||||
public function test_update2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array (array ("group","object"));
|
||||
$db->primary = "group";
|
||||
// Update primary key
|
||||
$res = $db->update("gr ou\"p", array ("group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"));
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
public function testUpdate2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [["group","object"]];
|
||||
$db->primary = "group";
|
||||
// Update primary key
|
||||
$res = $db->update("gr ou\"p", ["group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"]);
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_read3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ();
|
||||
$res = $db->read(array (array ("group", "NEW GROUP"),
|
||||
array ("object","%éàoppp"),
|
||||
array ("where","\$'\""),
|
||||
array ("with space","WITH SPACE")));
|
||||
$this->assertSame(array (0 => array ("group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE")), $res);
|
||||
}
|
||||
public function testRead3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = [];
|
||||
$res = $db->read([["group", "NEW GROUP"],
|
||||
["object","%éàoppp"],
|
||||
["where","\$'\""],
|
||||
["with space","WITH SPACE"]]);
|
||||
$this->assertSame([0 => ["group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "WITH SPACE"]], $res);
|
||||
}
|
||||
|
||||
public function test_update3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = array ("group" => array ("varchar", "255", "not null"),
|
||||
"object" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ("group");
|
||||
$db->primary = "group";
|
||||
// Update primary key with primary key in unique with same values to test if
|
||||
// the exception is NOT raised
|
||||
$res = $db->update("NEW GROUP", array ("group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"));
|
||||
// SQLite and PostgreSQL return 1 line modified
|
||||
// MySQL return 0 by default because there is no modification on the line
|
||||
// http://fr2.php.net/manual/en/pdostatement.rowcount.php#104930
|
||||
// Now, the MYSQL_ATTR_FOUND_ROWS is added to connection to be the same in
|
||||
// all the engines
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
public function testUpdate3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "grouped";
|
||||
$db->fields = ["group" => ["varchar", "255", "not null"],
|
||||
"object" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = ["group"];
|
||||
$db->primary = "group";
|
||||
// Update primary key with primary key in unique with same values to test if
|
||||
// the exception is NOT raised
|
||||
$res = $db->update("NEW GROUP", ["group" => "NEW GROUP",
|
||||
"object" => "%éàoppp",
|
||||
"with space" => "WITH SPACE"]);
|
||||
// SQLite and PostgreSQL return 1 line modified
|
||||
// MySQL return 0 by default because there is no modification on the line
|
||||
// http://fr2.php.net/manual/en/pdostatement.rowcount.php#104930
|
||||
// Now, the MYSQL_ATTR_FOUND_ROWS is added to connection to be the same in
|
||||
// all the engines
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
// Part to test the foreign keys
|
||||
public function test_createTable2()
|
||||
{
|
||||
// Create a table named group
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->disconnect();
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = array ("user" => array ("varchar", "255", "not null"),
|
||||
"groupmember" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->foreign = array (
|
||||
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
// Part to test the foreign keys
|
||||
public function testCreateTable2()
|
||||
{
|
||||
// Create a table named group
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->disconnect();
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
|
||||
$res = $db->createTable();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
$res = $db->createTable();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
public function test_insert2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = array ("user" => array ("varchar", "255", "not null"),
|
||||
"groupmember" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->unique = array ("user");
|
||||
$db->primary = "user";
|
||||
$db->foreign = array (
|
||||
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
$res = $db->insert(array ("user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"));
|
||||
$db->disconnect();
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res <= 2 || $res === "Us ou\"r", true);
|
||||
}
|
||||
public function testInsert2()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->unique = ["user"];
|
||||
$db->primary = "user";
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
$res = $db->insert(["user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
$db->disconnect();
|
||||
// SQLite start at 1, MySQL start at 0...
|
||||
$this->assertSame($res <= 2 || $res === "Us ou\"r", true);
|
||||
}
|
||||
|
||||
// Test the unique feature
|
||||
public function test_insert3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = array ("user" => array ("varchar", "255", "not null"),
|
||||
"groupmember" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
// Unique simple in insert
|
||||
$db->unique = array ("user");
|
||||
$db->primary = "user";
|
||||
$db->foreign = array (
|
||||
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(array ("user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"));
|
||||
}
|
||||
// Test the unique feature
|
||||
public function testInsert3()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
// Unique simple in insert
|
||||
$db->unique = ["user"];
|
||||
$db->primary = "user";
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(["user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
}
|
||||
|
||||
public function test_insert4()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = array ("user" => array ("varchar", "255", "not null"),
|
||||
"groupmember" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
// Unique multiple in insert
|
||||
$db->unique = array (array ("user", "groupmember"));
|
||||
$db->primary = "user";
|
||||
$db->foreign = array (
|
||||
"groupmember" => array ("grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"),
|
||||
);
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(array ("user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"));
|
||||
}
|
||||
public function testInsert4()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
// Unique multiple in insert
|
||||
$db->unique = [["user", "groupmember"]];
|
||||
$db->primary = "user";
|
||||
$db->foreign = [
|
||||
"groupmember" => ["grouped", "group", "ON UPDATE CASCADE ON DELETE CASCADE"],
|
||||
];
|
||||
$this->setExpectedException("Exception");
|
||||
$res = $db->insert(["user" => "Us ou\"r",
|
||||
"groupmember" => "NEW GROUP",
|
||||
"where" => "\$'\"",
|
||||
"with space" => "with space"]);
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
// Test multiple actions in one single connection
|
||||
public function test_multiple1()
|
||||
{
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
// Test multiple actions in one single connection
|
||||
public function testMultiple1()
|
||||
{
|
||||
|
||||
// Create a table named group
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "multiple";
|
||||
$db->fields = array ("user" => array ("varchar", "255", "not null"),
|
||||
"groupmember" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db->createTable();
|
||||
$db2 = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db2->table = "multiple2";
|
||||
$db2->fields = array ("user" => array ("varchar", "255", "not null"),
|
||||
"groupmember" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$db2->createTable();
|
||||
$res = $db2->read(array (array ("user", "toto")));
|
||||
$res = $db->read(array (array ("user", "toto")));
|
||||
$db->disconnect();
|
||||
$this->assertSame(array (), $res);
|
||||
}
|
||||
// Create a table named group
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "multiple";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db->createTable();
|
||||
$db2 = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db2->table = "multiple2";
|
||||
$db2->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$db2->createTable();
|
||||
$res = $db2->read([["user", "toto"]]);
|
||||
$res = $db->read([["user", "toto"]]);
|
||||
$db->disconnect();
|
||||
$this->assertSame([], $res);
|
||||
}
|
||||
|
||||
/** @group singleton */
|
||||
public function test_createTable3()
|
||||
{
|
||||
// Create a table named group
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users3";
|
||||
$db->fields = array ("user" => array ("varchar", "255", "not null"),
|
||||
"groupmember" => array ("varchar", "255", "not null"),
|
||||
"where" => array ("varchar", "255", "not null"),
|
||||
"with space" => array ("varchar", "255", "not null"));
|
||||
$res = $db->createTable();
|
||||
$db->disconnect();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
/**
|
||||
* @group singleton
|
||||
*/
|
||||
public function testCreateTable3()
|
||||
{
|
||||
// Create a table named group
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "users3";
|
||||
$db->fields = ["user" => ["varchar", "255", "not null"],
|
||||
"groupmember" => ["varchar", "255", "not null"],
|
||||
"where" => ["varchar", "255", "not null"],
|
||||
"with space" => ["varchar", "255", "not null"]];
|
||||
$res = $db->createTable();
|
||||
$db->disconnect();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
/** Check the OR feature on the same column with different value */
|
||||
public function test_readOR1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "readOR";
|
||||
$db->fields = array ("id" => array ("integer"),
|
||||
"user" => array ("varchar", "255", "not null"));
|
||||
$db->primary = "id";
|
||||
$db->unique = array ("id");
|
||||
$db->createTable();
|
||||
$db->insert(array ("id" => "0", "user" => "test0"));
|
||||
$db->insert(array ("id" => "1", "user" => "test1"));
|
||||
$res = $db->read(
|
||||
array (array ("id", 0), array ("id", 1)),
|
||||
array ("user"),
|
||||
null,
|
||||
true
|
||||
);
|
||||
$db->disconnect();
|
||||
$this->assertSame(array (0 => array ("user" => "test0"),
|
||||
1 => array ("user" => "test1")), $res);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Check the OR feature on the same column with different value
|
||||
*/
|
||||
public function testReadOR1()
|
||||
{
|
||||
$dbconfig = $this->confs["{ENGINE}"];
|
||||
$db = new Dblayer(
|
||||
$dbconfig["dsn"],
|
||||
$dbconfig["username"],
|
||||
$dbconfig["password"],
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$db->table = "readOR";
|
||||
$db->fields = ["id" => ["integer"],
|
||||
"user" => ["varchar", "255", "not null"]];
|
||||
$db->primary = "id";
|
||||
$db->unique = ["id"];
|
||||
$db->createTable();
|
||||
$db->insert(["id" => "0", "user" => "test0"]);
|
||||
$db->insert(["id" => "1", "user" => "test1"]);
|
||||
$res = $db->read(
|
||||
[["id", 0], ["id", 1]],
|
||||
["user"],
|
||||
null,
|
||||
true
|
||||
);
|
||||
$db->disconnect();
|
||||
$this->assertSame([0 => ["user" => "test0"],
|
||||
1 => ["user" => "test1"]], $res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
@@ -13,23 +14,23 @@ use Domframework\Authzgroups;
|
||||
|
||||
class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public $confs = array (
|
||||
"sqlite" => array (
|
||||
public $confs = [
|
||||
"sqlite" => [
|
||||
"dsn" => "sqlite:/tmp/databaseAuthz.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
));
|
||||
]];
|
||||
|
||||
public function test_delDB()
|
||||
public function testDelDB()
|
||||
{
|
||||
if (file_exists("/tmp/databaseAuthz.db")) {
|
||||
unlink("/tmp/databaseAuthz.db");
|
||||
}
|
||||
}
|
||||
|
||||
public function test_createTablesAuthzgroups()
|
||||
public function testCreateTablesAuthzgroups()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -50,11 +51,11 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$a->rightAdd("modTest", "group", "/article", "RO");
|
||||
$a->rightAdd("modTest", "group", "/article/base", "RO");
|
||||
$res = $a->rightAdd("modTest", "group", "/article/base/poub", "RW");
|
||||
// Should not be verified : it is not a test for authzgroups !
|
||||
// Should not be verified : it is not a test for authzgroups !
|
||||
$this->assertSame("4", $res);
|
||||
}
|
||||
|
||||
public function test_createTable()
|
||||
public function testCreateTable()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$n = new Dblayerauthzgroups(
|
||||
@@ -71,21 +72,21 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")));
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]]);
|
||||
$res = $n->createTable();
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
public function test_insert1()
|
||||
public function testInsert1()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -102,29 +103,29 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
->createGroupSet("group")
|
||||
->pathSet("/article/base/poub");
|
||||
$res = $n->insert(array ("zo ne" => "zone1",
|
||||
"opendate" => "2015-05-04 00:11:22"));
|
||||
$res = $n->insert(["zo ne" => "zone1",
|
||||
"opendate" => "2015-05-04 00:11:22"]);
|
||||
$n->disconnect();
|
||||
$this->assertSame("1", $res);
|
||||
}
|
||||
|
||||
// Check if the update of the authzgroups database is OK
|
||||
public function test_addAuthzgroups()
|
||||
public function testAddAuthzgroups()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -138,7 +139,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("RW", $res);
|
||||
}
|
||||
|
||||
public function test_insert2()
|
||||
public function testInsert2()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -155,32 +156,32 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
->createGroupSet("group")
|
||||
->pathSet("/article/base/poub");
|
||||
$n->insert(array ("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(array ("zo ne" => "zone4", "opendate" => "2015-05-04 00:11:22"));
|
||||
$res = $n->insert(array ("zo ne" => "zone5",
|
||||
"opendate" => "2015-05-04 00:11:22"));
|
||||
$n->insert(["zo ne" => "zone2", "opendate" => "2015-05-04 00:11:22"]);
|
||||
$n->insert(["zo ne" => "zone3", "opendate" => "2015-05-04 00:11:22"]);
|
||||
$n->insert(["zo ne" => "zone4", "opendate" => "2015-05-04 00:11:22"]);
|
||||
$res = $n->insert(["zo ne" => "zone5",
|
||||
"opendate" => "2015-05-04 00:11:22"]);
|
||||
$n->disconnect();
|
||||
$this->assertSame("5", $res);
|
||||
}
|
||||
|
||||
// Access to all the tuples
|
||||
public function test_read1()
|
||||
public function testRead1()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -197,16 +198,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
@@ -218,7 +219,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// Remove the right access to 2 and 4
|
||||
public function test_rightDel()
|
||||
public function testRightDel()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -230,12 +231,12 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
$a->rightDel("modTest", "group", "/article/base/poub/2");
|
||||
$res = $a->rightDel("modTest", "group", "/article/base/poub/4");
|
||||
// Should not be verified : it is not a test for authzgroups !
|
||||
// Should not be verified : it is not a test for authzgroups !
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
// Access to 3 of the tuples (2 are blacklisted for the user)
|
||||
public function test_read2()
|
||||
public function testRead2()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -252,16 +253,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
@@ -273,7 +274,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// Del an entry without right -> exception
|
||||
public function test_delEntry1()
|
||||
public function testDelEntry1()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -290,16 +291,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
@@ -310,7 +311,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// Update a right to RO
|
||||
public function test_rightRO()
|
||||
public function testRightRO()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -321,12 +322,12 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$res = $a->rightUpdate("modTest", "group", "/article/base/poub/1", "RO");
|
||||
// Not necessary to test : authzgroups
|
||||
// Not necessary to test : authzgroups
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
// Update an entry with RO right -> exception
|
||||
public function test_updateEntry2()
|
||||
public function testUpdateEntry2()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -343,27 +344,27 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
->createGroupSet("group")
|
||||
->pathSet("/article/base/poub");
|
||||
$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
|
||||
public function test_delEntry2()
|
||||
public function testDelEntry2()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -380,16 +381,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
@@ -400,7 +401,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// Update a right to RW
|
||||
public function test_rightRW()
|
||||
public function testRightRW()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -411,12 +412,12 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$res = $a->rightUpdate("modTest", "group", "/article/base/poub/1", "RW");
|
||||
// Not necessary to test : authzgroups
|
||||
// Not necessary to test : authzgroups
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
// Update an entry with RW right
|
||||
public function test_updateEntry3()
|
||||
public function testUpdateEntry3()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -433,27 +434,27 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
->createGroupSet("group")
|
||||
->pathSet("/article/base/poub");
|
||||
$res = $n->update(1, array ("zo ne" => "ALLOWED"));
|
||||
$res = $n->update(1, ["zo ne" => "ALLOWED"]);
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
// Del an entry with the RW right
|
||||
public function test_delEntry3()
|
||||
public function testDelEntry3()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -470,16 +471,16 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
@@ -490,7 +491,7 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// Check if the update of the authzgroups database is OK after deletion
|
||||
public function test_delAuthzgroups()
|
||||
public function testDelAuthzgroups()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -501,12 +502,12 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$res = $a->objectRead("modTest", "/article/base/poub/1");
|
||||
$this->assertSame(array (), $res);
|
||||
$this->assertSame([], $res);
|
||||
}
|
||||
|
||||
|
||||
// Read the zone without id
|
||||
public function test_read3()
|
||||
public function testRead3()
|
||||
{
|
||||
$dbconfig = $this->confs["sqlite"];
|
||||
$a = new Authzgroups();
|
||||
@@ -523,25 +524,25 @@ class DblayerauthzgroupsTest extends \PHPUnit_Framework_TestCase
|
||||
$dbconfig["driver_options"]
|
||||
);
|
||||
$n->tableSet("dns zones")
|
||||
->fieldsSet(array (
|
||||
"id" => array ("integer", "not null", "autoincrement"),
|
||||
"zo ne" => array ("varchar", "255", "not null"),
|
||||
"vie wname" => array ("varchar", "255"),
|
||||
"view clients" => array ("varchar", "255"),
|
||||
"comme nt" => array ("varchar", "1024"),
|
||||
"opendate" => array ("datetime", "not null"),
|
||||
"closedate" => array ("datetime")))
|
||||
->fieldsSet([
|
||||
"id" => ["integer", "not null", "autoincrement"],
|
||||
"zo ne" => ["varchar", "255", "not null"],
|
||||
"vie wname" => ["varchar", "255"],
|
||||
"view clients" => ["varchar", "255"],
|
||||
"comme nt" => ["varchar", "1024"],
|
||||
"opendate" => ["datetime", "not null"],
|
||||
"closedate" => ["datetime"]])
|
||||
->primarySet("id")
|
||||
->uniqueSet(array ("id", array ("zo ne", "vie wname")))
|
||||
->uniqueSet(["id", ["zo ne", "vie wname"]])
|
||||
->authzgroupsSet($a)
|
||||
->moduleSet("modTest")
|
||||
->userSet("user")
|
||||
->createGroupSet("group")
|
||||
->pathSet("/article/base/poub");
|
||||
$res = $n->read(null, array ("zo ne", "vie wname"));
|
||||
$res = $n->read(null, ["zo ne", "vie wname"]);
|
||||
$this->assertSame(
|
||||
array (1 => array ("zo ne" => "zone3", "vie wname" => null),
|
||||
3 => array ("zo ne" => "zone5", "vie wname" => null)),
|
||||
[1 => ["zo ne" => "zone3", "vie wname" => null],
|
||||
3 => ["zo ne" => "zone5", "vie wname" => null]],
|
||||
$res
|
||||
);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,19 +1,23 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Encrypt;
|
||||
|
||||
/** Test the Encrypt.php file */
|
||||
/**
|
||||
* Test the Encrypt.php file
|
||||
*/
|
||||
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()
|
||||
{
|
||||
$encrypt = new Encrypt();
|
||||
@@ -24,8 +28,9 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
$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()
|
||||
{
|
||||
$encrypt = new Encrypt();
|
||||
@@ -36,8 +41,9 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, $payload);
|
||||
}
|
||||
|
||||
/** Check if the encrypted part is well unreadable
|
||||
*/
|
||||
/**
|
||||
* Check if the encrypted part is well unreadable
|
||||
*/
|
||||
public function testEncrypt3()
|
||||
{
|
||||
$encrypt = new Encrypt();
|
||||
@@ -47,8 +53,9 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
/** Encrypt : Invalid Cipher method
|
||||
*/
|
||||
/**
|
||||
* Encrypt : Invalid Cipher method
|
||||
*/
|
||||
public function testInvalidCypher1()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -61,8 +68,9 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
$token = $encrypt->encrypt($payload, "123456789012345678901234", "TOTO");
|
||||
}
|
||||
|
||||
/** Encrypt : Invalid Payload to encrypt
|
||||
*/
|
||||
/**
|
||||
* Encrypt : Invalid Payload to encrypt
|
||||
*/
|
||||
public function testInvalidPayload()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -71,12 +79,13 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
500
|
||||
);
|
||||
$encrypt = new Encrypt();
|
||||
$payload = array ("Invalid");
|
||||
$payload = ["Invalid"];
|
||||
$token = $encrypt->encrypt($payload, "123456789012345678901234");
|
||||
}
|
||||
|
||||
/** Encrypt : Invalid Cipher Key to encrypt
|
||||
*/
|
||||
/**
|
||||
* Encrypt : Invalid Cipher Key to encrypt
|
||||
*/
|
||||
public function testInvalidCipherKey()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -90,8 +99,9 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
$token = $encrypt->encrypt($payload, "124");
|
||||
}
|
||||
|
||||
/** Decrypt : invalid cipher text
|
||||
*/
|
||||
/**
|
||||
* Decrypt : invalid cipher text
|
||||
*/
|
||||
public function testDecryptInvalidCipherKey()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -104,8 +114,9 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
$token = $encrypt->decrypt("zfz", "124");
|
||||
}
|
||||
|
||||
/** Decrypt : empty cipher string
|
||||
*/
|
||||
/**
|
||||
* Decrypt : empty cipher string
|
||||
*/
|
||||
public function testDecryptEmptyCipherString()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -117,8 +128,9 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
$token = $encrypt->decrypt("", "124");
|
||||
}
|
||||
|
||||
/** Decrypt : Not a string cypher
|
||||
*/
|
||||
/**
|
||||
* Decrypt : Not a string cypher
|
||||
*/
|
||||
public function testDecryptNotStringCipherString()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -127,11 +139,12 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
500
|
||||
);
|
||||
$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()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -140,11 +153,12 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
500
|
||||
);
|
||||
$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()
|
||||
{
|
||||
$this->expectException(
|
||||
@@ -153,11 +167,12 @@ class EncryptTest extends \PHPUnit_Framework_TestCase
|
||||
500
|
||||
);
|
||||
$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()
|
||||
{
|
||||
$this->expectException(
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\File;
|
||||
|
||||
/** Test the domframework File part */
|
||||
/**
|
||||
* Test the domframework File part
|
||||
*/
|
||||
class FileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testinit()
|
||||
@@ -303,7 +306,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$file->chdir("/tmp/testDFFileDir");
|
||||
}
|
||||
|
||||
public function testFile_get_contents1()
|
||||
public function testFileGetContents1()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
"Exception",
|
||||
@@ -318,7 +321,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $file->file_get_contents("/testDFFileDir");
|
||||
}
|
||||
|
||||
public function testFile_get_contents2()
|
||||
public function testFileGetContents2()
|
||||
{
|
||||
if (file_exists("/tmp/testDFFileDir")) {
|
||||
rmdir("/tmp/testDFFileDir");
|
||||
@@ -331,7 +334,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, "");
|
||||
}
|
||||
|
||||
public function testFile_put_contents1()
|
||||
public function testFilePutContents1()
|
||||
{
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
@@ -340,7 +343,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, "content");
|
||||
}
|
||||
|
||||
public function testFile_put_contents2()
|
||||
public function testFilePutContents2()
|
||||
{
|
||||
$this->setExpectedException(
|
||||
"Exception",
|
||||
@@ -350,7 +353,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$file->file_put_contents("/tmp/testDFFileDir", "content");
|
||||
}
|
||||
|
||||
public function testFile_put_contents3()
|
||||
public function testFilePutContents3()
|
||||
{
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
@@ -362,7 +365,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$file = new File();
|
||||
$res = $file->scandir("/tmp/testDFFileDir");
|
||||
$this->assertSame($res, array ("toto"));
|
||||
$this->assertSame($res, ["toto"]);
|
||||
}
|
||||
|
||||
public function testscandir2()
|
||||
@@ -370,7 +373,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
$res = $file->scandir("/testDFFileDir");
|
||||
$this->assertSame($res, array ("toto"));
|
||||
$this->assertSame($res, ["toto"]);
|
||||
}
|
||||
|
||||
public function testscandir3()
|
||||
@@ -378,12 +381,12 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
$res = $file->scandir("/testDFFileDir/");
|
||||
$this->assertSame($res, array ("toto"));
|
||||
$this->assertSame($res, ["toto"]);
|
||||
}
|
||||
|
||||
public function testrmdir1()
|
||||
{
|
||||
// Directory not empty and NOT recursive : return false
|
||||
// Directory not empty and NOT recursive : return false
|
||||
$file = new File();
|
||||
$res = $file->rmdir("/tmp/testDFFileDir");
|
||||
$this->assertSame($res, false);
|
||||
@@ -391,7 +394,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testrmdir2()
|
||||
{
|
||||
// Directory not empty and NOT recursive : return false
|
||||
// Directory not empty and NOT recursive : return false
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
$res = $file->rmdir("/testDFFileDir");
|
||||
@@ -400,7 +403,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testrmdir3()
|
||||
{
|
||||
// Directory not empty and recursive : return true
|
||||
// Directory not empty and recursive : return true
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
$res = $file->rmdir("/testDFFileDir", true);
|
||||
@@ -459,7 +462,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
// The parent doesn't exists and not recursive mode : exception
|
||||
// The parent doesn't exists and not recursive mode : exception
|
||||
$this->expectException();
|
||||
$res = $file->mkdir("/testDFFileDir/tptp/titi/poo");
|
||||
}
|
||||
@@ -472,58 +475,58 @@ class FileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_glob_1()
|
||||
public function testGlob1()
|
||||
{
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
$res = $file->glob("/testDFFileDir/*");
|
||||
$this->assertSame($res, array ("/testDFFileDir/toto",
|
||||
"/testDFFileDir/tptp"));
|
||||
$this->assertSame($res, ["/testDFFileDir/toto",
|
||||
"/testDFFileDir/tptp"]);
|
||||
}
|
||||
|
||||
public function test_glob_2()
|
||||
public function testGlob2()
|
||||
{
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
$file->chdir("/testDFFileDir");
|
||||
$res = $file->glob("*");
|
||||
$this->assertSame($res, array ("toto",
|
||||
"tptp"));
|
||||
$this->assertSame($res, ["toto",
|
||||
"tptp"]);
|
||||
}
|
||||
|
||||
public function test_glob_3()
|
||||
public function testGlob3()
|
||||
{
|
||||
$file = new File();
|
||||
$file->chroot("/tmp");
|
||||
$file->chdir("/testDFFileDir");
|
||||
$res = $file->glob("/testDFFileDir/*");
|
||||
$this->assertSame($res, array ("/testDFFileDir/toto",
|
||||
"/testDFFileDir/tptp"));
|
||||
$this->assertSame($res, ["/testDFFileDir/toto",
|
||||
"/testDFFileDir/tptp"]);
|
||||
}
|
||||
|
||||
public function test_glob_4()
|
||||
public function testGlob4()
|
||||
{
|
||||
$file = new File();
|
||||
$res = $file->glob("/tmp/testDFFileDir/*");
|
||||
$this->assertSame($res, array ("/tmp/testDFFileDir/toto",
|
||||
"/tmp/testDFFileDir/tptp"));
|
||||
$this->assertSame($res, ["/tmp/testDFFileDir/toto",
|
||||
"/tmp/testDFFileDir/tptp"]);
|
||||
}
|
||||
|
||||
public function test_glob_5()
|
||||
public function testGlob5()
|
||||
{
|
||||
$file = new File();
|
||||
$file->chdir("/tmp/testDFFileDir");
|
||||
$res = $file->glob("*");
|
||||
$this->assertSame($res, array ("toto",
|
||||
"tptp"));
|
||||
$this->assertSame($res, ["toto",
|
||||
"tptp"]);
|
||||
}
|
||||
|
||||
public function test_glob_6()
|
||||
public function testGlob6()
|
||||
{
|
||||
$file = new File();
|
||||
$file->chdir("/tmp/testDFFileDir");
|
||||
$res = $file->glob("/tmp/testDFFileDir/*");
|
||||
$this->assertSame($res, array ("/tmp/testDFFileDir/toto",
|
||||
"/tmp/testDFFileDir/tptp"));
|
||||
$this->assertSame($res, ["/tmp/testDFFileDir/toto",
|
||||
"/tmp/testDFFileDir/tptp"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,182 +1,185 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Fts;
|
||||
|
||||
/** Test the FTS */
|
||||
/**
|
||||
* Test the FTS
|
||||
*/
|
||||
class FtsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testTokenizerSearch0()
|
||||
{
|
||||
// Empty
|
||||
// Empty
|
||||
$fts = new Fts();
|
||||
$fts->search("");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array (),
|
||||
"minuses" => array ()));
|
||||
$this->assertSame($res, ["tokens" => [],
|
||||
"minuses" => []]);
|
||||
}
|
||||
|
||||
public function testTokenizerSearch1()
|
||||
{
|
||||
// Too small
|
||||
// Too small
|
||||
$fts = new Fts();
|
||||
$fts->search("X");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array (),
|
||||
"minuses" => array ()));
|
||||
$this->assertSame($res, ["tokens" => [],
|
||||
"minuses" => []]);
|
||||
}
|
||||
|
||||
public function testTokenizerSearch2()
|
||||
{
|
||||
// One word
|
||||
// One word
|
||||
$fts = new Fts();
|
||||
$fts->search("XYZ");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ"),
|
||||
"minuses" => array ("")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ"],
|
||||
"minuses" => [""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerSearch3()
|
||||
{
|
||||
// Two word
|
||||
// Two word
|
||||
$fts = new Fts();
|
||||
$fts->search("XYZ 123");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ", "123"),
|
||||
"minuses" => array ("", "")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ", "123"],
|
||||
"minuses" => ["", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerSearch4()
|
||||
{
|
||||
// Three word
|
||||
// Three word
|
||||
$fts = new Fts();
|
||||
$fts->search("XYZ 123 ABC");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ", "123", "ABC"),
|
||||
"minuses" => array ("", "", "")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ", "123", "ABC"],
|
||||
"minuses" => ["", "", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerSearch5()
|
||||
{
|
||||
// Three word
|
||||
// Three word
|
||||
$fts = new Fts();
|
||||
$fts->search("XYZ 123 ABC KLM");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ", "123",
|
||||
"ABC", "KLM"),
|
||||
"minuses" => array ("", "", "", "")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ", "123",
|
||||
"ABC", "KLM"],
|
||||
"minuses" => ["", "", "", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerSearch6()
|
||||
{
|
||||
// Three word
|
||||
// Three word
|
||||
$fts = new Fts();
|
||||
$fts->search("Louis-XYZ 123 -AéBCé KLM");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("Louis-XYZ", "123",
|
||||
"AéBCé", "KLM"),
|
||||
"minuses" => array ("", "", "-", "")));
|
||||
$this->assertSame($res, ["tokens" => ["Louis-XYZ", "123",
|
||||
"AéBCé", "KLM"],
|
||||
"minuses" => ["", "", "-", ""]]);
|
||||
}
|
||||
|
||||
|
||||
public function testTokenizerSentence0()
|
||||
{
|
||||
// Empty sentence
|
||||
// Empty sentence
|
||||
$fts = new Fts();
|
||||
$fts->search("\"\"");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array (),
|
||||
"minuses" => array ()));
|
||||
$this->assertSame($res, ["tokens" => [],
|
||||
"minuses" => []]);
|
||||
}
|
||||
|
||||
public function testTokenizerSentence1()
|
||||
{
|
||||
// One sentence only
|
||||
// One sentence only
|
||||
$fts = new Fts();
|
||||
$fts->search("\"XYZ 123\"");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ 123"),
|
||||
"minuses" => array ("")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ 123"],
|
||||
"minuses" => [""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerSentence2()
|
||||
{
|
||||
// Two sentence
|
||||
// Two sentence
|
||||
$fts = new Fts();
|
||||
$fts->search("\"XYZ 123\" \"ABC KLM\"");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ 123", "ABC KLM"),
|
||||
"minuses" => array ("", "")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ 123", "ABC KLM"],
|
||||
"minuses" => ["", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerSentence3()
|
||||
{
|
||||
// Three sentence
|
||||
// Three sentence
|
||||
$fts = new Fts();
|
||||
$fts->search("\"XYZ 123\" -\"ABC KLM\" \"RPO YUI\"");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ 123", "ABC KLM",
|
||||
"RPO YUI"),
|
||||
"minuses" => array ("", "-", "")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ 123", "ABC KLM",
|
||||
"RPO YUI"],
|
||||
"minuses" => ["", "-", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerMixed1()
|
||||
{
|
||||
// One word and one sentence, starting by word
|
||||
// One word and one sentence, starting by word
|
||||
$fts = new Fts();
|
||||
$fts->search("XYZ \"ABC KLM\"");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("XYZ", "ABC KLM"),
|
||||
"minuses" => array ("", "")));
|
||||
$this->assertSame($res, ["tokens" => ["XYZ", "ABC KLM"],
|
||||
"minuses" => ["", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerMixed2()
|
||||
{
|
||||
// One word and one sentence, starting by sentence
|
||||
// One word and one sentence, starting by sentence
|
||||
$fts = new Fts();
|
||||
$fts->search("\"ABC KLM\" XYZ");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("ABC KLM", "XYZ"),
|
||||
"minuses" => array ("", "")));
|
||||
$this->assertSame($res, ["tokens" => ["ABC KLM", "XYZ"],
|
||||
"minuses" => ["", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerMixed3()
|
||||
{
|
||||
// One word and two sentences, starting by sentence
|
||||
// One word and two sentences, starting by sentence
|
||||
$fts = new Fts();
|
||||
$fts->search("\"ABC KLM\" XYZ \"RPO YUI\"");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("ABC KLM", "XYZ",
|
||||
"RPO YUI"),
|
||||
"minuses" => array ("", "", "")));
|
||||
$this->assertSame($res, ["tokens" => ["ABC KLM", "XYZ",
|
||||
"RPO YUI"],
|
||||
"minuses" => ["", "", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerMixed4()
|
||||
{
|
||||
// Two words and two sentences, starting by sentence
|
||||
// Two words and two sentences, starting by sentence
|
||||
$fts = new Fts();
|
||||
$fts->search("\"ABC KLM\" XYZ \"RPO YUI\" 123");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("ABC KLM", "XYZ",
|
||||
"RPO YUI", "123"),
|
||||
"minuses" => array ("", "", "", "")));
|
||||
$this->assertSame($res, ["tokens" => ["ABC KLM", "XYZ",
|
||||
"RPO YUI", "123"],
|
||||
"minuses" => ["", "", "", ""]]);
|
||||
}
|
||||
|
||||
public function testTokenizerMixed5()
|
||||
{
|
||||
// Two words and two sentences, starting by a word
|
||||
// Two words and two sentences, starting by a word
|
||||
$fts = new Fts();
|
||||
$fts->search("123 \"ABC KLM\" XYZ \"RPO YUI\"");
|
||||
$res = $fts->getTokensMin();
|
||||
$this->assertSame($res, array ("tokens" => array ("123", "ABC KLM",
|
||||
"XYZ", "RPO YUI"),
|
||||
"minuses" => array ("", "", "", "")));
|
||||
$this->assertSame($res, ["tokens" => ["123", "ABC KLM",
|
||||
"XYZ", "RPO YUI"],
|
||||
"minuses" => ["", "", "", ""]]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,183 +1,186 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Getopts;
|
||||
|
||||
/** Test the GetOpts */
|
||||
/**
|
||||
* Test the GetOpts
|
||||
*/
|
||||
class GetoptsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_empty1()
|
||||
public function testEmpty1()
|
||||
{
|
||||
// Empty
|
||||
// Empty
|
||||
$getopts = new Getopts();
|
||||
$res = $getopts->help();
|
||||
$this->assertSame($res, "No option defined\n");
|
||||
}
|
||||
|
||||
public function test_simu1()
|
||||
public function testSimu1()
|
||||
{
|
||||
$getopts = new Getopts();
|
||||
$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);
|
||||
}
|
||||
|
||||
public function test_add1()
|
||||
public function testAdd1()
|
||||
{
|
||||
$getopts = new Getopts();
|
||||
$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);
|
||||
}
|
||||
|
||||
public function test_add2()
|
||||
public function testAdd2()
|
||||
{
|
||||
$getopts = new Getopts();
|
||||
$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);
|
||||
$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");
|
||||
$getopts = new Getopts();
|
||||
$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);
|
||||
$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->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);
|
||||
$res = $getopts->get("Help");
|
||||
$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->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);
|
||||
$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->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);
|
||||
$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->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);
|
||||
$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->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);
|
||||
$res = $getopts->get("Help");
|
||||
$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->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);
|
||||
$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->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);
|
||||
$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->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);
|
||||
$res = $getopts->get("Debug");
|
||||
$this->assertSame($res, array ());
|
||||
$this->assertSame($res, []);
|
||||
}
|
||||
|
||||
public function test_restOfLine1()
|
||||
public function testRestOfLine1()
|
||||
{
|
||||
$getopts = new Getopts();
|
||||
$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);
|
||||
$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->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);
|
||||
$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->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);
|
||||
$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->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);
|
||||
$res = $getopts->programName();
|
||||
$this->assertSame($res, "sim ulate");
|
||||
|
||||
@@ -1,67 +1,76 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Http;
|
||||
|
||||
/** Test the Http.php file */
|
||||
/**
|
||||
* Test the Http.php file
|
||||
*/
|
||||
class HttpTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** bestChoice : exact existing entry
|
||||
*/
|
||||
/**
|
||||
* bestChoice : exact existing entry
|
||||
*/
|
||||
public function testBestChoice1()
|
||||
{
|
||||
$http = new Http();
|
||||
$res = $http->bestChoice(
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
array ("application/xml"),
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,
|
||||
*/*;q=0.8",
|
||||
["application/xml"],
|
||||
"text/html"
|
||||
);
|
||||
$this->assertSame($res, "application/xml");
|
||||
}
|
||||
|
||||
/** bestChoice : Generic catch.
|
||||
* Use default value
|
||||
*/
|
||||
/**
|
||||
* bestChoice : Generic catch.
|
||||
* Use default value
|
||||
*/
|
||||
public function testBestChoice2()
|
||||
{
|
||||
$http = new Http();
|
||||
$res = $http->bestChoice(
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
|
||||
array ("text/plain"),
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,
|
||||
*/*;q=0.8",
|
||||
["text/plain"],
|
||||
"text/html"
|
||||
);
|
||||
$this->assertSame($res, "text/html");
|
||||
}
|
||||
|
||||
/** bestChoice : no solution : use the default value
|
||||
*/
|
||||
/**
|
||||
* bestChoice : no solution : use the default value
|
||||
*/
|
||||
public function testBestChoice3()
|
||||
{
|
||||
$http = new Http();
|
||||
$res = $http->bestChoice(
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9",
|
||||
array ("text/plain"),
|
||||
["text/plain"],
|
||||
"text/html"
|
||||
);
|
||||
$this->assertSame($res, "text/html");
|
||||
}
|
||||
|
||||
/** bestChoice : invalid entry (end with comma). Continue without error and
|
||||
* skip the bad choices
|
||||
*/
|
||||
/**
|
||||
* bestChoice : invalid entry (end with comma). Continue without error and
|
||||
* skip the bad choices
|
||||
*/
|
||||
public function testBestChoice4()
|
||||
{
|
||||
$http = new Http();
|
||||
$res = $http->bestChoice(
|
||||
"text/html,application/xhtml+xml,application/xml;q=0.9,",
|
||||
array ("text/plain"),
|
||||
["text/plain"],
|
||||
"text/html"
|
||||
);
|
||||
$this->assertSame($res, "text/html");
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Inifile;
|
||||
|
||||
/** Test the Inifile.php file */
|
||||
/**
|
||||
* Test the Inifile.php file
|
||||
*/
|
||||
class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testsetString001()
|
||||
@@ -23,7 +26,7 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
public function testsetString002()
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(array (), true);
|
||||
$res = $inifile->setString([], true);
|
||||
$this->assertSame("", $res);
|
||||
}
|
||||
|
||||
@@ -32,34 +35,34 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->setExpectedException("Exception");
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(array ("section1"), true);
|
||||
$res = $inifile->setString(["section1"], true);
|
||||
}
|
||||
|
||||
public function testsetString104()
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(array ("section1" => array ()), true);
|
||||
$res = $inifile->setString(["section1" => []], true);
|
||||
$this->assertSame("[section1]\n\n", $res);
|
||||
}
|
||||
|
||||
public function testsetString105()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testsetString106()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testsetString107()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -67,7 +70,7 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null, 1 => 1)),
|
||||
["section1" => [0 => null, 1 => 1]],
|
||||
true
|
||||
);
|
||||
$this->assertSame("[section1]\n0 = \"null\"\n1 = \"1\"\n\n", $res);
|
||||
@@ -77,8 +80,8 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null,
|
||||
1 => 1, 2 => "str")),
|
||||
["section1" => [0 => null,
|
||||
1 => 1, 2 => "str"]],
|
||||
true
|
||||
);
|
||||
$this->assertSame(
|
||||
@@ -91,9 +94,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null,
|
||||
["section1" => [0 => null,
|
||||
1 => 1, 2 => "str",
|
||||
3 => array (1,2,3))),
|
||||
3 => [1,2,3]]],
|
||||
true
|
||||
);
|
||||
$this->assertSame(
|
||||
@@ -107,9 +110,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null,
|
||||
["section1" => [0 => null,
|
||||
1 => 1, 2 => "str",
|
||||
3 => array ())),
|
||||
3 => []]],
|
||||
true
|
||||
);
|
||||
$this->assertSame(
|
||||
@@ -122,9 +125,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null,
|
||||
["section1" => [0 => null,
|
||||
1 => 1, 2 => "str",
|
||||
"chain" => array ("key" => 1,2))),
|
||||
"chain" => ["key" => 1,2]]],
|
||||
true
|
||||
);
|
||||
$this->assertSame(
|
||||
@@ -138,35 +141,35 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
public function testsetString203()
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(array ("section1"), false);
|
||||
$res = $inifile->setString(["section1"], false);
|
||||
$this->assertSame("0 = \"section1\"\n\n", $res);
|
||||
}
|
||||
|
||||
public function testsetString204()
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(array ("section1" => array ()), false);
|
||||
$res = $inifile->setString(["section1" => []], false);
|
||||
$this->assertSame("\n", $res);
|
||||
}
|
||||
|
||||
public function testsetString205()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testsetString206()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
public function testsetString207()
|
||||
{
|
||||
$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);
|
||||
}
|
||||
|
||||
@@ -174,7 +177,7 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null, 1 => 1)),
|
||||
["section1" => [0 => null, 1 => 1]],
|
||||
false
|
||||
);
|
||||
$this->assertSame(
|
||||
@@ -187,8 +190,8 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null,
|
||||
1 => 1, 2 => "str")),
|
||||
["section1" => [0 => null,
|
||||
1 => 1, 2 => "str"]],
|
||||
false
|
||||
);
|
||||
$this->assertSame(
|
||||
@@ -203,9 +206,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->setExpectedException("Exception");
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null,
|
||||
["section1" => [0 => null,
|
||||
1 => 1, 2 => "str",
|
||||
3 => array (1,2,3))),
|
||||
3 => [1,2,3]]],
|
||||
false
|
||||
);
|
||||
}
|
||||
@@ -215,9 +218,9 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->setExpectedException("Exception");
|
||||
$inifile = new Inifile();
|
||||
$res = $inifile->setString(
|
||||
array ("section1" => array (0 => null,
|
||||
["section1" => [0 => null,
|
||||
1 => 1, 2 => "str",
|
||||
3 => array ())),
|
||||
3 => []]],
|
||||
false
|
||||
);
|
||||
}
|
||||
@@ -227,28 +230,28 @@ class InifileTest extends \PHPUnit_Framework_TestCase
|
||||
public function testLoop406()
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$loop = $inifile->setString(array ("section1" => array (0 => 1)), false);
|
||||
$loop = $inifile->setString(["section1" => [0 => 1]], false);
|
||||
var_dump($loop);
|
||||
$res = $inifile->getString($loop, false);
|
||||
var_dump($res);
|
||||
$this->assertSame(array ("section1" => array (0 => 1)), $res);
|
||||
$this->assertSame(["section1" => [0 => 1]], $res);
|
||||
}
|
||||
|
||||
public function testLoop407()
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$loop = $inifile->setString(array ("section1" => array (0 => null)), false);
|
||||
$loop = $inifile->setString(["section1" => [0 => null]], false);
|
||||
$res = $inifile->getString($loop, false);
|
||||
$this->assertSame(array ("section1" => array (0 => null)), $res);
|
||||
$this->assertSame(["section1" => [0 => null]], $res);
|
||||
}
|
||||
|
||||
public function testLoop408()
|
||||
{
|
||||
$inifile = new Inifile();
|
||||
$loop = $inifile->setString(array ("section1" => array (0 => "toto")), false);
|
||||
$loop = $inifile->setString(["section1" => [0 => "toto"]], false);
|
||||
var_dump($loop);
|
||||
$res = $inifile->getString($loop, false);
|
||||
var_dump($res);
|
||||
$this->assertSame(array ("section1" => array (0 => "toto")), $res);
|
||||
$this->assertSame(["section1" => [0 => "toto"]], $res);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,255 +1,258 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Ipaddresses;
|
||||
|
||||
/** Test the Ipaddresses.php file */
|
||||
/**
|
||||
* Test the Ipaddresses.php file
|
||||
*/
|
||||
class IpaddressesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_validIPAddress1()
|
||||
public function testValidIPAddress1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPAddress("::");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPAddress2()
|
||||
public function testValidIPAddress2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPAddress("1::");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPAddress3()
|
||||
public function testValidIPAddress3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPAddress("::1");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPAddress4()
|
||||
public function testValidIPAddress4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPAddress("2001::1");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPAddress5()
|
||||
public function testValidIPAddress5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPAddress("1.2.3.4");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPAddress6()
|
||||
public function testValidIPAddress6()
|
||||
{
|
||||
$this->setExpectedException("Exception");
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPAddress("");
|
||||
}
|
||||
public function test_validIPAddress7()
|
||||
public function testValidIPAddress7()
|
||||
{
|
||||
$this->setExpectedException("Exception");
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPAddress(array ());
|
||||
$res = $i->validIPAddress([]);
|
||||
}
|
||||
|
||||
public function test_validIPv4Address1()
|
||||
public function testValidIPv4Address1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv4Address("::");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validIPv4Address2()
|
||||
public function testValidIPv4Address2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv4Address("1.2.3.4");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_validIPv6Address1()
|
||||
public function testValidIPv6Address1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6Address("1.2.3.4");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validIPv6Address2()
|
||||
public function testValidIPv6Address2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6Address("::");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPv6Address3()
|
||||
public function testValidIPv6Address3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6Address("1::");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPv6Address4()
|
||||
public function testValidIPv6Address4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6Address("::1");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPv6Address5()
|
||||
public function testValidIPv6Address5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6Address("1::1");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPv6Address6()
|
||||
public function testValidIPv6Address6()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6Address("1:1:1");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
|
||||
public function test_validCIDR1()
|
||||
public function testValidCIDR1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validCIDR(-1);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validCIDR2()
|
||||
public function testValidCIDR2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validCIDR(129);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validCIDR3()
|
||||
public function testValidCIDR3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validCIDR(128);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validCIDR4()
|
||||
public function testValidCIDR4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validCIDR(0);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_validIPv4CIDR1()
|
||||
public function testValidIPv4CIDR1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv4CIDR(-1);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validIPv4CIDR2()
|
||||
public function testValidIPv4CIDR2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv4CIDR(33);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validIPv4CIDR3()
|
||||
public function testValidIPv4CIDR3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv4CIDR(32);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPv4CIDR4()
|
||||
public function testValidIPv4CIDR4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv4CIDR(0);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_validIPv6CIDR1()
|
||||
public function testValidIPv6CIDR1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6CIDR(-1);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validIPv6CIDR2()
|
||||
public function testValidIPv6CIDR2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6CIDR(129);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_validIPv6CIDR3()
|
||||
public function testValidIPv6CIDR3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6CIDR(128);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_validIPv6CIDR4()
|
||||
public function testValidIPv6CIDR4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->validIPv6CIDR(0);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_compressIP1()
|
||||
public function testCompressIP1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->compressIP("::");
|
||||
$this->assertSame("::", $res);
|
||||
}
|
||||
public function test_compressIP2()
|
||||
public function testCompressIP2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->compressIP("::1");
|
||||
$this->assertSame("::1", $res);
|
||||
}
|
||||
public function test_compressIP3()
|
||||
public function testCompressIP3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->compressIP("2::1");
|
||||
$this->assertSame("2::1", $res);
|
||||
}
|
||||
public function test_compressIP4()
|
||||
public function testCompressIP4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->compressIP("2::");
|
||||
$this->assertSame("2::", $res);
|
||||
}
|
||||
public function test_compressIP5()
|
||||
public function testCompressIP5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->compressIP("2:1:0:3::0:1");
|
||||
$this->assertSame("2:1:0:3::1", $res);
|
||||
}
|
||||
public function test_compressIP6()
|
||||
public function testCompressIP6()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->compressIP("2:1:0:3:0000::1");
|
||||
$this->assertSame("2:1:0:3::1", $res);
|
||||
}
|
||||
|
||||
public function test_uncompressIPv6a()
|
||||
public function testUncompressIPv6a()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->uncompressIPv6("1::1");
|
||||
$this->assertSame("1:0:0:0:0:0:0:1", $res);
|
||||
}
|
||||
public function test_uncompressIPv6b()
|
||||
public function testUncompressIPv6b()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->uncompressIPv6("1::");
|
||||
$this->assertSame("1:0:0:0:0:0:0:0", $res);
|
||||
}
|
||||
public function test_uncompressIPv6c()
|
||||
public function testUncompressIPv6c()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->uncompressIPv6("::");
|
||||
$this->assertSame("0:0:0:0:0:0:0:0", $res);
|
||||
}
|
||||
public function test_uncompressIPv6d()
|
||||
public function testUncompressIPv6d()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->uncompressIPv6("1.2.3.4");
|
||||
$this->assertSame("1.2.3.4", $res);
|
||||
}
|
||||
|
||||
public function test_groupIPv6a()
|
||||
public function testGroupIPv6a()
|
||||
{
|
||||
$this->setExpectedException("Exception");
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->groupIPv6("1.2.3.4");
|
||||
}
|
||||
public function test_groupIPv6b()
|
||||
public function testGroupIPv6b()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$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);
|
||||
}
|
||||
|
||||
public function test_completeAddressWithZero1()
|
||||
public function testCompleteAddressWithZero1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->completeAddressWithZero("::");
|
||||
$this->assertSame("0000:0000:0000:0000:0000:0000:0000:0000", $res);
|
||||
}
|
||||
public function test_completeAddressWithZero2()
|
||||
public function testCompleteAddressWithZero2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->completeAddressWithZero("::1");
|
||||
$this->assertSame("0000:0000:0000:0000:0000:0000:0000:0001", $res);
|
||||
}
|
||||
public function test_completeAddressWithZero3()
|
||||
public function testCompleteAddressWithZero3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->completeAddressWithZero("1::");
|
||||
$this->assertSame("0001:0000:0000:0000:0000:0000:0000:0000", $res);
|
||||
}
|
||||
public function test_completeAddressWithZero4()
|
||||
public function testCompleteAddressWithZero4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->completeAddressWithZero("1::1");
|
||||
$this->assertSame("0001:0000:0000:0000:0000:0000:0000:0001", $res);
|
||||
}
|
||||
public function test_completeAddressWithZero5()
|
||||
public function testCompleteAddressWithZero5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->completeAddressWithZero("1:222::1");
|
||||
$this->assertSame("0001:0222:0000:0000:0000:0000:0000:0001", $res);
|
||||
}
|
||||
public function test_completeAddressWithZero6()
|
||||
public function testCompleteAddressWithZero6()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->completeAddressWithZero("1.2.3.4");
|
||||
@@ -297,274 +300,274 @@ class IpaddressesTest extends \PHPUnit_Framework_TestCase
|
||||
// TODO : cidrToBin
|
||||
// TODO : str_base_convert
|
||||
|
||||
public function test_reverseIPAddress1()
|
||||
public function testReverseIPAddress1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->reverseIPAddress("1.2.3.4");
|
||||
$this->assertSame("4.3.2.1", $res);
|
||||
}
|
||||
public function test_reverseIPAddress2()
|
||||
public function testReverseIPAddress2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$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);
|
||||
}
|
||||
public function test_reverseIPAddress3()
|
||||
public function testReverseIPAddress3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$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);
|
||||
}
|
||||
public function test_reverseIPAddress4()
|
||||
public function testReverseIPAddress4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$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);
|
||||
}
|
||||
public function test_reverseIPAddress5()
|
||||
public function testReverseIPAddress5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$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);
|
||||
}
|
||||
|
||||
public function test_netmask2cidr1()
|
||||
public function testNetmask2cidr1()
|
||||
{
|
||||
$this->setExpectedException("Exception");
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr(0);
|
||||
}
|
||||
public function test_netmask2cidr2()
|
||||
public function testNetmask2cidr2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("255.255.255.0");
|
||||
$this->assertSame(24, $res);
|
||||
}
|
||||
public function test_netmask2cidr3()
|
||||
public function testNetmask2cidr3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("255.255.255.255");
|
||||
$this->assertSame(32, $res);
|
||||
}
|
||||
public function test_netmask2cidr4()
|
||||
public function testNetmask2cidr4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("255.255.255.255");
|
||||
$this->assertSame(32, $res);
|
||||
}
|
||||
public function test_netmask2cidr5()
|
||||
public function testNetmask2cidr5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("255.0.0.0");
|
||||
$this->assertSame(8, $res);
|
||||
}
|
||||
public function test_netmask2cidr6()
|
||||
public function testNetmask2cidr6()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("127.0.0.0");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_netmask2cidr7()
|
||||
public function testNetmask2cidr7()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("63.0.0.0");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_netmask2cidr8()
|
||||
public function testNetmask2cidr8()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("155.0.0.0");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_netmask2cidr9()
|
||||
public function testNetmask2cidr9()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("0.0.0.255");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
|
||||
public function test_netmask2cidrWildcard_1()
|
||||
public function testNetmask2cidrWildcard1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("255.255.255.0", false);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
|
||||
public function test_netmask2cidrWildcard_2()
|
||||
public function testNetmask2cidrWildcard2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("0.0.0.0", false);
|
||||
$this->assertSame(32, $res);
|
||||
}
|
||||
public function test_netmask2cidrWildcard_3()
|
||||
public function testNetmask2cidrWildcard3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->netmask2cidr("255.255.255.255", false);
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
public function test_cidr2netmask_1()
|
||||
public function testCidr2netmask1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->cidr2netmask(0, true);
|
||||
$this->assertSame("0.0.0.0", $res);
|
||||
}
|
||||
|
||||
public function test_cidr2netmask_2()
|
||||
public function testCidr2netmask2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->cidr2netmask(24, true);
|
||||
$this->assertSame("255.255.255.0", $res);
|
||||
}
|
||||
|
||||
public function test_cidr2netmask_3()
|
||||
public function testCidr2netmask3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->cidr2netmask(25, true);
|
||||
$this->assertSame("255.255.255.128", $res);
|
||||
}
|
||||
|
||||
public function test_cidr2netmask_4()
|
||||
public function testCidr2netmask4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->cidr2netmask(32, true);
|
||||
$this->assertSame("255.255.255.255", $res);
|
||||
}
|
||||
public function test_cidr2netmask_5()
|
||||
public function testCidr2netmask5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->cidr2netmask(1, true);
|
||||
$this->assertSame("128.0.0.0", $res);
|
||||
}
|
||||
|
||||
public function test_ipInNetwork1()
|
||||
public function testIpInNetwork1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->ipInNetwork("127.0.0.1", "127.1.0.0", 8);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_ipInNetwork2()
|
||||
public function testIpInNetwork2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->ipInNetwork("192.168.1.1", "127.1.0.0", 8);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_ipInNetwork3()
|
||||
public function testIpInNetwork3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->ipInNetwork("2001:660:530d:201::1", "2001:660:530d:201::", 64);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_ipInNetwork4()
|
||||
public function testIpInNetwork4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->ipInNetwork("2001:660:530d:203::1", "2001:660:530d:201::", 64);
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
public function test_ipInNetwork5()
|
||||
public function testIpInNetwork5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->ipInNetwork("2001:660:530d:203::1", "2001::", 0);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
public function test_ipInNetwork6()
|
||||
public function testIpInNetwork6()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->ipInNetwork("192.168.1.1", "127.0.0.0", 0);
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_networkFirstIP1()
|
||||
public function testNetworkFirstIP1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("192.168.1.21", 24);
|
||||
$this->assertSame($res, "192.168.1.0");
|
||||
}
|
||||
public function test_networkFirstIP2()
|
||||
public function testNetworkFirstIP2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("192.168.1.21", 0);
|
||||
$this->assertSame($res, "0.0.0.0");
|
||||
}
|
||||
public function test_networkFirstIP3()
|
||||
public function testNetworkFirstIP3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("192.168.1.21", 32);
|
||||
$this->assertSame($res, "192.168.1.21");
|
||||
}
|
||||
public function test_networkFirstIP4()
|
||||
public function testNetworkFirstIP4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("192.168.1.21", 31);
|
||||
$this->assertSame($res, "192.168.1.20");
|
||||
}
|
||||
public function test_networkFirstIP5()
|
||||
public function testNetworkFirstIP5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("2001:660:530d:201::125", 64);
|
||||
$this->assertSame($res, "2001:660:530d:201::");
|
||||
}
|
||||
public function test_networkFirstIP6()
|
||||
public function testNetworkFirstIP6()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("2001:660:530d:201::125", 0);
|
||||
$this->assertSame($res, "::");
|
||||
}
|
||||
public function test_networkFirstIP7()
|
||||
public function testNetworkFirstIP7()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("2001:660:530d:201::125", 128);
|
||||
$this->assertSame($res, "2001:660:530d:201::125");
|
||||
}
|
||||
public function test_networkFirstIP8()
|
||||
public function testNetworkFirstIP8()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkFirstIP("2001:660:530d:201::125", 127);
|
||||
$this->assertSame($res, "2001:660:530d:201::124");
|
||||
}
|
||||
public function test_networkLastIP1()
|
||||
public function testNetworkLastIP1()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("192.168.1.21", 24);
|
||||
$this->assertSame($res, "192.168.1.255");
|
||||
}
|
||||
public function test_networkLastIP2()
|
||||
public function testNetworkLastIP2()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("192.168.1.21", 0);
|
||||
$this->assertSame($res, "255.255.255.255");
|
||||
}
|
||||
public function test_networkLastIP3()
|
||||
public function testNetworkLastIP3()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("192.168.1.21", 32);
|
||||
$this->assertSame($res, "192.168.1.21");
|
||||
}
|
||||
public function test_networkLastIP4()
|
||||
public function testNetworkLastIP4()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("192.168.1.21", 31);
|
||||
$this->assertSame($res, "192.168.1.21");
|
||||
}
|
||||
public function test_networkLastIP5()
|
||||
public function testNetworkLastIP5()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("2001:660:530d:201::125", 64);
|
||||
$this->assertSame($res, "2001:660:530d:201:ffff:ffff:ffff:ffff");
|
||||
}
|
||||
public function test_networkLastIP6()
|
||||
public function testNetworkLastIP6()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("2001:660:530d:201::125", 0);
|
||||
$this->assertSame($res, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
|
||||
}
|
||||
public function test_networkLastIP7()
|
||||
public function testNetworkLastIP7()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("2001:660:530d:201::125", 128);
|
||||
$this->assertSame($res, "2001:660:530d:201::125");
|
||||
}
|
||||
public function test_networkLastIP8()
|
||||
public function testNetworkLastIP8()
|
||||
{
|
||||
$i = new Ipaddresses();
|
||||
$res = $i->networkLastIP("2001:660:530d:201::125", 127);
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Jwt;
|
||||
|
||||
/** Test the Jwt.php file */
|
||||
/**
|
||||
* Test the Jwt.php file
|
||||
*/
|
||||
class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_createKey_1()
|
||||
public function testCreateKey1()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$res = $jwt->createKey();
|
||||
$this->assertSame(40, strlen($res));
|
||||
}
|
||||
|
||||
public function test_sign_1()
|
||||
public function testSign1()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$res = $this->invokeMethod(
|
||||
@@ -36,7 +39,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_sign_2()
|
||||
public function testSign2()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$res = $this->invokeMethod(
|
||||
@@ -52,7 +55,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_sign_3()
|
||||
public function testSign3()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$res = $this->invokeMethod(
|
||||
@@ -68,10 +71,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_encode_1()
|
||||
public function testEncode1()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$res = $jwt->encode(array ("payload" => "value"), "key to use", "HS384");
|
||||
$res = $jwt->encode(["payload" => "value"], "key to use", "HS384");
|
||||
$this->assertSame(
|
||||
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzM4NCJ9." .
|
||||
"eyJwYXlsb2FkIjoidmFsdWUifQ." .
|
||||
@@ -80,7 +83,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_decode_1()
|
||||
public function testDecode1()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$res = $jwt->decode(
|
||||
@@ -89,10 +92,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
"0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge",
|
||||
"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;
|
||||
$jwt = new Jwt();
|
||||
@@ -102,10 +105,10 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
"0ByHaODQQjYEvmgU2u5LI034RRMc7CKJQ752ys19Fqj7QiTJO7-trerYKCxCyuge",
|
||||
"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();
|
||||
$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();
|
||||
$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();
|
||||
$this->expectException(
|
||||
@@ -144,7 +147,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_decode_6()
|
||||
public function testDecode6()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$this->expectException(
|
||||
@@ -159,7 +162,7 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_decode_7()
|
||||
public function testDecode7()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$this->expectException(
|
||||
@@ -176,8 +179,9 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
///////////////////////////////
|
||||
// ENCRYPT THE PAYLOAD //
|
||||
///////////////////////////////
|
||||
/** Check the length of the otken with cipher
|
||||
*/
|
||||
/**
|
||||
* Check the length of the otken with cipher
|
||||
*/
|
||||
public function testEncrypt1()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
@@ -191,8 +195,9 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
$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()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
@@ -203,15 +208,16 @@ class JwtTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, $payload);
|
||||
}
|
||||
|
||||
/** Check if the encrypted part is well unreadable
|
||||
*/
|
||||
/**
|
||||
* Check if the encrypted part is well unreadable
|
||||
*/
|
||||
public function testEncrypt3()
|
||||
{
|
||||
$jwt = new Jwt();
|
||||
$key = $jwt->createKey();
|
||||
$payload = (object)["email" => "toto@example.com", "password" => "ToTo"];
|
||||
$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");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
@@ -1,110 +1,113 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Macaddresses;
|
||||
|
||||
/** Test the Macaddresses.php file */
|
||||
/**
|
||||
* Test the Macaddresses.php file
|
||||
*/
|
||||
class MacaddressesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_isMACAddress_1()
|
||||
public function testIsMACAddress1()
|
||||
{
|
||||
$macaddresses = new Macaddresses();
|
||||
$res = $macaddresses->isMACAddress("");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
|
||||
public function test_isMACAddress_2()
|
||||
public function testIsMACAddress2()
|
||||
{
|
||||
$macaddresses = new Macaddresses();
|
||||
$res = $macaddresses->isMACAddress("INVALID");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
|
||||
public function test_isMACAddress_3()
|
||||
public function testIsMACAddress3()
|
||||
{
|
||||
$macaddresses = new Macaddresses();
|
||||
$res = $macaddresses->isMACAddress("de:ad:be:af:aa:bb");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_isMACAddress_4()
|
||||
public function testIsMACAddress4()
|
||||
{
|
||||
$macaddresses = new Macaddresses();
|
||||
$res = $macaddresses->isMACAddress("de-ad-be-af-aa-bb");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_isMACAddress_5()
|
||||
public function testIsMACAddress5()
|
||||
{
|
||||
$macaddresses = new Macaddresses();
|
||||
$res = $macaddresses->isMACAddress("0005.313B.9080");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_isMACAddress_6()
|
||||
public function testIsMACAddress6()
|
||||
{
|
||||
$macaddresses = new Macaddresses();
|
||||
$res = $macaddresses->isMACAddress("0005313B9080");
|
||||
$this->assertSame(true, $res);
|
||||
}
|
||||
|
||||
public function test_isMACAddress_7()
|
||||
public function testIsMACAddress7()
|
||||
{
|
||||
$macaddresses = new Macaddresses();
|
||||
$res = $macaddresses->isMACAddress("a0005313B9080a");
|
||||
$this->assertSame(false, $res);
|
||||
}
|
||||
|
||||
public function test_addSeparator_1()
|
||||
public function testAddSeparator1()
|
||||
{
|
||||
$res = Macaddresses::addSeparator("0005313B9080");
|
||||
$this->assertSame("00:05:31:3B:90:80", $res);
|
||||
}
|
||||
|
||||
public function test_addSeparator_2()
|
||||
public function testAddSeparator2()
|
||||
{
|
||||
$res = Macaddresses::addSeparator("0005313B9080", "-");
|
||||
$this->assertSame("00-05-31-3B-90-80", $res);
|
||||
}
|
||||
|
||||
public function test_addSeparator_3()
|
||||
public function testAddSeparator3()
|
||||
{
|
||||
$res = Macaddresses::addSeparator("0005313B9080", ".", 4);
|
||||
$this->assertSame("0005.313B.9080", $res);
|
||||
}
|
||||
|
||||
public function test_addSeparator_4()
|
||||
public function testAddSeparator4()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Macaddresses::addSeparator("INVALID", ".", 4);
|
||||
}
|
||||
|
||||
public function test_removeSeparator_1()
|
||||
public function testRemoveSeparator1()
|
||||
{
|
||||
$res = Macaddresses::removeSeparator("de:ad:be:af:aa:bb");
|
||||
$this->assertSame("deadbeafaabb", $res);
|
||||
}
|
||||
|
||||
public function test_removeSeparator_2()
|
||||
public function testRemoveSeparator2()
|
||||
{
|
||||
$res = Macaddresses::removeSeparator("de-ad-be-af-aa-bb");
|
||||
$this->assertSame("deadbeafaabb", $res);
|
||||
}
|
||||
|
||||
public function test_removeSeparator_3()
|
||||
public function testRemoveSeparator3()
|
||||
{
|
||||
$res = Macaddresses::removeSeparator("dead.beaf.aabb");
|
||||
$this->assertSame("deadbeafaabb", $res);
|
||||
}
|
||||
|
||||
public function test_removeSeparator_4()
|
||||
public function testRemoveSeparator4()
|
||||
{
|
||||
$res = Macaddresses::removeSeparator("deadbeafaabb");
|
||||
$this->assertSame("deadbeafaabb", $res);
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Mail;
|
||||
|
||||
/** Test the Mail.php file */
|
||||
/**
|
||||
* Test the Mail.php file
|
||||
*/
|
||||
class MailTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSetBodyText1()
|
||||
@@ -91,58 +94,59 @@ class MailTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$mail = new Mail();
|
||||
$res = $mail->convertPeopleToArray("toto toto <toto@toto.com>");
|
||||
$this->assertSame($res, array (array ("name" => "toto toto",
|
||||
"mail" => "toto@toto.com")));
|
||||
$this->assertSame($res, [["name" => "toto toto",
|
||||
"mail" => "toto@toto.com"]]);
|
||||
}
|
||||
|
||||
public function testConvertPeopleToArray2()
|
||||
{
|
||||
$mail = new Mail();
|
||||
$res = $mail->convertPeopleToArray("<toto@toto.com>");
|
||||
$this->assertSame($res, array (array ("name" => "",
|
||||
"mail" => "toto@toto.com")));
|
||||
$this->assertSame($res, [["name" => "",
|
||||
"mail" => "toto@toto.com"]]);
|
||||
}
|
||||
|
||||
public function testConvertPeopleToArray3()
|
||||
{
|
||||
$mail = new Mail();
|
||||
$res = $mail->convertPeopleToArray("toto@toto.com,titi@titi.com");
|
||||
$this->assertSame($res, array (array ("name" => "",
|
||||
"mail" => "toto@toto.com"),
|
||||
array ("name" => "",
|
||||
"mail" => "titi@titi.com")));
|
||||
$this->assertSame($res, [["name" => "",
|
||||
"mail" => "toto@toto.com"],
|
||||
["name" => "",
|
||||
"mail" => "titi@titi.com"]]);
|
||||
}
|
||||
|
||||
public function testConvertPeopleToArray4()
|
||||
{
|
||||
$mail = new Mail();
|
||||
$res = $mail->convertPeopleToArray("toto@toto.com");
|
||||
$this->assertSame($res, array (array ("name" => "",
|
||||
"mail" => "toto@toto.com")));
|
||||
$this->assertSame($res, [["name" => "",
|
||||
"mail" => "toto@toto.com"]]);
|
||||
}
|
||||
|
||||
public function testConvertPeopleToArray5()
|
||||
{
|
||||
$mail = new Mail();
|
||||
$res = $mail->convertPeopleToArray(" <toto@toto.com> , <titi@titi.com>");
|
||||
$this->assertSame($res, array (array ("name" => "",
|
||||
"mail" => "toto@toto.com"),
|
||||
array ("name" => "",
|
||||
"mail" => "titi@titi.com")));
|
||||
$this->assertSame($res, [["name" => "",
|
||||
"mail" => "toto@toto.com"],
|
||||
["name" => "",
|
||||
"mail" => "titi@titi.com"]]);
|
||||
}
|
||||
|
||||
public function testConvertPeopleToArray6()
|
||||
{
|
||||
$mail = new Mail();
|
||||
$res = $mail->convertPeopleToArray("ToTo <toto@toto.com> , <titi@titi.com>");
|
||||
$this->assertSame($res, array (array ("name" => "ToTo",
|
||||
"mail" => "toto@toto.com"),
|
||||
array ("name" => "",
|
||||
"mail" => "titi@titi.com")));
|
||||
$this->assertSame($res, [["name" => "ToTo",
|
||||
"mail" => "toto@toto.com"],
|
||||
["name" => "",
|
||||
"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()
|
||||
{
|
||||
$mail = new Mail();
|
||||
@@ -190,8 +194,8 @@ http://www.nltk.org/nltk_data/
|
||||
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"],
|
||||
["Delivered-To" => "dominique@fournier38.fr\n"],
|
||||
["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"],
|
||||
|
||||
|
||||
));
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Markdown;
|
||||
|
||||
/** Test the Markdown.php file */
|
||||
/**
|
||||
* Test the Markdown.php file
|
||||
*/
|
||||
class MarkdownTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// TitleSeText
|
||||
// TitleSeText
|
||||
public function testTitleSeText1()
|
||||
{
|
||||
$this->expectOutputString("<h1>test</h1>");
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Outputdl;
|
||||
|
||||
/** Test the Outputdl.php file */
|
||||
/**
|
||||
* Test the Outputdl.php file
|
||||
*/
|
||||
class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_outputdl_init()
|
||||
public function testOutputdlInit()
|
||||
{
|
||||
exec("rm -f /tmp/testDFWoutputDL*");
|
||||
file_put_contents(
|
||||
@@ -27,9 +30,9 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
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();
|
||||
$this->expectOutputString(str_repeat(
|
||||
"1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\n",
|
||||
@@ -38,18 +41,18 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
$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->downloadFile("/tmp/testDFWoutputDL");
|
||||
$res = $outputdl->headers();
|
||||
$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->resumeAllow(false);
|
||||
$outputdl->downloadFile("/tmp/testDFWoutputDL");
|
||||
@@ -57,9 +60,9 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
$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();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=3-9";
|
||||
$this->expectOutputString("4567890");
|
||||
@@ -67,9 +70,9 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
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();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=3-";
|
||||
$this->expectOutputString(substr(str_repeat(
|
||||
@@ -80,9 +83,9 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
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();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=0-";
|
||||
$this->expectOutputString(str_repeat(
|
||||
@@ -93,9 +96,9 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
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();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=-5";
|
||||
$this->expectOutputString("wxyz\n");
|
||||
@@ -103,9 +106,9 @@ class OutputdlTest extends \PHPUnit_Framework_TestCase
|
||||
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();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=0-3,6-9";
|
||||
$this->expectOutputString("--Qm91bmRhcnk=\r
|
||||
@@ -124,9 +127,9 @@ Content-Type: application/octet-stream\r
|
||||
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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=99999-";
|
||||
@@ -134,9 +137,9 @@ Content-Type: application/octet-stream\r
|
||||
$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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=9-3";
|
||||
@@ -144,9 +147,9 @@ Content-Type: application/octet-stream\r
|
||||
$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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=9-999999";
|
||||
@@ -154,9 +157,9 @@ Content-Type: application/octet-stream\r
|
||||
$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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$_SERVER["HTTP_RANGE"] = "bytes=-";
|
||||
@@ -164,9 +167,9 @@ Content-Type: application/octet-stream\r
|
||||
$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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$outputdl->base("/tmp");
|
||||
@@ -177,9 +180,9 @@ Content-Type: application/octet-stream\r
|
||||
$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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$outputdl->base("/tmp");
|
||||
@@ -191,9 +194,9 @@ Content-Type: application/octet-stream\r
|
||||
$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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$outputdl->base("/tmp");
|
||||
@@ -205,9 +208,9 @@ Content-Type: application/octet-stream\r
|
||||
$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"]);
|
||||
$outputdl = new Outputdl();
|
||||
$outputdl->base("/tmp");
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Outputhtml;
|
||||
|
||||
/** Test the Outputhtml.php file */
|
||||
/**
|
||||
* Test the Outputhtml.php file
|
||||
*/
|
||||
class OutputhtmlTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** Entry null */
|
||||
/**
|
||||
* Entry null
|
||||
*/
|
||||
public function testlayout1()
|
||||
{
|
||||
$this->expectOutputRegex("#<body>\s+</body>#");
|
||||
@@ -58,7 +63,7 @@ class OutputhtmlTest extends \PHPUnit_Framework_TestCase
|
||||
</body>
|
||||
</html>\n");
|
||||
$output = new Outputhtml();
|
||||
$variable = array ("var" => "VARIABLE");
|
||||
$variable = ["var" => "VARIABLE"];
|
||||
$output->out(
|
||||
"data",
|
||||
"title",
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Outputjson;
|
||||
|
||||
/** Test the Outputjson.php file */
|
||||
/**
|
||||
* Test the Outputjson.php file
|
||||
*/
|
||||
class OutputjsonTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** Entry null */
|
||||
/**
|
||||
* Entry null
|
||||
*/
|
||||
public function testoutputjson1()
|
||||
{
|
||||
$this->expectOutputString("\"\"");
|
||||
@@ -21,7 +26,9 @@ class OutputjsonTest extends \PHPUnit_Framework_TestCase
|
||||
$output->out("");
|
||||
}
|
||||
|
||||
/** Entry string */
|
||||
/**
|
||||
* Entry string
|
||||
*/
|
||||
public function testoutputjson2()
|
||||
{
|
||||
$this->expectOutputString("\"string\"");
|
||||
@@ -29,11 +36,13 @@ class OutputjsonTest extends \PHPUnit_Framework_TestCase
|
||||
$output->out("string");
|
||||
}
|
||||
|
||||
/** Entry array */
|
||||
/**
|
||||
* Entry array
|
||||
*/
|
||||
public function testoutputjson3()
|
||||
{
|
||||
$this->expectOutputString("[1,2,3]");
|
||||
$output = new Outputjson();
|
||||
$output->out(array (1,2,3));
|
||||
$output->out([1,2,3]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,66 +1,68 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Password;
|
||||
|
||||
/** Test the Password class
|
||||
*/
|
||||
/**
|
||||
* Test the Password class
|
||||
*/
|
||||
class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_cryptPasswd_1()
|
||||
public function testCryptPasswd1()
|
||||
{
|
||||
$res = Password::cryptPasswd("AAA");
|
||||
$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");
|
||||
echo "RES1=$res1\n";
|
||||
$res2 = Password::cryptPasswd("AAA");
|
||||
echo "RES2=$res2\n";
|
||||
$res3 = Password::cryptPasswd("AAA");
|
||||
echo "RES3=$res3\n";
|
||||
$this->assertSame(count(array_unique(array ($res1, $res2, $res3))), 3);
|
||||
// Three passwords : each must have a different result
|
||||
$this->assertSame(count(array_unique([$res1, $res2, $res3])), 3);
|
||||
// Three passwords : each must have a different result
|
||||
}
|
||||
|
||||
public function test_cryptPasswd_3()
|
||||
public function testCryptPasswd3()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::cryptPasswd(false);
|
||||
}
|
||||
|
||||
public function test_cryptPassword_MYSQL()
|
||||
public function testCryptPasswordMYSQL()
|
||||
{
|
||||
$password = new password();
|
||||
$res = $password->cryptPassword("AAA", "MYSQL");
|
||||
$this->assertSame($res, "*5AF9D0EA5F6406FB0EDD0507F81C1D5CEBE8AC9C");
|
||||
}
|
||||
|
||||
public function test_cryptPassword_CRYPT_STD_DES()
|
||||
public function testCryptPasswordCRYPTSTDDES()
|
||||
{
|
||||
$password = new password();
|
||||
$res = $password->cryptPassword("AAA", "CRYPT_STD_DES");
|
||||
$this->assertSame(strlen($res), 13);
|
||||
}
|
||||
|
||||
public function test_cryptPassword_CRYPT_EXT_DES()
|
||||
public function testCryptPasswordCRYPTEXTDES()
|
||||
{
|
||||
$password = new password();
|
||||
$res = $password->cryptPassword("AAA", "CRYPT_EXT_DES");
|
||||
$this->assertSame(strlen($res), 13);
|
||||
}
|
||||
|
||||
public function test_cryptPassword_CRYPT_MD5()
|
||||
public function testCryptPasswordCRYPTMD5()
|
||||
{
|
||||
$password = new password();
|
||||
$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();
|
||||
$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();
|
||||
$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();
|
||||
$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();
|
||||
$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();
|
||||
$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();
|
||||
$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();
|
||||
$password = new password();
|
||||
$res = $password->cryptPassword("AAA", "UNKNOWN");
|
||||
}
|
||||
|
||||
public function test_checkPassword_1()
|
||||
public function testCheckPassword1()
|
||||
{
|
||||
$res = Password::checkPassword("AAA", "AAA");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_checkPassword_2()
|
||||
public function testCheckPassword2()
|
||||
{
|
||||
$crypt = Password::cryptPasswd("AAA");
|
||||
$res = Password::checkPassword("AAA", $crypt);
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_checkPassword_3()
|
||||
public function testCheckPassword3()
|
||||
{
|
||||
$res = Password::checkPassword("AAA", Password::cryptPasswd("BBB"));
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_checkPassword_4()
|
||||
public function testCheckPassword4()
|
||||
{
|
||||
$res = Password::checkPassword(
|
||||
"AAA",
|
||||
@@ -165,7 +167,7 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_checkPassword_invalid1()
|
||||
public function testCheckPasswordInvalid1()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::checkPassword(
|
||||
@@ -174,74 +176,74 @@ class PasswordTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_checkPassword_invalid2()
|
||||
public function testCheckPasswordInvalid2()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::checkPassword("AAA", false);
|
||||
}
|
||||
|
||||
public function test_generateASCII_defaultsize()
|
||||
public function testGenerateASCIIDefaultsize()
|
||||
{
|
||||
$res = Password::generateASCII();
|
||||
$this->assertSame(strlen($res), 12);
|
||||
}
|
||||
|
||||
public function test_generateASCII_toobig()
|
||||
public function testGenerateASCIIToobig()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::generateASCII(112);
|
||||
}
|
||||
|
||||
public function test_generateASCII_toosmall()
|
||||
public function testGenerateASCIIToosmall()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::generateASCII(0);
|
||||
}
|
||||
|
||||
public function test_generateAlphanum_defaultsize()
|
||||
public function testGenerateAlphanumDefaultsize()
|
||||
{
|
||||
$res = Password::generateAlphanum();
|
||||
$this->assertSame(strlen($res), 12);
|
||||
}
|
||||
|
||||
public function test_generateAlphanum_toobig()
|
||||
public function testGenerateAlphanumToobig()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::generateAlphanum(112);
|
||||
}
|
||||
|
||||
public function test_generateAlphanum_toosmall()
|
||||
public function testGenerateAlphanumToosmall()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::generateAlphanum(0);
|
||||
}
|
||||
|
||||
public function test_generateAlphabetical_defaultsize()
|
||||
public function testGenerateAlphabeticalDefaultsize()
|
||||
{
|
||||
$res = Password::generateAlphabetical();
|
||||
$this->assertSame(strlen($res), 12);
|
||||
}
|
||||
|
||||
public function test_generateAlphabetical_toobig()
|
||||
public function testGenerateAlphabeticalToobig()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::generateAlphabetical(112);
|
||||
}
|
||||
|
||||
public function test_generateAlphabetical_toosmall()
|
||||
public function testGenerateAlphabeticalToosmall()
|
||||
{
|
||||
$this->expectException();
|
||||
$res = Password::generateAlphabetical(0);
|
||||
}
|
||||
|
||||
public function test_listMethods_1()
|
||||
public function testListMethods1()
|
||||
{
|
||||
$password = new password();
|
||||
$res = $password->listMethods();
|
||||
$this->assertSame(count($res) > 7, true);
|
||||
}
|
||||
|
||||
public function test_salt_1()
|
||||
public function testSalt1()
|
||||
{
|
||||
$password = new password();
|
||||
$res = $password->salt();
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Queue;
|
||||
|
||||
/** Test the Queue.php file */
|
||||
/**
|
||||
* Test the Queue.php file
|
||||
*/
|
||||
class QueueTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test()
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Queuefile;
|
||||
|
||||
/** Test the Queuefile.php file */
|
||||
/**
|
||||
* Test the Queuefile.php file
|
||||
*/
|
||||
class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_clean()
|
||||
public function testClean()
|
||||
{
|
||||
if (file_exists("/tmp/queuefileTest/queuefileTest.json")) {
|
||||
unlink("/tmp/queuefileTest/queuefileTest.json");
|
||||
}
|
||||
}
|
||||
|
||||
public function test_add1()
|
||||
public function testAdd1()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -28,7 +31,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(true, is_object($res));
|
||||
}
|
||||
|
||||
public function test_count1()
|
||||
public function testCount1()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -36,7 +39,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(1, $res);
|
||||
}
|
||||
|
||||
public function test_add2()
|
||||
public function testAdd2()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -44,7 +47,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(true, is_object($res));
|
||||
}
|
||||
|
||||
public function test_count2()
|
||||
public function testCount2()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -52,7 +55,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(2, $res);
|
||||
}
|
||||
|
||||
public function test_getFirst1()
|
||||
public function testGetFirst1()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -60,7 +63,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("test1", $res);
|
||||
}
|
||||
|
||||
public function test_getLast1()
|
||||
public function testGetLast1()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -68,7 +71,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame("test2", $res);
|
||||
}
|
||||
|
||||
public function test_getRange1()
|
||||
public function testGetRange1()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -76,7 +79,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(["test2"], $res);
|
||||
}
|
||||
|
||||
public function test_getRange2()
|
||||
public function testGetRange2()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -84,7 +87,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(["test1", "test2"], $res);
|
||||
}
|
||||
|
||||
public function test_getRange3()
|
||||
public function testGetRange3()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -92,7 +95,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $queuefile->getRange(0, 3);
|
||||
}
|
||||
|
||||
public function test_getAll1()
|
||||
public function testGetAll1()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$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
|
||||
public function test_getAll2()
|
||||
public function testGetAll2()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -109,7 +112,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(true, is_object($res));
|
||||
}
|
||||
|
||||
public function test_count3()
|
||||
public function testCount3()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -117,7 +120,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(0, $res);
|
||||
}
|
||||
|
||||
public function test_getAll3()
|
||||
public function testGetAll3()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -125,7 +128,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame([], $res);
|
||||
}
|
||||
|
||||
public function test_getFirst2()
|
||||
public function testGetFirst2()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
@@ -133,7 +136,7 @@ class QueuefileTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(null, $res);
|
||||
}
|
||||
|
||||
public function test_getLast2()
|
||||
public function testGetLast2()
|
||||
{
|
||||
$queuefile = new Queuefile();
|
||||
$queuefile->connect("file:///tmp/queuefileTest/queuefileTest.json");
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Ratelimit;
|
||||
|
||||
/** Test the Ratelimit.php file */
|
||||
/**
|
||||
* Test the Ratelimit.php file
|
||||
*/
|
||||
class RatelimitTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_ratelimit0()
|
||||
public function testRatelimit0()
|
||||
{
|
||||
$ratelimit = new Ratelimit();
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Ratelimitfile;
|
||||
|
||||
/** Test the Ratelimitfile.php file */
|
||||
/**
|
||||
* Test the Ratelimitfile.php file
|
||||
*/
|
||||
class RatelimitfileTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testRatelimitfile0()
|
||||
@@ -20,7 +23,7 @@ class RatelimitfileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRatelimitfile1()
|
||||
{
|
||||
// Create one non ratelimited entry
|
||||
// Create one non ratelimited entry
|
||||
$ratelimitfile = new Ratelimitfile();
|
||||
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
||||
$res = $ratelimitfile->set("TOTO");
|
||||
@@ -29,7 +32,7 @@ class RatelimitfileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRatelimitfile2()
|
||||
{
|
||||
// Too much entries
|
||||
// Too much entries
|
||||
$ratelimitfile = new Ratelimitfile();
|
||||
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
||||
$ratelimitfile->set("TOTO");
|
||||
@@ -47,7 +50,7 @@ class RatelimitfileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRatelimitfile3()
|
||||
{
|
||||
// Del the ratelimited entry
|
||||
// Del the ratelimited entry
|
||||
$ratelimitfile = new Ratelimitfile();
|
||||
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
||||
$res = $ratelimitfile->del("TOTO");
|
||||
@@ -56,7 +59,7 @@ class RatelimitfileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRatelimitfile4()
|
||||
{
|
||||
// Create one non ratelimited entry
|
||||
// Create one non ratelimited entry
|
||||
$ratelimitfile = new Ratelimitfile();
|
||||
$ratelimitfile->storageDir = "/tmp/testDFWratelimit";
|
||||
$res = $ratelimitfile->set("TOTO");
|
||||
@@ -65,7 +68,7 @@ class RatelimitfileTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testRatelimitfile5()
|
||||
{
|
||||
// Clean expired entries
|
||||
// Clean expired entries
|
||||
sleep(2);
|
||||
$ratelimitfile = new Ratelimitfile();
|
||||
$ratelimitfile->unittime = 1;
|
||||
|
||||
@@ -1,20 +1,24 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Rest;
|
||||
|
||||
/** Test the domframework REST part */
|
||||
/**
|
||||
* Test the domframework REST part
|
||||
*/
|
||||
class RestTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** No param, JSON by default
|
||||
*/
|
||||
/**
|
||||
* No param, JSON by default
|
||||
*/
|
||||
public function testChooseType1()
|
||||
{
|
||||
$rest = new Rest();
|
||||
@@ -22,44 +26,51 @@ class RestTest extends \PHPUnit_Framework_TestCase
|
||||
$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()
|
||||
{
|
||||
$rest = new Rest();
|
||||
$rest->allowedtypes = array ("xml", "csv");
|
||||
$rest->allowedtypes = ["xml", "csv"];
|
||||
$res = $rest->chooseType();
|
||||
$this->assertSame($res, "xml");
|
||||
}
|
||||
|
||||
/** Choose by the user specification : exact match
|
||||
*/
|
||||
/**
|
||||
* Choose by the user specification : exact match
|
||||
*/
|
||||
public function testChooseType3()
|
||||
{
|
||||
$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();
|
||||
$this->assertSame($res, "xml");
|
||||
}
|
||||
|
||||
/** Choose by the user specification : generic match
|
||||
*/
|
||||
/**
|
||||
* Choose by the user specification : generic match
|
||||
*/
|
||||
public function testChooseType4()
|
||||
{
|
||||
$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();
|
||||
$this->assertSame($res, "json");
|
||||
}
|
||||
|
||||
/** Choose by the user specification : generic match with limited allowed
|
||||
* types
|
||||
*/
|
||||
/**
|
||||
* Choose by the user specification : generic match with limited allowed
|
||||
* types
|
||||
*/
|
||||
public function testChooseType5()
|
||||
{
|
||||
$rest = new Rest();
|
||||
$rest->allowedtypes = array ("xml", "csv");
|
||||
$_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,*/*;q=0.8";
|
||||
$rest->allowedtypes = ["xml", "csv"];
|
||||
$_SERVER["HTTP_ACCEPT"] = "text/html;q=0.9,
|
||||
*/*;q=0.8";
|
||||
$res = $rest->chooseType();
|
||||
$this->assertSame($res, "xml");
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Robotstxt;
|
||||
|
||||
/** Test the Robotstxt file
|
||||
*/
|
||||
/**
|
||||
* Test the Robotstxt file
|
||||
*/
|
||||
class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Empty Robots
|
||||
// Empty Robots
|
||||
public function testConstruct1()
|
||||
{
|
||||
$robotstxt = new Robotstxt("", "domsearch");
|
||||
@@ -25,13 +27,13 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$robotstxt = new Robotstxt("", "domsearch");
|
||||
$res = $robotstxt->disallow();
|
||||
$this->assertSame($res, array ());
|
||||
$this->assertSame($res, []);
|
||||
}
|
||||
public function testConstruct3()
|
||||
{
|
||||
$robotstxt = new Robotstxt("", "domsearch");
|
||||
$res = $robotstxt->sitemaps();
|
||||
$this->assertSame($res, array ());
|
||||
$this->assertSame($res, []);
|
||||
}
|
||||
public function testConstruct4()
|
||||
{
|
||||
@@ -259,7 +261,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
// Tests like http://www.robotstxt.org/norobots-rfc.txt
|
||||
public function testRfcUnhipbot1()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -279,7 +281,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/"),
|
||||
false
|
||||
@@ -287,7 +289,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot2()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -307,7 +309,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/index.html"),
|
||||
false
|
||||
@@ -315,7 +317,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot3()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -335,7 +337,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/robots.txt"),
|
||||
true
|
||||
@@ -343,7 +345,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot4()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -363,7 +365,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/server.html"),
|
||||
false
|
||||
@@ -371,7 +373,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot5()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -391,7 +393,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/fast.html"),
|
||||
false
|
||||
@@ -399,7 +401,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot6()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -419,7 +421,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/slow.html"),
|
||||
false
|
||||
@@ -427,7 +429,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot7()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -447,7 +449,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/orgo.gif"),
|
||||
false
|
||||
@@ -455,7 +457,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot8()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -475,7 +477,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/about.html"),
|
||||
false
|
||||
@@ -483,7 +485,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot9()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -503,7 +505,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/plans.html"),
|
||||
false
|
||||
@@ -511,7 +513,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot10()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -531,7 +533,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~jim/jim.html"),
|
||||
false
|
||||
@@ -539,7 +541,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcUnhipbot11()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -559,7 +561,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"unhipbot"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~mak/mak.html"),
|
||||
false
|
||||
@@ -567,7 +569,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler1()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -587,7 +589,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/"),
|
||||
true
|
||||
@@ -595,7 +597,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler2()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -615,7 +617,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/index.html"),
|
||||
true
|
||||
@@ -623,7 +625,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler3()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -643,7 +645,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/robots.txt"),
|
||||
true
|
||||
@@ -651,7 +653,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler4()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -671,7 +673,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/server.html"),
|
||||
true
|
||||
@@ -679,7 +681,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler5()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -699,7 +701,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/fast.html"),
|
||||
true
|
||||
@@ -707,7 +709,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler6()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -727,7 +729,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/slow.html"),
|
||||
true
|
||||
@@ -735,7 +737,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler7()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -755,7 +757,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/orgo.gif"),
|
||||
true
|
||||
@@ -763,7 +765,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler8()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -783,7 +785,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/about.html"),
|
||||
true
|
||||
@@ -791,7 +793,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler9()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -811,7 +813,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/plans.html"),
|
||||
true
|
||||
@@ -819,7 +821,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler10()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -839,7 +841,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~jim/jim.html"),
|
||||
true
|
||||
@@ -847,7 +849,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcWebcrawler11()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -867,7 +869,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"webcrawler"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~mak/mak.html"),
|
||||
true
|
||||
@@ -875,7 +877,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite1()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -895,7 +897,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/"),
|
||||
true
|
||||
@@ -903,7 +905,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite2()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -923,7 +925,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/index.html"),
|
||||
true
|
||||
@@ -931,7 +933,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite3()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -951,7 +953,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/robots.txt"),
|
||||
true
|
||||
@@ -959,7 +961,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite4()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -979,7 +981,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/server.html"),
|
||||
true
|
||||
@@ -987,7 +989,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite5()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1007,7 +1009,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/fast.html"),
|
||||
true
|
||||
@@ -1015,7 +1017,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite6()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1035,7 +1037,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/slow.html"),
|
||||
true
|
||||
@@ -1043,7 +1045,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite7()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1063,7 +1065,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/orgo.gif"),
|
||||
true
|
||||
@@ -1071,7 +1073,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite8()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1091,7 +1093,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/about.html"),
|
||||
true
|
||||
@@ -1099,7 +1101,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite9()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1119,7 +1121,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/plans.html"),
|
||||
true
|
||||
@@ -1127,7 +1129,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite10()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1147,7 +1149,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~jim/jim.html"),
|
||||
true
|
||||
@@ -1155,7 +1157,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcExcite11()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1175,7 +1177,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"excite"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~mak/mak.html"),
|
||||
true
|
||||
@@ -1183,7 +1185,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther1()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1203,12 +1205,12 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame($robotstxt->URLAllow("http://www.fict.org/"), false);
|
||||
}
|
||||
public function testRfcOther2()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1228,7 +1230,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/index.html"),
|
||||
false
|
||||
@@ -1236,7 +1238,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther3()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1256,7 +1258,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/robots.txt"),
|
||||
true
|
||||
@@ -1264,7 +1266,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther4()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1284,7 +1286,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/server.html"),
|
||||
true
|
||||
@@ -1292,7 +1294,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther5()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1312,7 +1314,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/fast.html"),
|
||||
true
|
||||
@@ -1320,7 +1322,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther6()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1340,7 +1342,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/services/slow.html"),
|
||||
true
|
||||
@@ -1348,7 +1350,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther7()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1368,7 +1370,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/orgo.gif"),
|
||||
false
|
||||
@@ -1376,7 +1378,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther8()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1396,7 +1398,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/about.html"),
|
||||
true
|
||||
@@ -1404,7 +1406,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther9()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1424,7 +1426,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/org/plans.html"),
|
||||
false
|
||||
@@ -1432,7 +1434,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther10()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1452,7 +1454,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~jim/jim.html"),
|
||||
false
|
||||
@@ -1460,7 +1462,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
public function testRfcOther11()
|
||||
{
|
||||
// {{{
|
||||
// {{{
|
||||
$robotstxt = new Robotstxt(
|
||||
"# /robots.txt for http://www.fict.org/
|
||||
# comments to webmaster@fict.org
|
||||
@@ -1480,7 +1482,7 @@ class RobotstxtTest extends \PHPUnit_Framework_TestCase
|
||||
Disallow: /",
|
||||
"other"
|
||||
);
|
||||
// }}}
|
||||
// }}}
|
||||
$this->assertSame(
|
||||
$robotstxt->URLAllow("http://www.fict.org/~mak/mak.html"),
|
||||
true
|
||||
|
||||
@@ -1,29 +1,36 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Route;
|
||||
|
||||
/** Test the Route.php file */
|
||||
/**
|
||||
* Test the Route.php file
|
||||
*/
|
||||
class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/// RELATIVE ///
|
||||
/** Entry null */
|
||||
public function test_baseURL_1_relative()
|
||||
/// RELATIVE ///
|
||||
/**
|
||||
* Entry null
|
||||
*/
|
||||
public function testBaseURL1Relative()
|
||||
{
|
||||
$route = new Route();
|
||||
$route->baseURL();
|
||||
$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_PORT"] = "80";
|
||||
@@ -33,8 +40,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -46,8 +55,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -58,8 +69,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "888";
|
||||
@@ -70,8 +83,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -82,8 +97,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "443";
|
||||
@@ -94,8 +111,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -106,8 +125,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "888";
|
||||
@@ -119,16 +140,20 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/// ABSOLUTE ///
|
||||
/** Entry null */
|
||||
public function test_baseURL_1_absolute()
|
||||
/**
|
||||
* Entry null
|
||||
*/
|
||||
public function testBaseURL1Absolute()
|
||||
{
|
||||
$route = new Route();
|
||||
$route->baseURL(false, true);
|
||||
$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_PORT"] = "80";
|
||||
@@ -138,8 +163,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -151,8 +178,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -163,8 +192,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "888";
|
||||
@@ -175,8 +206,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -187,8 +220,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "443";
|
||||
@@ -199,8 +234,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -211,8 +248,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "888";
|
||||
@@ -224,8 +263,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/// REQUESTURL ///
|
||||
/** Port 80 and HTTP requestURL */
|
||||
public function test_requestURL_2_direct()
|
||||
/**
|
||||
* Port 80 and HTTP requestURL
|
||||
*/
|
||||
public function testRequestURL2Direct()
|
||||
{
|
||||
unset($_SERVER["HTTPS"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -237,8 +278,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "443";
|
||||
@@ -250,8 +293,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -263,8 +308,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "888";
|
||||
@@ -276,8 +323,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -289,8 +338,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "443";
|
||||
@@ -302,8 +353,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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"]);
|
||||
$_SERVER["SERVER_NAME"] = "localhost";
|
||||
@@ -315,8 +368,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$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_PORT"] = "888";
|
||||
@@ -328,8 +383,10 @@ class RouteTest extends \PHPUnit_Framework_TestCase
|
||||
$this->expectOutputString("var=1");
|
||||
}
|
||||
|
||||
/** Ratelimiting in errors */
|
||||
public function test_errorRateLimit1()
|
||||
/**
|
||||
* Ratelimiting in errors
|
||||
*/
|
||||
public function testErrorRateLimit1()
|
||||
{
|
||||
$route = new Route();
|
||||
$route->ratelimiter->storageDir = "/tmp/ratelimit-" . time();
|
||||
|
||||
@@ -1,29 +1,32 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Rss;
|
||||
|
||||
/** Test the RSS */
|
||||
/**
|
||||
* Test the RSS
|
||||
*/
|
||||
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");
|
||||
$rss = new Rss();
|
||||
$res = $rss->asXML();
|
||||
}
|
||||
|
||||
public function test_functional1()
|
||||
public function testFunctional1()
|
||||
{
|
||||
// Functionnal 1
|
||||
// Functionnal 1
|
||||
$rss = new Rss();
|
||||
$rss->title("Global Title")
|
||||
->link("http://localhost")
|
||||
@@ -60,9 +63,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
|
||||
");
|
||||
}
|
||||
|
||||
public function test_error1()
|
||||
public function testError1()
|
||||
{
|
||||
// Missing global description
|
||||
// Missing global description
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
"No description is provided for this RSS"
|
||||
@@ -74,9 +77,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
|
||||
$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");
|
||||
$rss = new Rss();
|
||||
$rss->title("Global Title")
|
||||
@@ -85,9 +88,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
|
||||
$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");
|
||||
$rss = new Rss();
|
||||
$rss->link("http://localhost")
|
||||
@@ -96,9 +99,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $rss->asXML();
|
||||
}
|
||||
|
||||
public function test_error4()
|
||||
public function testError4()
|
||||
{
|
||||
// Invalid date provided
|
||||
// Invalid date provided
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
"lastBuildDate provided to RSS is not a valid date"
|
||||
@@ -112,9 +115,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $rss->asXML();
|
||||
}
|
||||
|
||||
public function test_itemError1()
|
||||
public function testItemError1()
|
||||
{
|
||||
// Empty Item provided
|
||||
// Empty Item provided
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
"No title nor description defined in the RSS item"
|
||||
@@ -129,9 +132,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $rss->asXML();
|
||||
}
|
||||
|
||||
public function test_itemError2()
|
||||
public function testItemError2()
|
||||
{
|
||||
// Item without Title and Description
|
||||
// Item without Title and Description
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
"No title nor description defined in the RSS item"
|
||||
@@ -146,9 +149,9 @@ class RssTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $rss->asXML();
|
||||
}
|
||||
|
||||
public function test_itemError3()
|
||||
public function testItemError3()
|
||||
{
|
||||
// Item with invalid date
|
||||
// Item with invalid date
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
"pubDate provided to RSS Item is not a valid date"
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Sitemap;
|
||||
|
||||
/** Test the Sitemap.php file
|
||||
*/
|
||||
/**
|
||||
* Test the Sitemap.php file
|
||||
*/
|
||||
class SitemapTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Empty Sitemap
|
||||
public function test_EmptySitemap_1()
|
||||
// Empty Sitemap
|
||||
public function testEmptySitemap1()
|
||||
{
|
||||
$sitemap = new Sitemap();
|
||||
$res = $sitemap->analyze("", "http://example.com");
|
||||
@@ -23,7 +25,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// Empty Sitemap
|
||||
public function test_EmptySitemap_2()
|
||||
public function testEmptySitemap2()
|
||||
{
|
||||
$sitemap = new Sitemap();
|
||||
$res = $sitemap->analyze(" ", "http://example.com");
|
||||
@@ -31,7 +33,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// Textual Sitemap
|
||||
public function test_TextualSitemap_1()
|
||||
public function testTextualSitemap1()
|
||||
{
|
||||
$sitemap = new Sitemap();
|
||||
$res = $sitemap->analyze("http://example.com", "http://example.com");
|
||||
@@ -41,7 +43,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
|
||||
"sitemaps" => []]
|
||||
);
|
||||
}
|
||||
public function test_TextualSitemap_2()
|
||||
public function testTextualSitemap2()
|
||||
{
|
||||
$sitemap = new Sitemap();
|
||||
$res = $sitemap->analyze(
|
||||
@@ -56,7 +58,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
// XML Sitemap
|
||||
public function test_XMLSitemap_1()
|
||||
public function testXMLSitemap1()
|
||||
{
|
||||
$sitemap = new Sitemap();
|
||||
$res = $sitemap->analyze(
|
||||
@@ -84,7 +86,7 @@ class SitemapTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function test_XMLSitemap_2()
|
||||
public function testXMLSitemap2()
|
||||
{
|
||||
$sitemap = new Sitemap();
|
||||
$res = $sitemap->analyze(
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Spfcheck;
|
||||
|
||||
/** Test the Spfcheck tools
|
||||
*/
|
||||
/**
|
||||
* Test the Spfcheck tools
|
||||
*/
|
||||
class SpfcheckTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_getRecords_NoSPF()
|
||||
public function testGetRecordsNoSPF()
|
||||
{
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
@@ -26,18 +28,18 @@ class SpfcheckTest extends \PHPUnit_Framework_TestCase
|
||||
$res = $spfcheck->getRecords("notfound.tester.fournier38.fr");
|
||||
}
|
||||
|
||||
public function test_getRecords_SPFReject()
|
||||
public function testGetRecordsSPFReject()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("reject.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("reject.spf.tester.fournier38.fr" =>
|
||||
array ("-all" => array ()))
|
||||
["reject.spf.tester.fournier38.fr" =>
|
||||
["-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_Loop()
|
||||
public function testGetRecordsLoop()
|
||||
{
|
||||
$this->expectException(
|
||||
"Exception",
|
||||
@@ -46,267 +48,267 @@ class SpfcheckTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
$spfcheck = new Spfcheck();
|
||||
$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();
|
||||
$res = $spfcheck->getRecords("includeempty.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("includeempty.spf.tester.fournier38.fr" =>
|
||||
array ("include:" => array (), "-all" => array ()))
|
||||
["includeempty.spf.tester.fournier38.fr" =>
|
||||
["include:" => [], "-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_Redirect_emptyRedirect()
|
||||
public function testGetRecordsRedirectEmptyRedirect()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("redirectempty.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("redirectempty.spf.tester.fournier38.fr" =>
|
||||
array ("redirect=" => array (), "-all" => array ()))
|
||||
["redirectempty.spf.tester.fournier38.fr" =>
|
||||
["redirect=" => [], "-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_MX_emptyMX()
|
||||
public function testGetRecordsMXEmptyMX()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("mx.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("mx.spf.tester.fournier38.fr" =>
|
||||
array ("mx" => array (), "-all" => array ()))
|
||||
["mx.spf.tester.fournier38.fr" =>
|
||||
["mx" => [], "-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_MX_validMX()
|
||||
public function testGetRecordsMXValidMX()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("mxvalid.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("mxvalid.spf.tester.fournier38.fr" => array (
|
||||
"mx:tester.fournier38.fr" => array (
|
||||
["mxvalid.spf.tester.fournier38.fr" => [
|
||||
"mx:tester.fournier38.fr" => [
|
||||
"2a01:e0a:2a7:9cd1::103",
|
||||
"2a01:e0a:392:ab60::206",
|
||||
"82.64.75.195",
|
||||
"82.66.67.64"),
|
||||
"-all" => array ()))
|
||||
"82.66.67.64"],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_A_emptyA()
|
||||
public function testGetRecordsAEmptyA()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("a.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("a.spf.tester.fournier38.fr" =>
|
||||
array ("a" => array (), "-all" => array ()))
|
||||
["a.spf.tester.fournier38.fr" =>
|
||||
["a" => [], "-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_A_validA()
|
||||
public function testGetRecordsAValidA()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("avalid.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("avalid.spf.tester.fournier38.fr" => array (
|
||||
"a:tester.fournier38.fr" => array (
|
||||
["avalid.spf.tester.fournier38.fr" => [
|
||||
"a:tester.fournier38.fr" => [
|
||||
"2a01:e0a:2a7:9cd1::100",
|
||||
"82.64.75.195",),
|
||||
"-all" => array ()))
|
||||
"82.64.75.195",],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_IP4_emptyIP4()
|
||||
public function testGetRecordsIP4EmptyIP4()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("ip4empty.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("ip4empty.spf.tester.fournier38.fr" => array (
|
||||
"ip4:" => array (),
|
||||
"-all" => array ()))
|
||||
["ip4empty.spf.tester.fournier38.fr" => [
|
||||
"ip4:" => [],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_IP4_invalidIP4()
|
||||
public function testGetRecordsIP4InvalidIP4()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("ip4invalid.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("ip4invalid.spf.tester.fournier38.fr" => array (
|
||||
"ip4:0::1" => array (),
|
||||
"-all" => array ()))
|
||||
["ip4invalid.spf.tester.fournier38.fr" => [
|
||||
"ip4:0::1" => [],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_IP4_validIP4()
|
||||
public function testGetRecordsIP4ValidIP4()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("ip4valid.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("ip4valid.spf.tester.fournier38.fr" => array (
|
||||
"ip4:192.168.1.1" => array ("192.168.1.1"),
|
||||
"-all" => array ()))
|
||||
["ip4valid.spf.tester.fournier38.fr" => [
|
||||
"ip4:192.168.1.1" => ["192.168.1.1"],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_IP6_emptyIP6()
|
||||
public function testGetRecordsIP6EmptyIP6()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("ip6empty.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("ip6empty.spf.tester.fournier38.fr" => array (
|
||||
"ip6:" => array (),
|
||||
"-all" => array ()))
|
||||
["ip6empty.spf.tester.fournier38.fr" => [
|
||||
"ip6:" => [],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_IP6_invalidIP6()
|
||||
public function testGetRecordsIP6InvalidIP6()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("ip6invalid.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("ip6invalid.spf.tester.fournier38.fr" => array (
|
||||
"ip6:192.168.1.1" => array (),
|
||||
"-all" => array ()))
|
||||
["ip6invalid.spf.tester.fournier38.fr" => [
|
||||
"ip6:192.168.1.1" => [],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_IP6_validIP6()
|
||||
public function testGetRecordsIP6ValidIP6()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("ip6valid.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("ip6valid.spf.tester.fournier38.fr" => array (
|
||||
"ip6:0::1" => array ("0::1"),
|
||||
"-all" => array ()))
|
||||
["ip6valid.spf.tester.fournier38.fr" => [
|
||||
"ip6:0::1" => ["0::1"],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_PTR()
|
||||
public function testGetRecordsPTR()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("ptrvalid.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("ptrvalid.spf.tester.fournier38.fr" => array (
|
||||
"ptr" => array (),
|
||||
"-all" => array ()))
|
||||
["ptrvalid.spf.tester.fournier38.fr" => [
|
||||
"ptr" => [],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_All_Multiple()
|
||||
public function testGetRecordsAllMultiple()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("allmultiple.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("allmultiple.spf.tester.fournier38.fr" => array (
|
||||
"+all" => array (),
|
||||
"-all" => array ()))
|
||||
["allmultiple.spf.tester.fournier38.fr" => [
|
||||
"+all" => [],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_All_NotEnd()
|
||||
public function testGetRecordsAllNotEnd()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("allnotend.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("allnotend.spf.tester.fournier38.fr" => array (
|
||||
"+all" => array (),
|
||||
"mx" => array ()))
|
||||
["allnotend.spf.tester.fournier38.fr" => [
|
||||
"+all" => [],
|
||||
"mx" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_All_NotSet()
|
||||
public function testGetRecordsAllNotSet()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("allnotset.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("allnotset.spf.tester.fournier38.fr" => array (
|
||||
"mx" => array ()))
|
||||
["allnotset.spf.tester.fournier38.fr" => [
|
||||
"mx" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_wideIPRange()
|
||||
public function testWideIPRange()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$spfcheck->getRecords("wide.spf.tester.fournier38.fr");
|
||||
$res = $spfcheck->getErrors();
|
||||
$this->assertSame(
|
||||
$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",
|
||||
"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();
|
||||
$res = $spfcheck->getRecords("plus.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("plus.spf.tester.fournier38.fr" => array (
|
||||
"+a" => array (),
|
||||
"+mx" => array (),
|
||||
"+ip4:178.33.236.5" => array ("178.33.236.5"),
|
||||
"-ip4:137.74.69.64" => array ("137.74.69.64"),
|
||||
"+ip4:51.254.45.81" => array ("51.254.45.81"),
|
||||
"-all" => array (),
|
||||
))
|
||||
["plus.spf.tester.fournier38.fr" => [
|
||||
"+a" => [],
|
||||
"+mx" => [],
|
||||
"+ip4:178.33.236.5" => ["178.33.236.5"],
|
||||
"-ip4:137.74.69.64" => ["137.74.69.64"],
|
||||
"+ip4:51.254.45.81" => ["51.254.45.81"],
|
||||
"-all" => [],
|
||||
]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_getRecords_Unknown()
|
||||
public function testGetRecordsUnknown()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->getRecords("unknown.spf.tester.fournier38.fr");
|
||||
$this->assertSame(
|
||||
$res,
|
||||
array ("unknown.spf.tester.fournier38.fr" => array (
|
||||
"unknown" => array (),
|
||||
"-all" => array ()))
|
||||
["unknown.spf.tester.fournier38.fr" => [
|
||||
"unknown" => [],
|
||||
"-all" => []]]
|
||||
);
|
||||
}
|
||||
|
||||
public function test_ipCheckToSPF_OK_inA()
|
||||
public function testIpCheckToSPFOKInA()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "178.33.236.5");
|
||||
$this->assertSame($res, "PASS");
|
||||
}
|
||||
|
||||
public function test_ipCheckToSPF_FAIL_inALL()
|
||||
public function testIpCheckToSPFFAILInALL()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5");
|
||||
$this->assertSame($res, "FAIL");
|
||||
}
|
||||
|
||||
public function test_ipCheckToSPF_OK_inALL()
|
||||
public function testIpCheckToSPFOKInALL()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "1.3.6.5");
|
||||
$this->assertSame($res, "FAIL");
|
||||
}
|
||||
|
||||
public function test_ipCheckToSPF_FAIL_inIP4()
|
||||
public function testIpCheckToSPFFAILInIP4()
|
||||
{
|
||||
$spfcheck = new Spfcheck();
|
||||
$res = $spfcheck->ipCheckToSPF("plus.spf.tester.fournier38.fr", "137.74.69.64");
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Sse;
|
||||
|
||||
/** Test the domframework Server-Sent Events part */
|
||||
/**
|
||||
* Test the domframework Server-Sent Events part
|
||||
*/
|
||||
class SseTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_loop_NOTDEFINED()
|
||||
public function testLoopNOTDEFINED()
|
||||
{
|
||||
$this->expectException("Exception");
|
||||
$sse = new Sse();
|
||||
$res = $sse->loop();
|
||||
}
|
||||
|
||||
public function test_loop_JUSTPING()
|
||||
public function testLoopJUSTPING()
|
||||
{
|
||||
$this->expectOutputString(str_repeat(": ping\n\n", 5));
|
||||
$sse = new Sse();
|
||||
@@ -32,7 +35,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
|
||||
$sse->loop();
|
||||
}
|
||||
|
||||
public function test_loop_SKIP_START()
|
||||
public function testLoopSKIPSTART()
|
||||
{
|
||||
$this->expectOutputString(str_repeat(": ping\n\n", 5));
|
||||
$sse = new Sse();
|
||||
@@ -45,7 +48,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
|
||||
$sse->loop();
|
||||
}
|
||||
|
||||
public function test_loop_DATA()
|
||||
public function testLoopDATA()
|
||||
{
|
||||
$this->expectOutputString(str_repeat(": ping\n\n", 4) .
|
||||
"data: WILL BE SEEN\n\n: ping\n\n");
|
||||
@@ -62,7 +65,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
|
||||
$sse->loop();
|
||||
}
|
||||
|
||||
public function test_loop_EVENTS()
|
||||
public function testLoopEVENTS()
|
||||
{
|
||||
$this->expectOutputString(str_repeat(": ping\n\n", 4) .
|
||||
"event: event1\ndata: WILL BE SEEN 1\n\n" .
|
||||
@@ -86,7 +89,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
|
||||
$sse->loop();
|
||||
}
|
||||
|
||||
public function test_loop_HandlersEvent()
|
||||
public function testLoopHandlersEvent()
|
||||
{
|
||||
$this->expectOutputString(str_repeat(": ping\n\n", 4) .
|
||||
"event: event1\ndata: will be seen 1\n\n" .
|
||||
@@ -116,7 +119,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
|
||||
$sse->loop();
|
||||
}
|
||||
|
||||
public function test_loop_HandlerDataonly()
|
||||
public function testLoopHandlerDataonly()
|
||||
{
|
||||
$this->expectOutputString(str_repeat(": ping\n\n", 4) .
|
||||
"data: will be seen 1\n\n" .
|
||||
@@ -139,7 +142,7 @@ class SseTest extends \PHPUnit_Framework_TestCase
|
||||
$sse->loop();
|
||||
}
|
||||
|
||||
public function test_loop_HandlerDataonlyWithParams()
|
||||
public function testLoopHandlerDataonlyWithParams()
|
||||
{
|
||||
$this->expectOutputString(str_repeat(": ping\n\n", 4) .
|
||||
"data: PREwill be seen 1POST\n\n" .
|
||||
|
||||
@@ -1,19 +1,22 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Tcpclient;
|
||||
|
||||
/** Test the TCP client */
|
||||
/**
|
||||
* Test the TCP client
|
||||
*/
|
||||
class TcpclientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_GoogleIPv4()
|
||||
public function testGoogleIPv4()
|
||||
{
|
||||
$tcpclient = new Tcpclient("www.google.fr", 80);
|
||||
$tcpclient->preferIPv4(true);
|
||||
@@ -31,7 +34,7 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
|
||||
$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->connect();
|
||||
@@ -48,7 +51,7 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
|
||||
$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->connect();
|
||||
@@ -66,7 +69,7 @@ class TcpclientTest extends \PHPUnit_Framework_TestCase
|
||||
$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->connect();
|
||||
|
||||
@@ -1,96 +1,99 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Userssql;
|
||||
|
||||
/** Test the Userssql.php file */
|
||||
/**
|
||||
* Test the Userssql.php file
|
||||
*/
|
||||
class UserssqlTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_clean()
|
||||
public function testClean()
|
||||
{
|
||||
@unlink("/tmp/database.db");
|
||||
}
|
||||
|
||||
public function test_initStorage()
|
||||
public function testInitStorage()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->initStorage();
|
||||
$this->assertSame($res, 0);
|
||||
}
|
||||
|
||||
public function test_listusers1()
|
||||
public function testListusers1()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->listusers();
|
||||
$this->assertSame($res, array ());
|
||||
$this->assertSame($res, []);
|
||||
}
|
||||
|
||||
public function test_adduser1()
|
||||
public function testAdduser1()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->adduser("toto@toto.com", "Toto", "Toto2");
|
||||
$this->assertSame($res, "toto@toto.com");
|
||||
}
|
||||
|
||||
public function test_listusers2()
|
||||
public function testListusers2()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->listusers();
|
||||
$this->assertSame($res, array (array ("email" => "toto@toto.com",
|
||||
$this->assertSame($res, [["email" => "toto@toto.com",
|
||||
"firstname" => "Toto",
|
||||
"lastname" => "Toto2")));
|
||||
"lastname" => "Toto2"]]);
|
||||
}
|
||||
|
||||
public function test_overwritepassword1()
|
||||
public function testOverwritepassword1()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->overwritepassword("toto@toto.com", "PassW0rd");
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
|
||||
public function test_checkValidPassword1()
|
||||
public function testCheckValidPassword1()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_checkValidPassword2()
|
||||
public function testCheckValidPassword2()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->checkValidPassword("toto@toto.com", "BAD PASSWD");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_changepassword1()
|
||||
public function testChangepassword1()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->changepassword("toto@toto.com", "PassW0rd", "NEW PASS!");
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
|
||||
public function test_checkValidPassword3()
|
||||
public function testCheckValidPassword3()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->checkValidPassword("toto@toto.com", "PassW0rd");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_checkValidPassword4()
|
||||
public function testCheckValidPassword4()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->checkValidPassword("toto@toto.com", "NEW PASS!");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_updateuser()
|
||||
public function testUpdateuser()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->updateuser(
|
||||
@@ -102,33 +105,33 @@ class UserssqlTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
|
||||
public function test_listusers3()
|
||||
public function testListusers3()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->listusers();
|
||||
$this->assertSame($res, array (array ("email" => "titi@titi.com",
|
||||
$this->assertSame($res, [["email" => "titi@titi.com",
|
||||
"firstname" => "titi",
|
||||
"lastname" => "titi2")));
|
||||
"lastname" => "titi2"]]);
|
||||
}
|
||||
|
||||
public function test_checkValidPassword5()
|
||||
public function testCheckValidPassword5()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->checkValidPassword("titi@titi.com", "NEW PASS!");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_deluser()
|
||||
public function testDeluser()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->deluser("titi@titi.com");
|
||||
$this->assertSame($res, 1);
|
||||
}
|
||||
|
||||
public function test_listusers4()
|
||||
public function testListusers4()
|
||||
{
|
||||
$userssql = new Userssql("sqlite:///tmp/database.db");
|
||||
$res = $userssql->listusers();
|
||||
$this->assertSame($res, array ());
|
||||
$this->assertSame($res, []);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Uuid;
|
||||
|
||||
/** Test the Uuid.php file */
|
||||
/**
|
||||
* Test the Uuid.php file
|
||||
*/
|
||||
class UuidTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_uuid1()
|
||||
public function testUuid1()
|
||||
{
|
||||
$res = Uuid::uuid4();
|
||||
$this->assertRegExp(36, strlen($res));
|
||||
}
|
||||
|
||||
public function test_uuid2()
|
||||
public function testUuid2()
|
||||
{
|
||||
$res = Uuid::uuid4();
|
||||
$this->assertRegExp(true, strspn("0123456789abcdef-", $res) ==
|
||||
|
||||
@@ -1,67 +1,70 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Verify;
|
||||
|
||||
/** Test the Verify */
|
||||
/**
|
||||
* Test the Verify
|
||||
*/
|
||||
class VerifyTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
///////////////
|
||||
// DATES //
|
||||
///////////////
|
||||
public function test_is_datetimeSQL1()
|
||||
///////////////
|
||||
// DATES //
|
||||
///////////////
|
||||
public function testIsDatetimeSQL1()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_datetimeSQL("2017-04-13 22:55:17");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_is_datetimeSQL2()
|
||||
public function testIsDatetimeSQL2()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_datetimeSQL("2017-13-55 22:55:17");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticIs_datetimeSQL1()
|
||||
public function testStaticIsDatetimeSQL1()
|
||||
{
|
||||
$res = Verify::staticIs_datetimeSQL("2017-04-13 22:55:17");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_staticIs_datetimeSQL2()
|
||||
public function testStaticIsDatetimeSQL2()
|
||||
{
|
||||
$res = Verify::staticIs_datetimeSQL("2017-13-55 22:55:17");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
public function test_is_dateSQL1()
|
||||
public function testIsDateSQL1()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_dateSQL("2017-04-13");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_is_dateSQL2()
|
||||
public function testIsDateSQL2()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_dateSQL("2017-13-55");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticIs_dateSQL1()
|
||||
public function testStaticIsDateSQL1()
|
||||
{
|
||||
$res = Verify::staticIs_dateSQL("2017-04-13");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_staticIs_dateSQL2()
|
||||
public function testStaticIsDateSQL2()
|
||||
{
|
||||
$res = Verify::staticIs_dateSQL("2017-13-55");
|
||||
$this->assertSame($res, false);
|
||||
@@ -71,13 +74,13 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
|
||||
/////////////////
|
||||
// STRINGS //
|
||||
/////////////////
|
||||
public function test_staticIsAllowedChars_1()
|
||||
public function testStaticIsAllowedChars1()
|
||||
{
|
||||
$res = Verify::staticIsAllowedChars("éléphant", "abcd");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticIsAllowedChars_2()
|
||||
public function testStaticIsAllowedChars2()
|
||||
{
|
||||
$res = Verify::staticIsAllowedChars("éléphant", "anhplté");
|
||||
$this->assertSame($res, true);
|
||||
@@ -86,25 +89,25 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
|
||||
/////////////////
|
||||
// NUMBERS //
|
||||
/////////////////
|
||||
public function test_staticIs_integer1()
|
||||
public function testStaticIsInteger1()
|
||||
{
|
||||
$res = Verify::staticIs_integer("2017-04-13 22:55:17");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticIs_integer2()
|
||||
public function testStaticIsInteger2()
|
||||
{
|
||||
$res = Verify::staticIs_integer("01234");
|
||||
$this->assertSame($res, true);
|
||||
}
|
||||
|
||||
public function test_staticIs_integer3()
|
||||
public function testStaticIsInteger3()
|
||||
{
|
||||
$res = Verify::staticIs_integer("0x1234");
|
||||
$this->assertSame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticIs_integer4()
|
||||
public function testStaticIsInteger4()
|
||||
{
|
||||
$res = Verify::staticIs_integer("");
|
||||
$this->assertSame($res, false);
|
||||
@@ -117,27 +120,27 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
|
||||
/////////////
|
||||
// URL //
|
||||
/////////////
|
||||
public function test_is_url1()
|
||||
public function testIsUrl1()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_url("invalid");
|
||||
$this->assertsame($res, false);
|
||||
}
|
||||
|
||||
public function test_is_url2()
|
||||
public function testIsUrl2()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_url("http://valid");
|
||||
$this->assertsame($res, true);
|
||||
}
|
||||
|
||||
public function test_staticIs_url1()
|
||||
public function testStaticIsUrl1()
|
||||
{
|
||||
$res = Verify::staticIs_url("invalid");
|
||||
$this->assertsame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticIs_url2()
|
||||
public function testStaticIsUrl2()
|
||||
{
|
||||
$res = Verify::staticIs_url("http://valid");
|
||||
$this->assertsame($res, true);
|
||||
@@ -146,40 +149,40 @@ class VerifyTest extends \PHPUnit_Framework_TestCase
|
||||
////////////////
|
||||
// OTHERS //
|
||||
////////////////
|
||||
public function test_is_UUID1()
|
||||
public function testIsUUID1()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_UUID("ca39275f-9224-425f-ba94-efce2aa5b52c");
|
||||
$this->assertsame($res, true);
|
||||
}
|
||||
|
||||
public function test_is_UUID2()
|
||||
public function testIsUUID2()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_UUID("zz39275f-9224-425f-ba94-efce2aa5b52c");
|
||||
$this->assertsame($res, false);
|
||||
}
|
||||
|
||||
public function test_is_UUID3()
|
||||
public function testIsUUID3()
|
||||
{
|
||||
$verify = new Verify();
|
||||
$res = $verify->is_UUID("2c");
|
||||
$this->assertsame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticis_UUID1()
|
||||
public function testStaticisUUID1()
|
||||
{
|
||||
$res = Verify::staticis_UUID("ca39275f-9224-425f-ba94-efce2aa5b52c");
|
||||
$this->assertsame($res, true);
|
||||
}
|
||||
|
||||
public function test_staticis_UUID2()
|
||||
public function testStaticisUUID2()
|
||||
{
|
||||
$res = Verify::staticis_UUID("zz39275f-9224-425f-ba94-efce2aa5b52c");
|
||||
$this->assertsame($res, false);
|
||||
}
|
||||
|
||||
public function test_staticis_UUID3()
|
||||
public function testStaticisUUID3()
|
||||
{
|
||||
$res = Verify::staticis_UUID("2c");
|
||||
$this->assertsame($res, false);
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Xdiff;
|
||||
|
||||
/** Test the domframework xdiff part */
|
||||
/**
|
||||
* Test the domframework xdiff part
|
||||
*/
|
||||
class XdiffTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
// Declaration of $string1 and $string2
|
||||
// {{{
|
||||
// Declaration of $string1 and $string2
|
||||
// {{{
|
||||
private $string1 = "This part of the
|
||||
document has stayed the
|
||||
same from version to
|
||||
@@ -70,11 +73,11 @@ This paragraph contains
|
||||
important new additions
|
||||
to this document.
|
||||
";
|
||||
// }}}
|
||||
// }}}
|
||||
|
||||
public function testDiffNormal1()
|
||||
{
|
||||
// Mode normal
|
||||
// Mode normal
|
||||
$xdiff = new Xdiff();
|
||||
$res = $xdiff->diff($this->string1, $this->string2);
|
||||
$this->assertSame($res, "0a1,6
|
||||
@@ -104,7 +107,7 @@ to this document.
|
||||
|
||||
public function testDiffNormal2()
|
||||
{
|
||||
// Mode normal
|
||||
// Mode normal
|
||||
$xdiff = new Xdiff();
|
||||
$res = $xdiff->diff("NEWLINE\n" . $this->string1, $this->string2);
|
||||
$this->assertSame($res, "1c1,6
|
||||
@@ -134,9 +137,9 @@ to this document.
|
||||
");
|
||||
}
|
||||
|
||||
public function test_diff_normal_3()
|
||||
public function testDiffNormal3()
|
||||
{
|
||||
// Mode normal
|
||||
// Mode normal
|
||||
$xdiff = new Xdiff();
|
||||
$res = $xdiff->diff("NEWLINE\n", "\n");
|
||||
$this->assertSame($res, "1c1
|
||||
@@ -148,7 +151,7 @@ to this document.
|
||||
|
||||
public function testDiffNormal4()
|
||||
{
|
||||
// Mode normal
|
||||
// Mode normal
|
||||
$xdiff = new Xdiff();
|
||||
$res = $xdiff->diff("\n", "NEWLINE\n");
|
||||
$this->assertSame($res, "1c1
|
||||
@@ -183,11 +186,11 @@ to this document.
|
||||
|
||||
public function testDiffUnified1()
|
||||
{
|
||||
// Mode unified
|
||||
// Mode unified
|
||||
$xdiff = new Xdiff("unified");
|
||||
$res = $xdiff->diff($this->string1, $this->string2);
|
||||
$date = date("Y-m-d H:i:s.u00");
|
||||
// DST must answer +0200 in winter and +0100 in summer
|
||||
// DST must answer +0200 in winter and +0100 in summer
|
||||
$dst = date("O");
|
||||
$this->assertSame($res, "--- Original {$date}0 $dst
|
||||
+++ New {$date}1 $dst
|
||||
@@ -217,7 +220,7 @@ to this document.
|
||||
|
||||
public function testDiffUnified2()
|
||||
{
|
||||
// Mode unified
|
||||
// Mode unified
|
||||
$xdiff = new Xdiff("unified");
|
||||
$res = $xdiff->diff("NEWLINE\n" . $this->string1, $this->string2);
|
||||
$this->assertSame($res, "--- Original " . date("Y-m-d H:i:s.u000 O") . "
|
||||
|
||||
@@ -1,26 +1,29 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
use Domframework\Xmppclient;
|
||||
|
||||
/** Test the domframework xmppclient part */
|
||||
/**
|
||||
* Test the domframework xmppclient part
|
||||
*/
|
||||
class xmppclientTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function test_connection_BADNAME()
|
||||
public function testConnectionBADNAME()
|
||||
{
|
||||
$this->expectException("Exception");
|
||||
$xmppclient = new Xmppclient();
|
||||
$res = $xmppclient->connect("NOTFOUND.fournier38.fr", 5222, "", "");
|
||||
}
|
||||
|
||||
public function test_connection_authenticate_1()
|
||||
public function testConnectionAuthenticate1()
|
||||
{
|
||||
$xmppclient = new Xmppclient();
|
||||
$res = $xmppclient->connect(
|
||||
@@ -32,7 +35,7 @@ class xmppclientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(is_object($res), true);
|
||||
}
|
||||
|
||||
public function test_connection_disco_1()
|
||||
public function testConnectionDisco1()
|
||||
{
|
||||
$xmppclient = new Xmppclient();
|
||||
$xmppclient->connect(
|
||||
@@ -45,7 +48,7 @@ class xmppclientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(is_array($res) && count($res) > 5, true);
|
||||
}
|
||||
|
||||
public function test_connection_sendMessage_1()
|
||||
public function testConnectionSendMessage1()
|
||||
{
|
||||
$xmppclient = new Xmppclient();
|
||||
$xmppclient->connect(
|
||||
@@ -61,7 +64,7 @@ class xmppclientTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame(is_object($res), true);
|
||||
}
|
||||
|
||||
public function test_connection_sendMessage_2()
|
||||
public function testConnectionSendMessage2()
|
||||
{
|
||||
$xmppclient = new Xmppclient();
|
||||
$xmppclient->connect(
|
||||
|
||||
@@ -1,45 +1,74 @@
|
||||
<?php
|
||||
/** Autoload */
|
||||
/**
|
||||
* Autoload
|
||||
*/
|
||||
spl_autoload_register(function ($class) {
|
||||
$classes = array ();
|
||||
foreach (scandir ("src") as $file)
|
||||
{
|
||||
$fileShort = basename ($file);
|
||||
if ($fileShort == "." || $fileShort == "..")
|
||||
continue;
|
||||
$classFile = substr ($fileShort, 0, -4);
|
||||
$classes["Domframework\\".$classFile] = "src/$file";
|
||||
}
|
||||
if (key_exists ($class, $classes))
|
||||
{
|
||||
@include ($classes[$class]);
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "ERROR : $class : doesnt exists in src\n";
|
||||
}
|
||||
$classes = [];
|
||||
foreach (scandir("src") as $file) {
|
||||
$fileShort = basename($file);
|
||||
if ($fileShort == "." || $fileShort == "..") {
|
||||
continue;
|
||||
}
|
||||
$classFile = substr($fileShort, 0, -4);
|
||||
$classes["Domframework\\" . $classFile] = "src/$file";
|
||||
}
|
||||
if (key_exists($class, $classes)) {
|
||||
@include($classes[$class]);
|
||||
} else {
|
||||
echo "ERROR : $class : doesnt exists in src\n";
|
||||
}
|
||||
});
|
||||
|
||||
define ("PHPUNIT", "ON-GOING");
|
||||
define("PHPUNIT", "ON-GOING");
|
||||
|
||||
|
||||
file_put_contents ("Tests/DblayerooSqliteTest.php",
|
||||
str_replace ("{ENGINE}", "sqlite",
|
||||
file_get_contents ("Tests/DblayerooComplet.php")));
|
||||
file_put_contents ("Tests/DblayerooMySQLTest.php",
|
||||
str_replace ("{ENGINE}", "mysql",
|
||||
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 ("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")));
|
||||
file_put_contents(
|
||||
"Tests/DblayerooSqliteTest.php",
|
||||
str_replace(
|
||||
"{ENGINE}",
|
||||
"sqlite",
|
||||
file_get_contents("Tests/DblayerooComplet.php")
|
||||
)
|
||||
);
|
||||
file_put_contents(
|
||||
"Tests/DblayerooMySQLTest.php",
|
||||
str_replace(
|
||||
"{ENGINE}",
|
||||
"mysql",
|
||||
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(
|
||||
"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
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
<?php
|
||||
|
||||
/** DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
/**
|
||||
* DomFramework - Tests
|
||||
* @package domframework
|
||||
* @author Dominique Fournier <dominique@fournier38.fr>
|
||||
* @license BSD
|
||||
*/
|
||||
|
||||
namespace Domframework\Tests;
|
||||
|
||||
$conf = array (
|
||||
"database" => array (
|
||||
$conf = [
|
||||
"database" => [
|
||||
"dsn" => "sqlite:/tmp/database.db",
|
||||
"username" => null,
|
||||
"password" => null,
|
||||
"driver_options" => null,
|
||||
"tableprefix" => "",
|
||||
),
|
||||
);
|
||||
],
|
||||
];
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
<html>
|
||||
<body>
|
||||
Text
|
||||
<?php if (isset ($var)) echo $var; ?>
|
||||
<?php if (isset($var)) {
|
||||
echo $var;
|
||||
} ?>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
7
phpstan.neon
Normal file
7
phpstan.neon
Normal file
@@ -0,0 +1,7 @@
|
||||
parameters:
|
||||
level: 1
|
||||
paths:
|
||||
- src
|
||||
- tools
|
||||
|
||||
# vim: set noexpandtab ts=4 sw=2: nolist #
|
||||
@@ -311,6 +311,7 @@ class Ipaddresses
|
||||
$e[count($e) - 1] = "0";
|
||||
}
|
||||
$s = 8 - count($e);
|
||||
$newipv6 = [];
|
||||
foreach ($e as $key => $val) {
|
||||
if ($val === "") {
|
||||
for ($i = 0; $i <= $s; $i++) {
|
||||
|
||||
@@ -72,14 +72,16 @@ class Logger
|
||||
* LOG_INFO informational message
|
||||
* LOG_DEBUG debug-level message
|
||||
*/
|
||||
private $priorities = [LOG_EMERG => "EMERG",
|
||||
LOG_ALERT => "ALERT",
|
||||
LOG_CRIT => "CRITICAL",
|
||||
LOG_ERR => "ERROR",
|
||||
LOG_WARNING => "WARNING",
|
||||
LOG_NOTICE => "NOTICE",
|
||||
LOG_INFO => "INFO",
|
||||
LOG_DEBUG => "DEBUG"];
|
||||
private $priorities = [
|
||||
LOG_EMERG => "EMERG",
|
||||
LOG_ALERT => "ALERT",
|
||||
LOG_CRIT => "CRITICAL",
|
||||
LOG_ERR => "ERROR",
|
||||
LOG_WARNING => "WARNING",
|
||||
LOG_NOTICE => "NOTICE",
|
||||
LOG_INFO => "INFO",
|
||||
LOG_DEBUG => "DEBUG",
|
||||
];
|
||||
|
||||
/**
|
||||
* Catch all the messages raised by the PHP, in trigger_error
|
||||
@@ -103,6 +105,7 @@ class Logger
|
||||
// This error code is not included in error_reporting
|
||||
return;
|
||||
}
|
||||
$priority = LOG_ERR;
|
||||
switch ($errno) {
|
||||
case E_ERROR:
|
||||
$priority = LOG_ERR;
|
||||
@@ -111,7 +114,7 @@ class Logger
|
||||
$priority = LOG_WARNING;
|
||||
break;
|
||||
case E_PARSE:
|
||||
$priority = LOG_PARSE;
|
||||
$priority = LOG_ERR;
|
||||
break;
|
||||
case E_NOTICE:
|
||||
$priority = LOG_NOTICE;
|
||||
@@ -225,6 +228,7 @@ class Logger
|
||||
if ($this->loglevelmin < $priority) {
|
||||
return;
|
||||
}
|
||||
$back = [];
|
||||
$backtrace = debug_backtrace();
|
||||
for ($i = 0; $i <= $this->backTraceSkip; $i++) {
|
||||
$back = array_shift($backtrace);
|
||||
@@ -271,6 +275,7 @@ class Logger
|
||||
$msg .= "\n" . ($e->getTraceAsString());
|
||||
}
|
||||
|
||||
$logsType = [];
|
||||
if (is_string($this->logtype)) {
|
||||
$logsType = explode("|", $this->logtype);
|
||||
} elseif (is_array($this->logtype)) {
|
||||
|
||||
@@ -53,6 +53,7 @@ class Queue
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,5 +101,6 @@ class Queue
|
||||
*/
|
||||
public function getRange($start, $number, $delete = false)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +153,7 @@ class Renderer
|
||||
$dataflash = "";
|
||||
if (isset($_SESSION["renderer"]["flash"])) {
|
||||
foreach ($_SESSION["renderer"]["flash"] as $flash) {
|
||||
$alert = "";
|
||||
$dataflash .= "<div class='alert ";
|
||||
switch ($flash[0]) {
|
||||
case 4:
|
||||
|
||||
@@ -221,6 +221,7 @@ class RouteSQL
|
||||
} else {
|
||||
if (isset($_SESSION["renderer"]["flash"])) {
|
||||
foreach ($_SESSION["renderer"]["flash"] as $flash) {
|
||||
$alert = "";
|
||||
$dataflash .= "<div class='alert ";
|
||||
switch ($flash[0]) {
|
||||
case 4:
|
||||
|
||||
@@ -184,6 +184,8 @@ class Tcpclient
|
||||
} else {
|
||||
$ips = array_merge($this->ipv6, $this->ipv4);
|
||||
}
|
||||
$errno = -1;
|
||||
$errstr = "";
|
||||
foreach ($ips as $ip) {
|
||||
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
|
||||
$ip = "[$ip]";
|
||||
|
||||
@@ -531,6 +531,7 @@ class Xdiff
|
||||
{
|
||||
$found1 = false;
|
||||
$found2 = false;
|
||||
$tmp1 = $tmp2 = -1;
|
||||
while ($i < count($array1)) {
|
||||
$tmp2 = $j;
|
||||
while ($tmp2 < count($array2)) {
|
||||
|
||||
@@ -178,5 +178,5 @@ if (! isset($argv[3])) {
|
||||
if (! isset($argv[4])) {
|
||||
die("No output file provided\n");
|
||||
}
|
||||
$modelgraph = new modelgraph($argv[1], $argv[2], $argv[3], $argv[4]);
|
||||
$modelgraph = new Modelgraph($argv[1], $argv[2], $argv[3], $argv[4]);
|
||||
$modelgraph->generate();
|
||||
|
||||
@@ -101,7 +101,7 @@ class Main
|
||||
if (! file_exists($configurationFile)) {
|
||||
touch($configurationFile);
|
||||
}
|
||||
$config = new Domframework\Configuration();
|
||||
$config = new Configuration();
|
||||
$config->confFile = $configurationFile;
|
||||
|
||||
$db = $config->get("db");
|
||||
@@ -400,7 +400,7 @@ class Main
|
||||
}
|
||||
|
||||
try {
|
||||
$main = new \main();
|
||||
$main = new \Main();
|
||||
} catch (Exception $e) {
|
||||
file_put_contents("php://stderr", $e->getMessage() . "\n");
|
||||
exit(4);
|
||||
|
||||
Reference in New Issue
Block a user