From 5cd5b0fb184d67fc82fecdf5df0016297c03f6d2 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Thu, 4 Dec 2014 17:05:59 +0100 Subject: [PATCH 01/57] Add a CLI script to init DB --- PhpRbac/install-cli.php | 181 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 PhpRbac/install-cli.php diff --git a/PhpRbac/install-cli.php b/PhpRbac/install-cli.php new file mode 100644 index 0000000..e956336 --- /dev/null +++ b/PhpRbac/install-cli.php @@ -0,0 +1,181 @@ + null, + 'host' => null, + 'name' => null, + 'table_prefix' => null, + 'user' => null, + 'password' => null + ]; + + $adapters = [ + 'pdo_mysql' => '"%s"', + 'mysqli' => '"%s"', + 'pdo_sqlite' => '__DIR__ . "/%s.sqlite3"' + ]; + + do{ + $retry = true; + + setAdapters($database, $adapters); + setHost($database); + setName($database); + setTablePrefix($database); + setUser($database); + setPassword($database); + + if(confirm($database) === false) + { + fputs(STDOUT, 'Cleaning the previous data..' . PHP_EOL); + continue; + } + + generateConfig($database, $adapters); + generateDatabase(); + + if(tryConnection($database) === false) + { + $retry = true; + continue; + } + + $retry = false; + }while($retry === true); + + function setAdapters(&$database, $adapters) + { + fputs(STDOUT, 'Please select one DB adapter' . PHP_EOL); + fputs(STDOUT, 'Available adapters' . PHP_EOL); + + reset($adapters); + while($key = key($adapters)) + { + fputs(STDOUT, "- $key".PHP_EOL); + next($adapters); + } + + fputs(STDOUT, 'Database adapter [pdo_mysql] : '); + $adapter = trim(fgets(STDIN)); + + $database['adapter'] = (!empty($adapter)) ? $adapter : 'pdo_mysql'; + + if(!isset($adapters[$database['adapter']])) + { + fputs(STDOUT, 'A wrong adapter has been chosen. Please correct it.' . PHP_EOL); + setAdapters($database, $adapters); + return true; + } + } + + function setHost(&$database) + { + fputs(STDOUT, 'Database host (ex. 127.0.0.1) : '); + + $database['host'] = trim(fgets(STDIN)); + } + + function setName(&$database) + { + fputs(STDOUT, 'Database name : '); + + $database['name'] = trim(fgets(STDIN)); + } + + function setTablePrefix(&$database) + { + fputs(STDOUT, 'Table prefix [phprbac_] : '); + + $prefix = trim(fgets(STDIN)); + $database['table_prefix'] = (!empty($prefix)) ? $prefix : 'phprbac_'; + } + + function setUser(&$database) + { + fputs(STDOUT, 'Database user : '); + + $database['user'] = trim(fgets(STDIN)); + } + + function setPassword(&$database) + { + fputs(STDOUT, 'Database password : '); + + $database['password'] = trim(fgets(STDIN)); + } + + function confirm($database) + { + fputs(STDOUT, PHP_EOL); + fputs(STDOUT, "The host is {$database['host']}" . PHP_EOL); + fputs(STDOUT, "The database name is {$database['name']} with {$database['adapter']} driver" . PHP_EOL); + fputs(STDOUT, "All the RBAC tables will be prefixed with {$database['table_prefix']}" . PHP_EOL); + fputs(STDOUT, "The credentials are {$database['user']}:{$database['password']}" . PHP_EOL); + fputs(STDOUT, "Do you confirm this is the expected configuration [Y/n] (Y) ?" . PHP_EOL); + + return (trim(fgets(STDIN)) !== 'n'); + } + + function tryConnection($database) + { + try{ + new PDO( + "mysql:host={$database['host']}; dbname={$database['name']}", + $database['user'], + $database['password'], + [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION + ] + ); + fputs(STDOUT, 'Test connection success.' . PHP_EOL); + return true; + } + catch (PDOException $ex) + { + fputs(STDOUT, 'The connection failed. Please try again.' . PHP_EOL); + return false; + } + } + + function generateConfig($database, $adapters) + { + $data = + 'reset(true); + + fputs(STDOUT, 'Database is generated.' . PHP_EOL); + } \ No newline at end of file From ebae7bdd50dffb1e2748cc239fa3f6c60a6592c7 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Thu, 4 Dec 2014 17:15:25 +0100 Subject: [PATCH 02/57] Replace the old file by the CLI script --- PhpRbac/install-cli.php | 181 --------------- PhpRbac/install.php | 475 ++++++++++++++-------------------------- 2 files changed, 167 insertions(+), 489 deletions(-) delete mode 100644 PhpRbac/install-cli.php diff --git a/PhpRbac/install-cli.php b/PhpRbac/install-cli.php deleted file mode 100644 index e956336..0000000 --- a/PhpRbac/install-cli.php +++ /dev/null @@ -1,181 +0,0 @@ - null, - 'host' => null, - 'name' => null, - 'table_prefix' => null, - 'user' => null, - 'password' => null - ]; - - $adapters = [ - 'pdo_mysql' => '"%s"', - 'mysqli' => '"%s"', - 'pdo_sqlite' => '__DIR__ . "/%s.sqlite3"' - ]; - - do{ - $retry = true; - - setAdapters($database, $adapters); - setHost($database); - setName($database); - setTablePrefix($database); - setUser($database); - setPassword($database); - - if(confirm($database) === false) - { - fputs(STDOUT, 'Cleaning the previous data..' . PHP_EOL); - continue; - } - - generateConfig($database, $adapters); - generateDatabase(); - - if(tryConnection($database) === false) - { - $retry = true; - continue; - } - - $retry = false; - }while($retry === true); - - function setAdapters(&$database, $adapters) - { - fputs(STDOUT, 'Please select one DB adapter' . PHP_EOL); - fputs(STDOUT, 'Available adapters' . PHP_EOL); - - reset($adapters); - while($key = key($adapters)) - { - fputs(STDOUT, "- $key".PHP_EOL); - next($adapters); - } - - fputs(STDOUT, 'Database adapter [pdo_mysql] : '); - $adapter = trim(fgets(STDIN)); - - $database['adapter'] = (!empty($adapter)) ? $adapter : 'pdo_mysql'; - - if(!isset($adapters[$database['adapter']])) - { - fputs(STDOUT, 'A wrong adapter has been chosen. Please correct it.' . PHP_EOL); - setAdapters($database, $adapters); - return true; - } - } - - function setHost(&$database) - { - fputs(STDOUT, 'Database host (ex. 127.0.0.1) : '); - - $database['host'] = trim(fgets(STDIN)); - } - - function setName(&$database) - { - fputs(STDOUT, 'Database name : '); - - $database['name'] = trim(fgets(STDIN)); - } - - function setTablePrefix(&$database) - { - fputs(STDOUT, 'Table prefix [phprbac_] : '); - - $prefix = trim(fgets(STDIN)); - $database['table_prefix'] = (!empty($prefix)) ? $prefix : 'phprbac_'; - } - - function setUser(&$database) - { - fputs(STDOUT, 'Database user : '); - - $database['user'] = trim(fgets(STDIN)); - } - - function setPassword(&$database) - { - fputs(STDOUT, 'Database password : '); - - $database['password'] = trim(fgets(STDIN)); - } - - function confirm($database) - { - fputs(STDOUT, PHP_EOL); - fputs(STDOUT, "The host is {$database['host']}" . PHP_EOL); - fputs(STDOUT, "The database name is {$database['name']} with {$database['adapter']} driver" . PHP_EOL); - fputs(STDOUT, "All the RBAC tables will be prefixed with {$database['table_prefix']}" . PHP_EOL); - fputs(STDOUT, "The credentials are {$database['user']}:{$database['password']}" . PHP_EOL); - fputs(STDOUT, "Do you confirm this is the expected configuration [Y/n] (Y) ?" . PHP_EOL); - - return (trim(fgets(STDIN)) !== 'n'); - } - - function tryConnection($database) - { - try{ - new PDO( - "mysql:host={$database['host']}; dbname={$database['name']}", - $database['user'], - $database['password'], - [ - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION - ] - ); - fputs(STDOUT, 'Test connection success.' . PHP_EOL); - return true; - } - catch (PDOException $ex) - { - fputs(STDOUT, 'The connection failed. Please try again.' . PHP_EOL); - return false; - } - } - - function generateConfig($database, $adapters) - { - $data = - 'reset(true); - - fputs(STDOUT, 'Database is generated.' . PHP_EOL); - } \ No newline at end of file diff --git a/PhpRbac/install.php b/PhpRbac/install.php index 724e8a3..e956336 100644 --- a/PhpRbac/install.php +++ b/PhpRbac/install.php @@ -1,322 +1,181 @@ - - - - - - - PHP-RBAC Installation - - - - - - - -
-
- -
- - - null, + 'host' => null, + 'name' => null, + 'table_prefix' => null, + 'user' => null, + 'password' => null + ]; + + $adapters = [ + 'pdo_mysql' => '"%s"', + 'mysqli' => '"%s"', + 'pdo_sqlite' => '__DIR__ . "/%s.sqlite3"' + ]; + + do{ + $retry = true; + + setAdapters($database, $adapters); + setHost($database); + setName($database); + setTablePrefix($database); + setUser($database); + setPassword($database); + + if(confirm($database) === false) + { + fputs(STDOUT, 'Cleaning the previous data..' . PHP_EOL); + continue; } - } - - if (isset($_GET['error_dbHost'])) { - if ($_GET['error_dbHost'] == 1) { - $dbHost = ''; - } else { - $dbHost = $_GET['error_dbHost']; + + generateConfig($database, $adapters); + generateDatabase(); + + if(tryConnection($database) === false) + { + $retry = true; + continue; } - } - - if (isset($_GET['error_dbName'])) { - if ($_GET['error_dbName'] == 1) { - $dbName = ''; - } else { - $dbName = $_GET['error_dbName']; + + $retry = false; + }while($retry === true); + + function setAdapters(&$database, $adapters) + { + fputs(STDOUT, 'Please select one DB adapter' . PHP_EOL); + fputs(STDOUT, 'Available adapters' . PHP_EOL); + + reset($adapters); + while($key = key($adapters)) + { + fputs(STDOUT, "- $key".PHP_EOL); + next($adapters); } - } - - if (isset($_GET['error_dbTablePrefix'])) { - if ($_GET['error_dbTablePrefix'] == 1) { - $dbTablePrefix = ''; - } else { - $dbTablePrefix = $_GET['error_dbTablePrefix']; + + fputs(STDOUT, 'Database adapter [pdo_mysql] : '); + $adapter = trim(fgets(STDIN)); + + $database['adapter'] = (!empty($adapter)) ? $adapter : 'pdo_mysql'; + + if(!isset($adapters[$database['adapter']])) + { + fputs(STDOUT, 'A wrong adapter has been chosen. Please correct it.' . PHP_EOL); + setAdapters($database, $adapters); + return true; } } - - if (isset($_GET['error_dbUser'])) { - if ($_GET['error_dbUser'] == 1) { - $dbUser = ''; - } else { - $dbUser = $_GET['error_dbUser']; + + function setHost(&$database) + { + fputs(STDOUT, 'Database host (ex. 127.0.0.1) : '); + + $database['host'] = trim(fgets(STDIN)); + } + + function setName(&$database) + { + fputs(STDOUT, 'Database name : '); + + $database['name'] = trim(fgets(STDIN)); + } + + function setTablePrefix(&$database) + { + fputs(STDOUT, 'Table prefix [phprbac_] : '); + + $prefix = trim(fgets(STDIN)); + $database['table_prefix'] = (!empty($prefix)) ? $prefix : 'phprbac_'; + } + + function setUser(&$database) + { + fputs(STDOUT, 'Database user : '); + + $database['user'] = trim(fgets(STDIN)); + } + + function setPassword(&$database) + { + fputs(STDOUT, 'Database password : '); + + $database['password'] = trim(fgets(STDIN)); + } + + function confirm($database) + { + fputs(STDOUT, PHP_EOL); + fputs(STDOUT, "The host is {$database['host']}" . PHP_EOL); + fputs(STDOUT, "The database name is {$database['name']} with {$database['adapter']} driver" . PHP_EOL); + fputs(STDOUT, "All the RBAC tables will be prefixed with {$database['table_prefix']}" . PHP_EOL); + fputs(STDOUT, "The credentials are {$database['user']}:{$database['password']}" . PHP_EOL); + fputs(STDOUT, "Do you confirm this is the expected configuration [Y/n] (Y) ?" . PHP_EOL); + + return (trim(fgets(STDIN)) !== 'n'); + } + + function tryConnection($database) + { + try{ + new PDO( + "mysql:host={$database['host']}; dbname={$database['name']}", + $database['user'], + $database['password'], + [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION + ] + ); + fputs(STDOUT, 'Test connection success.' . PHP_EOL); + return true; + } + catch (PDOException $ex) + { + fputs(STDOUT, 'The connection failed. Please try again.' . PHP_EOL); + return false; } } + + function generateConfig($database, $adapters) + { + $data = + ' - -

PHP-RBAC Quick Install

- -

Database information

- - - -

- All Fields Are Required -

- - - -

- Passwords Do Not Match -

- - - -
- -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- -
- -
- -
- - - - - - - - reset(true);' - $rbac->reset(true); - - // Send to Success Message - header('Location: install.php?success=1'); - exit; - - ?> - - - -

Installation Successful!

- -

Congratulations: You are now ready to use PHP-RBAC!

- -

- Warning - Please remove 'install.php' for security reasons! -

- - - -
- -
- -
- - - \ No newline at end of file + + function generateDatabase() + { + $rbac = new Rbac(); + $rbac->reset(true); + + fputs(STDOUT, 'Database is generated.' . PHP_EOL); + } \ No newline at end of file From c17420e89b3cf4d13a9294f584f1b83474280a7f Mon Sep 17 00:00:00 2001 From: Charles Sanquer Date: Thu, 8 Jan 2015 12:41:11 +0100 Subject: [PATCH 03/57] add vendor to gitignore --- .gitignore | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 477de25..b820983 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,10 @@ -.settings -.buildpath -.project -*bak* -*draft* -*phprbac.sqlite3* -*Doxygen* -*phpdoc* -index.php \ No newline at end of file +.settings +.buildpath +.project +*bak* +*draft* +*phprbac.sqlite3* +*Doxygen* +*phpdoc* +index.php +vendor From 4958d1952805165056b06a437ca629af65a4766b Mon Sep 17 00:00:00 2001 From: Charles Sanquer Date: Thu, 8 Jan 2015 12:41:58 +0100 Subject: [PATCH 04/57] remove unnecessary repositories in composer.json --- composer.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/composer.json b/composer.json index d8e71c9..eb11f79 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,5 @@ "psr-0" : { "PhpRbac" : "PhpRbac/src" } - }, - "repositories" : [{ - "type" : "vcs", - "url" : "https://github.com/OWASP/rbac.git" - } - ] + } } From 3d3a27d941d2aa03ccb1c21189377c574901af51 Mon Sep 17 00:00:00 2001 From: Charles Sanquer Date: Thu, 8 Jan 2015 14:34:45 +0100 Subject: [PATCH 05/57] fix instanceof usage --- PhpRbac/src/PhpRbac/core/lib/Jf.php | 4 ++-- PhpRbac/src/PhpRbac/core/lib/rbac.php | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/PhpRbac/src/PhpRbac/core/lib/Jf.php b/PhpRbac/src/PhpRbac/core/lib/Jf.php index a769ea8..bf303e5 100644 --- a/PhpRbac/src/PhpRbac/core/lib/Jf.php +++ b/PhpRbac/src/PhpRbac/core/lib/Jf.php @@ -43,10 +43,10 @@ public static function tablePrefix() static function sql($Query) { $args = func_get_args (); - if (get_class ( self::$Db ) == "PDO") + if (self::$Db instanceof \PDO) return call_user_func_array ( "self::sqlPdo", $args ); else - if (get_class ( self::$Db ) == "mysqli") + if (self::$Db instanceof mysqli) return call_user_func_array ( "self::sqlMysqli", $args ); else throw new Exception ( "Unknown database interface type." ); diff --git a/PhpRbac/src/PhpRbac/core/lib/rbac.php b/PhpRbac/src/PhpRbac/core/lib/rbac.php index 9c2dc3e..1878afd 100644 --- a/PhpRbac/src/PhpRbac/core/lib/rbac.php +++ b/PhpRbac/src/PhpRbac/core/lib/rbac.php @@ -24,13 +24,11 @@ function tablePrefix() protected function isSQLite() { - $Adapter=get_class(Jf::$Db); - return $Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite"; + return Jf::$Db instanceof \PDO && Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite"; } protected function isMySql() { - $Adapter=get_class(Jf::$Db); - return $Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql"); + return Jf::$Db instanceof mysqli || (Jf::$Db instanceof \PDO && Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql"); } } From 742fc9e37a05b988a764d63914c3b9006c8cd744 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Fri, 9 Jan 2015 14:59:50 +0100 Subject: [PATCH 06/57] Move files in new directories --- .gitignore | 2 +- PhpRbac/Database/JModel.php | 21 + .../{src/PhpRbac/core/lib => Database}/Jf.php | 1 - .../{database => Database}/database.config | 0 PhpRbac/{database => Database}/mysql.sql | 0 PhpRbac/{database => Database}/sqlite.sql | 0 PhpRbac/Exception/RbacException.php | 5 + .../RbacPermissionNotFoundException.php | 5 + .../Exception/RbacRoleNotFoundException.php | 5 + .../RbacUserNotProvidedException.php | 5 + PhpRbac/Manager/BaseRbacManager.php | 462 +++++++ PhpRbac/Manager/PermissionManager.php | 100 ++ PhpRbac/Manager/RbacManager.php | 181 +++ PhpRbac/Manager/RoleManager.php | 153 +++ PhpRbac/Manager/UserManager.php | 185 +++ .../base.php => NestedSet/BaseNestedSet.php} | 26 +- .../NestedSet/ExtendedNestedSetInterface.php | 24 + .../full.php => NestedSet/FullNestedSet.php} | 28 +- PhpRbac/NestedSet/NestedSetInterface.php | 22 + PhpRbac/{src/PhpRbac => }/Rbac.php | 0 PhpRbac/{tests => Tests}/README.md | 0 PhpRbac/{tests => Tests}/bootstrap.php | 0 .../{tests => Tests}/database/database.config | 0 PhpRbac/{tests => Tests}/mysql_tests.bat | 0 PhpRbac/{tests => Tests}/mysql_tests.sh | 0 PhpRbac/{tests => Tests}/phpunit.bat | 0 PhpRbac/{tests => Tests}/phpunit.phar | 0 PhpRbac/{tests => Tests}/phpunit_mysql.xml | 0 PhpRbac/{tests => Tests}/phpunit_sqlite.xml | 0 PhpRbac/{tests => Tests}/sqlite_tests.bat | 0 PhpRbac/{tests => Tests}/sqlite_tests.sh | 0 .../src/Generic_Tests_DatabaseTestCase.php | 0 PhpRbac/{tests => Tests}/src/RbacBase.php | 0 .../{tests => Tests}/src/RbacManagerTest.php | 0 .../src/RbacPermissionsTest.php | 0 .../{tests => Tests}/src/RbacRolesTest.php | 0 PhpRbac/{tests => Tests}/src/RbacSetup.php | 0 .../{tests => Tests}/src/RbacUsersTest.php | 0 ...xpected_add_path_permissions_hierarchy.xml | 0 ...path_permissions_hierarchy_description.xml | 0 ...pected_add_path_permissions_sequential.xml | 0 ...ath_permissions_sequential_description.xml | 0 .../expected_add_path_permissions_single.xml | 0 ...dd_path_permissions_single_description.xml | 0 .../expected_add_path_roles_hierarchy.xml | 0 ...d_add_path_roles_hierarchy_description.xml | 0 .../expected_add_path_roles_sequential.xml | 0 ..._add_path_roles_sequential_description.xml | 0 .../base/expected_add_path_roles_single.xml | 0 ...cted_add_path_roles_single_description.xml | 0 .../expected_add_permissions_hierarchy.xml | 0 .../expected_add_permissions_sequential.xml | 0 .../base/expected_add_roles_hierarchy.xml | 0 .../base/expected_add_roles_sequential.xml | 0 .../base/expected_assign_permissions.xml | 0 .../datasets/base/expected_assign_roles.xml | 0 .../base/expected_edit_permissions_all.xml | 0 .../expected_edit_permissions_description.xml | 0 .../base/expected_edit_permissions_title.xml | 0 .../datasets/base/expected_edit_roles_all.xml | 0 .../base/expected_edit_roles_description.xml | 0 .../base/expected_edit_roles_title.xml | 0 ...expected_reset_assignments_permissions.xml | 0 .../base/expected_reset_assignments_roles.xml | 0 .../base/expected_reset_permissions.xml | 0 .../datasets/base/expected_reset_roles.xml | 0 .../base/expected_unassign_permissions.xml | 0 .../datasets/base/expected_unassign_roles.xml | 0 .../src/datasets/database-seed.xml | 0 .../datasets/manager/expected_assign_id.xml | 0 .../datasets/manager/expected_assign_path.xml | 0 .../manager/expected_assign_title.xml | 0 .../src/datasets/manager/expected_reset.xml | 0 .../permissions/expected_remove_recursive.xml | 0 .../permissions/expected_remove_single.xml | 0 .../expected_remove_single_role.xml | 0 .../permissions/expected_unassign_roles.xml | 0 .../roles/expected_remove_recursive.xml | 0 .../datasets/roles/expected_remove_single.xml | 0 .../expected_remove_single_permission.xml | 0 .../roles/expected_unassign_permissions.xml | 0 .../roles/expected_unassign_users.xml | 0 .../datasets/users/expected_assign_no_id.xml | 0 .../users/expected_assign_with_id.xml | 0 .../users/expected_assign_with_path.xml | 0 .../users/expected_reset_assignments.xml | 0 .../src/datasets/users/expected_unassign.xml | 0 PhpRbac/{src/PhpRbac/core => }/setup.php | 0 PhpRbac/src/PhpRbac/core/README.md | 3 - PhpRbac/src/PhpRbac/core/lib/rbac.php | 1120 ----------------- 90 files changed, 1172 insertions(+), 1176 deletions(-) create mode 100644 PhpRbac/Database/JModel.php rename PhpRbac/{src/PhpRbac/core/lib => Database}/Jf.php (99%) rename PhpRbac/{database => Database}/database.config (100%) rename PhpRbac/{database => Database}/mysql.sql (100%) rename PhpRbac/{database => Database}/sqlite.sql (100%) create mode 100644 PhpRbac/Exception/RbacException.php create mode 100644 PhpRbac/Exception/RbacPermissionNotFoundException.php create mode 100644 PhpRbac/Exception/RbacRoleNotFoundException.php create mode 100644 PhpRbac/Exception/RbacUserNotProvidedException.php create mode 100644 PhpRbac/Manager/BaseRbacManager.php create mode 100644 PhpRbac/Manager/PermissionManager.php create mode 100644 PhpRbac/Manager/RbacManager.php create mode 100644 PhpRbac/Manager/RoleManager.php create mode 100644 PhpRbac/Manager/UserManager.php rename PhpRbac/{src/PhpRbac/core/lib/nestedset/base.php => NestedSet/BaseNestedSet.php} (95%) create mode 100644 PhpRbac/NestedSet/ExtendedNestedSetInterface.php rename PhpRbac/{src/PhpRbac/core/lib/nestedset/full.php => NestedSet/FullNestedSet.php} (95%) create mode 100644 PhpRbac/NestedSet/NestedSetInterface.php rename PhpRbac/{src/PhpRbac => }/Rbac.php (100%) rename PhpRbac/{tests => Tests}/README.md (100%) rename PhpRbac/{tests => Tests}/bootstrap.php (100%) rename PhpRbac/{tests => Tests}/database/database.config (100%) rename PhpRbac/{tests => Tests}/mysql_tests.bat (100%) rename PhpRbac/{tests => Tests}/mysql_tests.sh (100%) rename PhpRbac/{tests => Tests}/phpunit.bat (100%) rename PhpRbac/{tests => Tests}/phpunit.phar (100%) rename PhpRbac/{tests => Tests}/phpunit_mysql.xml (100%) rename PhpRbac/{tests => Tests}/phpunit_sqlite.xml (100%) rename PhpRbac/{tests => Tests}/sqlite_tests.bat (100%) rename PhpRbac/{tests => Tests}/sqlite_tests.sh (100%) rename PhpRbac/{tests => Tests}/src/Generic_Tests_DatabaseTestCase.php (100%) rename PhpRbac/{tests => Tests}/src/RbacBase.php (100%) rename PhpRbac/{tests => Tests}/src/RbacManagerTest.php (100%) rename PhpRbac/{tests => Tests}/src/RbacPermissionsTest.php (100%) rename PhpRbac/{tests => Tests}/src/RbacRolesTest.php (100%) rename PhpRbac/{tests => Tests}/src/RbacSetup.php (100%) rename PhpRbac/{tests => Tests}/src/RbacUsersTest.php (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_permissions_hierarchy.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_permissions_hierarchy_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_permissions_sequential.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_permissions_sequential_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_permissions_single.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_permissions_single_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_roles_hierarchy.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_roles_hierarchy_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_roles_sequential.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_roles_sequential_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_roles_single.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_path_roles_single_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_permissions_hierarchy.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_permissions_sequential.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_roles_hierarchy.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_add_roles_sequential.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_assign_permissions.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_assign_roles.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_edit_permissions_all.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_edit_permissions_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_edit_permissions_title.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_edit_roles_all.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_edit_roles_description.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_edit_roles_title.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_reset_assignments_permissions.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_reset_assignments_roles.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_reset_permissions.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_reset_roles.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_unassign_permissions.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/base/expected_unassign_roles.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/database-seed.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/manager/expected_assign_id.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/manager/expected_assign_path.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/manager/expected_assign_title.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/manager/expected_reset.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/permissions/expected_remove_recursive.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/permissions/expected_remove_single.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/permissions/expected_remove_single_role.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/permissions/expected_unassign_roles.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/roles/expected_remove_recursive.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/roles/expected_remove_single.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/roles/expected_remove_single_permission.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/roles/expected_unassign_permissions.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/roles/expected_unassign_users.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/users/expected_assign_no_id.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/users/expected_assign_with_id.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/users/expected_assign_with_path.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/users/expected_reset_assignments.xml (100%) rename PhpRbac/{tests => Tests}/src/datasets/users/expected_unassign.xml (100%) rename PhpRbac/{src/PhpRbac/core => }/setup.php (100%) delete mode 100644 PhpRbac/src/PhpRbac/core/README.md delete mode 100644 PhpRbac/src/PhpRbac/core/lib/rbac.php diff --git a/.gitignore b/.gitignore index 477de25..d1c47ff 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ *phprbac.sqlite3* *Doxygen* *phpdoc* -index.php \ No newline at end of file +/nbproject/ \ No newline at end of file diff --git a/PhpRbac/Database/JModel.php b/PhpRbac/Database/JModel.php new file mode 100644 index 0000000..d98f7b8 --- /dev/null +++ b/PhpRbac/Database/JModel.php @@ -0,0 +1,21 @@ +getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite"; + } + + protected function isMySql() + { + $Adapter=get_class(Jf::$Db); + return $Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql"); + } +} \ No newline at end of file diff --git a/PhpRbac/src/PhpRbac/core/lib/Jf.php b/PhpRbac/Database/Jf.php similarity index 99% rename from PhpRbac/src/PhpRbac/core/lib/Jf.php rename to PhpRbac/Database/Jf.php index a769ea8..7ab9579 100644 --- a/PhpRbac/src/PhpRbac/core/lib/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -1,5 +1,4 @@ rootId (); + return (int)$this->{$this->type ()}->insertChildData ( array ("Title" => $Title, "Description" => $Description ), "ID=?", $ParentID ); + } + + /** + * Adds a path and all its components. + * Will not replace or create siblings if a component exists. + * + * @param string $Path + * such as /some/role/some/where - Must begin with a / (slash) + * @param array $Descriptions + * array of descriptions (will add with empty description if not available) + * + * @return integer Number of nodes created (0 if none created) + */ + function addPath($Path, array $Descriptions = null) + { + if ($Path[0] !== "/") + throw new \Exception ("The path supplied is not valid."); + + $Path = substr ( $Path, 1 ); + $Parts = explode ( "/", $Path ); + $Parent = 1; + $index = 0; + $CurrentPath = ""; + $NodesCreated = 0; + + foreach ($Parts as $p) + { + if (isset ($Descriptions[$index])) + $Description = $Descriptions[$index]; + else + $Description = ""; + $CurrentPath .= "/{$p}"; + $t = $this->pathId($CurrentPath); + if (! $t) + { + $IID = $this->add($p, $Description, $Parent); + $Parent = $IID; + $NodesCreated++; + } + else + { + $Parent = $t; + } + + $index += 1; + } + + return (int)$NodesCreated; + } + + /** + * Return count of the entity + * + * @return integer + */ + function count() + { + $Res = Jf::sql ( "SELECT COUNT(*) FROM {$this->tablePrefix()}{$this->type()}" ); + return (int)$Res [0] ['COUNT(*)']; + } + + /** + * Returns ID of entity + * + * @param string $entity (Path or Title) + * + * @return mixed ID of entity or null + */ + public function returnId($entity = null) + { + if (substr ($entity, 0, 1) == "/") { + $entityID = $this->pathId($entity); + } else { + $entityID = $this->titleId($entity); + } + + return $entityID; + } + + /** + * Returns ID of a path + * + * @todo this has a limit of 1000 characters on $Path + * @param string $Path + * such as /role1/role2/role3 ( a single slash is root) + * @return integer NULL + */ + public function pathId($Path) + { + $Path = "root" . $Path; + + if ($Path [strlen ( $Path ) - 1] == "/") + $Path = substr ( $Path, 0, strlen ( $Path ) - 1 ); + $Parts = explode ( "/", $Path ); + + $Adapter = get_class(Jf::$Db); + if ($Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql")) { + $GroupConcat="GROUP_CONCAT(parent.Title ORDER BY parent.Lft SEPARATOR '/')"; + } elseif ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite") { + $GroupConcat="GROUP_CONCAT(parent.Title,'/')"; + } else { + throw new \Exception ("Unknown Group_Concat on this type of database: {$Adapter}"); + } + + $res = Jf::sql ( "SELECT node.ID,{$GroupConcat} AS Path + FROM {$this->tablePrefix()}{$this->type()} AS node, + {$this->tablePrefix()}{$this->type()} AS parent + WHERE node.Lft BETWEEN parent.Lft AND parent.Rght + AND node.Title=? + GROUP BY node.ID + HAVING Path = ? + ", $Parts [count ( $Parts ) - 1], $Path ); + + if ($res) + return $res [0] ['ID']; + else + return null; + // TODO: make the below SQL work, so that 1024 limit is over + + $QueryBase = ("SELECT n0.ID \nFROM {$this->tablePrefix()}{$this->type()} AS n0"); + $QueryCondition = "\nWHERE n0.Title=?"; + + for($i = 1; $i < count ( $Parts ); ++ $i) + { + $j = $i - 1; + $QueryBase .= "\nJOIN {$this->tablePrefix()}{$this->type()} AS n{$i} ON (n{$j}.Lft BETWEEN n{$i}.Lft+1 AND n{$i}.Rght)"; + $QueryCondition .= "\nAND n{$i}.Title=?"; + // Forcing middle elements + $QueryBase .= "\nLEFT JOIN {$this->tablePrefix()}{$this->type()} AS nn{$i} ON (nn{$i}.Lft BETWEEN n{$i}.Lft+1 AND n{$j}.Lft-1)"; + $QueryCondition .= "\nAND nn{$i}.Lft IS NULL"; + } + $Query = $QueryBase . $QueryCondition; + $PartsRev = array_reverse ( $Parts ); + array_unshift ( $PartsRev, $Query ); + + print_ ( $PartsRev ); + $res = call_user_func_array ( "Jf::sql", $PartsRev ); + + if ($res) + return $res [0] ['ID']; + else + return null; + } + + /** + * Returns ID belonging to a title, and the first one on that + * + * @param string $Title + * @return integer Id of specified Title + */ + public function titleId($Title) + { + return $this->{$this->type ()}->getID ( "Title=?", $Title ); + } + + /** + * Return the whole record of a single entry (including Rght and Lft fields) + * + * @param integer $ID + */ + protected function getRecord($ID) + { + $args = func_get_args (); + return call_user_func_array ( array ($this->{$this->type ()}, "getRecord" ), $args ); + } + + /** + * Returns title of entity + * + * @param integer $ID + * @return string NULL + */ + function getTitle($ID) + { + $r = $this->getRecord ( "ID=?", $ID ); + if ($r) + return $r ['Title']; + else + return null; + } + + /** + * Returns path of a node + * + * @param integer $ID + * @return string path + */ + function getPath($ID) + { + $res = $this->{$this->type ()}->pathConditional ( "ID=?", $ID ); + $out = null; + if (is_array ( $res )) + foreach ( $res as $r ) + if ($r ['ID'] == 1) + $out = '/'; + else + $out .= "/" . $r ['Title']; + if (strlen ( $out ) > 1) + return substr ( $out, 1 ); + else + return $out; + } + + /** + * Return description of entity + * + * @param integer $ID + * @return string NULL + */ + function getDescription($ID) + { + $r = $this->getRecord ( "ID=?", $ID ); + if ($r) + return $r ['Description']; + else + return null; + } + + /** + * Edits an entity, changing title and/or description. Maintains Id. + * + * @param integer $ID + * @param string $NewTitle + * @param string $NewDescription + * + */ + function edit($ID, $NewTitle = null, $NewDescription = null) + { + $Data = array (); + + if ($NewTitle !== null) + $Data ['Title'] = $NewTitle; + + if ($NewDescription !== null) + $Data ['Description'] = $NewDescription; + + return $this->{$this->type ()}->editData ( $Data, "ID=?", $ID ) == 1; + } + + /** + * Returns children of an entity + * + * @param integer $ID + * @return array + * + */ + function children($ID) + { + return $this->{$this->type ()}->childrenConditional ( "ID=?", $ID ); + } + + /** + * Returns descendants of a node, with their depths in integer + * + * @param integer $ID + * @return array with keys as titles and Title,ID, Depth and Description + * + */ + function descendants($ID) + { + $res = $this->{$this->type ()}->descendantsConditional(/* absolute depths*/false, "ID=?", $ID ); + $out = array (); + if (is_array ( $res )) + foreach ( $res as $v ) + $out [$v ['Title']] = $v; + return $out; + } + + /** + * Return depth of a node + * + * @param integer $ID + */ + function depth($ID) + { + return $this->{$this->type ()}->depthConditional ( "ID=?", $ID ); + } + + /** + * Returns parent of a node + * + * @param integer $ID + * @return array including Title, Description and ID + * + */ + function parentNode($ID) + { + return $this->{$this->type ()}->parentNodeConditional ( "ID=?", $ID ); + } + + /** + * Reset the table back to its initial state + * Keep in mind that this will not touch relations + * + * @param boolean $Ensure + * must be true to work, otherwise an \Exception is thrown + * @throws \Exception + * @return integer number of deleted entries + * + */ + function reset($Ensure = false) + { + if ($Ensure !== true) + { + throw new \Exception ("You must pass true to this function, otherwise it won't work."); + return; + } + $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}{$this->type()}" ); + $Adapter = get_class(Jf::$Db); + if ($this->isMySql()) + Jf::sql ( "ALTER TABLE {$this->tablePrefix()}{$this->type()} AUTO_INCREMENT=1 " ); + elseif ($this->isSQLite()) + Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "{$this->type()}" ); + else + throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" ); + $iid = Jf::sql ( "INSERT INTO {$this->tablePrefix()}{$this->type()} (Title,Description,Lft,Rght) VALUES (?,?,?,?)", "root", "root",0,1 ); + return (int)$res; + } + + /** + * Assigns a role to a permission (or vice-verse) + * + * @param mixed $Role + * Id, Title and Path + * @param mixed $Permission + * Id, Title and Path + * @return boolean inserted or existing + * + * @todo: Check for valid permissions/roles + * @todo: Implement custom error handler + */ + function assign($Role, $Permission) + { + if (is_numeric($Role)) + { + $RoleID = $Role; + } else { + if (substr($Role, 0, 1) == "/") + $RoleID = Jf::$Rbac->Roles->pathId($Role); + else + $RoleID = Jf::$Rbac->Roles->titleId($Role); + } + + if (is_numeric($Permission)) + { + $PermissionID = $Permission; + } else { + if (substr($Permission, 0, 1) == "/") + $PermissionID = Jf::$Rbac->Permissions->pathId($Permission); + else + $PermissionID = Jf::$Rbac->Permissions->titleId($Permission); + } + + return Jf::sql("INSERT INTO {$this->tablePrefix()}rolepermissions + (RoleID,PermissionID,AssignmentDate) + VALUES (?,?,?)", $RoleID, $PermissionID, Jf::time()) >= 1; + } + + /** + * Unassigns a role-permission relation + * + * @param mixed $Role + * Id, Title and Path + * @param mixed $Permission: + * Id, Title and Path + * @return boolean + */ + function unassign($Role, $Permission) + { + if (is_numeric($Role)) + { + $RoleID = $Role; + } else { + if (substr($Role, 0, 1) == "/") + $RoleID = Jf::$Rbac->Roles->pathId($Role); + else + $RoleID = Jf::$Rbac->Roles->titleId($Role); + } + + if (is_numeric($Permission)) + { + $PermissionID = $Permission; + } else { + if (substr($Permission, 0, 1) == "/") + $PermissionID = Jf::$Rbac->Permissions->pathId($Permission); + else + $PermissionID = Jf::$Rbac->Permissions->titleId($Permission); + } + + return Jf::sql("DELETE FROM {$this->tablePrefix()}rolepermissions WHERE + RoleID=? AND PermissionID=?", $RoleID, $PermissionID) == 1; + } + + /** + * Remove all role-permission relations + * mostly used for testing + * + * @param boolean $Ensure + * must be set to true or throws an \Exception + * @return number of deleted assignments + */ + function resetAssignments($Ensure = false) + { + if ($Ensure !== true) + { + throw new \Exception ("You must pass true to this function, otherwise it won't work."); + return; + } + $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions" ); + + $Adapter = get_class(Jf::$Db); + if ($this->isMySql()) + Jf::sql ( "ALTER TABLE {$this->tablePrefix()}rolepermissions AUTO_INCREMENT =1 " ); + elseif ($this->isSQLite()) + Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_rolepermissions" ); + else + throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" ); + $this->assign ( $this->rootId(), $this->rootId()); + return $res; + } +} \ No newline at end of file diff --git a/PhpRbac/Manager/PermissionManager.php b/PhpRbac/Manager/PermissionManager.php new file mode 100644 index 0000000..dd502ab --- /dev/null +++ b/PhpRbac/Manager/PermissionManager.php @@ -0,0 +1,100 @@ +permissions = new FullNestedSet ( $this->tablePrefix () . "permissions", "ID", "Lft", "Rght" ); + } + + /** + * Remove permissions from system + * + * @param integer $ID + * permission id + * @param boolean $Recursive + * delete all descendants + * + */ + function remove($ID, $Recursive = false) + { + $this->unassignRoles ( $ID ); + if (! $Recursive) + return $this->permissions->deleteConditional ( "ID=?", $ID ); + else + return $this->permissions->deleteSubtreeConditional ( "ID=?", $ID ); + } + + /** + * Unassignes all roles of this permission, and returns their number + * + * @param integer $ID + * Permission Id + * @return integer + */ + function unassignRoles($ID) + { + $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE + PermissionID=?", $ID ); + return (int)$res; + } + + /** + * Returns all roles assigned to a permission + * + * @param mixed $Permission + * Id, Title, Path + * @param boolean $OnlyIDs + * if true, result will be a 1D array of IDs + * @return Array 2D or 1D or null + */ + function roles($Permission, $OnlyIDs = true) + { + if (!is_numeric($Permission)) + $Permission = $this->returnId($Permission); + + if ($OnlyIDs) + { + $Res = Jf::sql ( "SELECT RoleID AS `ID` FROM + {$this->tablePrefix()}rolepermissions WHERE PermissionID=? ORDER BY RoleID", $Permission ); + + if (is_array ( $Res )) + { + $out = array (); + foreach ( $Res as $R ) + $out [] = $R ['ID']; + return $out; + } + else + return null; + } else { + return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}roles AS `TP` + LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.RoleID=`TP`.ID) + WHERE PermissionID=? ORDER BY TP.ID", $Permission ); + } + } +} \ No newline at end of file diff --git a/PhpRbac/Manager/RbacManager.php b/PhpRbac/Manager/RbacManager.php new file mode 100644 index 0000000..a315f97 --- /dev/null +++ b/PhpRbac/Manager/RbacManager.php @@ -0,0 +1,181 @@ +Users = new RbacUserManager (); + $this->Roles = new RoleManager (); + $this->Permissions = new PermissionManager (); + } + + /** + * + * @var \Jf\PermissionManager + */ + public $Permissions; + + /** + * + * @var \Jf\RoleManager + */ + public $Roles; + + /** + * + * @var \Jf\RbacUserManager + */ + public $Users; + + /** + * Assign a role to a permission. + * Alias for what's in the base class + * + * @param string|integer $Role + * Id, Title or Path + * @param string|integer $Permission + * Id, Title or Path + * @return boolean + */ + function assign($Role, $Permission) + { + return $this->Roles->assign($Role, $Permission); + } + + /** + * Prepared statement for check query + * + * @var BaseDatabaseStatement + */ + private $ps_Check = null; + + /** + * Checks whether a user has a permission or not. + * + * @param string|integer $Permission + * you can provide a path like /some/permission, a title, or the + * permission ID. + * in case of ID, don't forget to provide integer (not a string + * containing a number) + * @param string|integer $UserID + * User ID of a user + * + * @throws RbacPermissionNotFoundException + * @throws RbacUserNotProvidedException + * @return boolean + */ + function check($Permission, $UserID = null) + { + if ($UserID === null) + throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); + + // convert permission to ID + if (is_numeric ( $Permission )) + { + $PermissionID = $Permission; + } + else + { + if (substr ( $Permission, 0, 1 ) == "/") + $PermissionID = $this->Permissions->pathId ( $Permission ); + else + $PermissionID = $this->Permissions->titleId ( $Permission ); + } + + // if invalid, throw exception + if ($PermissionID === null) + throw new RbacPermissionNotFoundException ( "The permission '{$Permission}' not found." ); + + if ($this->isSQLite()) + { + $LastPart="AS Temp ON ( TR.ID = Temp.RoleID) + WHERE + TUrel.UserID=? + AND + Temp.ID=?"; + } + else //mysql + { + $LastPart="ON ( TR.ID = TRel.RoleID) + WHERE + TUrel.UserID=? + AND + TPdirect.ID=?"; + } + $Res=Jf::sql ( "SELECT COUNT(*) AS Result + FROM + {$this->tablePrefix()}userroles AS TUrel + + JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUrel.RoleID) + JOIN {$this->tablePrefix()}roles AS TR ON ( TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) + JOIN + ( {$this->tablePrefix()}permissions AS TPdirect + JOIN {$this->tablePrefix()}permissions AS TP ON ( TPdirect.Lft BETWEEN TP.Lft AND TP.Rght) + JOIN {$this->tablePrefix()}rolepermissions AS TRel ON (TP.ID=TRel.PermissionID) + ) $LastPart", + $UserID, $PermissionID ); + + return $Res [0] ['Result'] >= 1; + } + + /** + * Enforce a permission on a user + * + * @param string|integer $Permission + * path or title or ID of permission + * + * @param integer $UserID + * + * @throws RbacUserNotProvidedException + */ + function enforce($Permission, $UserID = null) + { + if ($UserID === null) + throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); + + if (! $this->check($Permission, $UserID)) { + header('HTTP/1.1 403 Forbidden'); + die("Forbidden: You do not have permission to access this resource."); + } + + return true; + } + + /** + * Remove all roles, permissions and assignments + * mostly used for testing + * + * @param boolean $Ensure + * must set or throws error + * @return boolean + */ + function reset($Ensure = false) + { + if ($Ensure !== true) { + throw new \Exception ("You must pass true to this function, otherwise it won't work."); + return; + } + + $res = true; + $res = $res and $this->Roles->resetAssignments ( true ); + $res = $res and $this->Roles->reset ( true ); + $res = $res and $this->Permissions->reset ( true ); + $res = $res and $this->Users->resetAssignments ( true ); + + return $res; + } +} \ No newline at end of file diff --git a/PhpRbac/Manager/RoleManager.php b/PhpRbac/Manager/RoleManager.php new file mode 100644 index 0000000..3e66d82 --- /dev/null +++ b/PhpRbac/Manager/RoleManager.php @@ -0,0 +1,153 @@ +type = "roles"; + $this->roles = new FullNestedSet ( $this->tablePrefix () . "roles", "ID", "Lft", "Rght" ); + } + + /** + * Remove roles from system + * + * @param integer $ID + * role id + * @param boolean $Recursive + * delete all descendants + * + */ + function remove($ID, $Recursive = false) + { + $this->unassignPermissions ( $ID ); + $this->unassignUsers ( $ID ); + if (! $Recursive) + return $this->roles->deleteConditional ( "ID=?", $ID ); + else + return $this->roles->deleteSubtreeConditional ( "ID=?", $ID ); + } + + /** + * Unassigns all permissions belonging to a role + * + * @param integer $ID + * role ID + * @return integer number of assignments deleted + */ + function unassignPermissions($ID) + { + $r = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE + RoleID=? ", $ID ); + return $r; + } + + /** + * Unassign all users that have a certain role + * + * @param integer $ID + * role ID + * @return integer number of deleted assignments + */ + function unassignUsers($ID) + { + return Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles WHERE + RoleID=?", $ID ); + } + + /** + * Checks to see if a role has a permission or not + * + * @param integer $Role + * ID + * @param integer $Permission + * ID + * @return boolean + * + * @todo: If we pass a Role that doesn't exist the method just returns false. We may want to check for a valid Role. + */ + function hasPermission($Role, $Permission) + { + $Res = Jf::sql ( " + SELECT COUNT(*) AS Result + FROM {$this->tablePrefix()}rolepermissions AS TRel + JOIN {$this->tablePrefix()}permissions AS TP ON ( TP.ID= TRel.PermissionID) + JOIN {$this->tablePrefix()}roles AS TR ON ( TR.ID = TRel.RoleID) + WHERE TR.Lft BETWEEN + (SELECT Lft FROM {$this->tablePrefix()}roles WHERE ID=?) + AND + (SELECT Rght FROM {$this->tablePrefix()}roles WHERE ID=?) + /* the above section means any row that is a descendants of our role (if descendant roles have some permission, then our role has it two) */ + AND TP.ID IN ( + SELECT parent.ID + FROM {$this->tablePrefix()}permissions AS node, + {$this->tablePrefix()}permissions AS parent + WHERE node.Lft BETWEEN parent.Lft AND parent.Rght + AND ( node.ID=? ) + ORDER BY parent.Lft + ); + /* + the above section returns all the parents of (the path to) our permission, so if one of our role or its descendants + has an assignment to any of them, we're good. + */ + ", $Role, $Role, $Permission ); + return $Res [0] ['Result'] >= 1; + } + + /** + * Returns all permissions assigned to a role + * + * @param integer $Role + * ID + * @param boolean $OnlyIDs + * if true, result would be a 1D array of IDs + * @return Array 2D or 1D or null + * the two dimensional array would have ID,Title and Description of permissions + */ + function permissions($Role, $OnlyIDs = true) + { + if (! is_numeric ($Role)) + $Role = $this->returnId($Role); + + if ($OnlyIDs) + { + $Res = Jf::sql ( "SELECT PermissionID AS `ID` FROM {$this->tablePrefix()}rolepermissions WHERE RoleID=? ORDER BY PermissionID", $Role ); + if (is_array ( $Res )) + { + $out = array (); + foreach ( $Res as $R ) + $out [] = $R ['ID']; + return $out; + } + else + return null; + } else { + return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}permissions AS `TP` + LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.PermissionID=`TP`.ID) + WHERE RoleID=? ORDER BY TP.ID", $Role ); + } + } +} \ No newline at end of file diff --git a/PhpRbac/Manager/UserManager.php b/PhpRbac/Manager/UserManager.php new file mode 100644 index 0000000..76fa56c --- /dev/null +++ b/PhpRbac/Manager/UserManager.php @@ -0,0 +1,185 @@ +Roles->pathId ( $Role ); + else + $RoleID = Jf::$Rbac->Roles->titleId ( $Role ); + } + + $R = Jf::sql ( "SELECT * FROM {$this->tablePrefix()}userroles AS TUR + JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUR.RoleID) + JOIN {$this->tablePrefix()}roles AS TR ON (TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) + + WHERE + TUR.UserID=? AND TR.ID=?", $UserID, $RoleID ); + return $R !== null; + } + + /** + * Assigns a role to a user + * + * @param mixed $Role + * Id, Path or Title + * @param integer $UserID + * UserID (use 0 for guest) + * + * @throws RbacUserNotProvidedException + * @return boolean inserted or existing + */ + function assign($Role, $UserID = null) + { + if ($UserID === null) + throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); + + if (is_numeric($Role)) + { + $RoleID = $Role; + } else { + if (substr($Role, 0, 1) == "/") + $RoleID = Jf::$Rbac->Roles->pathId($Role); + else + $RoleID = Jf::$Rbac->Roles->titleId($Role); + } + + $res = Jf::sql ( "INSERT INTO {$this->tablePrefix()}userroles + (UserID,RoleID,AssignmentDate) + VALUES (?,?,?) + ", $UserID, $RoleID, Jf::time () ); + return $res >= 1; + } + + /** + * Unassigns a role from a user + * + * @param mixed $Role + * Id, Title, Path + * @param integer $UserID + * UserID (use 0 for guest) + * + * @throws RbacUserNotProvidedException + * @return boolean success + */ + function unassign($Role, $UserID = null) + { + if ($UserID === null) + throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); + + if (is_numeric($Role)) + { + $RoleID = $Role; + + } else { + + if (substr($Role, 0, 1) == "/") + $RoleID = Jf::$Rbac->Roles->pathId($Role); + else + $RoleID = Jf::$Rbac->Roles->titleId($Role); + } + + return Jf::sql("DELETE FROM {$this->tablePrefix()}userroles WHERE UserID=? AND RoleID=?", $UserID, $RoleID) >= 1; + } + + /** + * Returns all roles of a user + * + * @param integer $UserID + * Not optional + * + * @throws RbacUserNotProvidedException + * @return array null + * + */ + function allRoles($UserID = null) + { + if ($UserID === null) + throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); + + return Jf::sql ( "SELECT TR.* + FROM + {$this->tablePrefix()}userroles AS `TRel` + JOIN {$this->tablePrefix()}roles AS `TR` ON + (`TRel`.RoleID=`TR`.ID) + WHERE TRel.UserID=?", $UserID ); + } + + /** + * Return count of roles assigned to a user + * + * @param integer $UserID + * + * @throws RbacUserNotProvidedException + * @return integer Count of Roles assigned to a User + */ + function roleCount($UserID = null) + { + if ($UserID === null) + throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); + + $Res = Jf::sql ( "SELECT COUNT(*) AS Result FROM {$this->tablePrefix()}userroles WHERE UserID=?", $UserID ); + return (int)$Res [0] ['Result']; + } + + /** + * Remove all role-user relations + * mostly used for testing + * + * @param boolean $Ensure + * must set to true or throws an Exception + * @return number of deleted relations + */ + function resetAssignments($Ensure = false) + { + if ($Ensure !== true) + { + throw new \Exception ("You must pass true to this function, otherwise it won't work."); + return; + } + $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles" ); + + $Adapter = get_class(Jf::$Db); + if ($this->isMySql()) + Jf::sql ( "ALTER TABLE {$this->tablePrefix()}userroles AUTO_INCREMENT =1 " ); + elseif ($this->isSQLite()) + Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_userroles" ); + else + throw new \Exception ("Rbac can not reset table on this type of database: {$Adapter}"); + $this->assign ( "root", 1 /* root user */ ); + return $res; + } +} diff --git a/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php b/PhpRbac/NestedSet/BaseNestedSet.php similarity index 95% rename from PhpRbac/src/PhpRbac/core/lib/nestedset/base.php rename to PhpRbac/NestedSet/BaseNestedSet.php index 4bf64df..92f4c78 100644 --- a/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php +++ b/PhpRbac/NestedSet/BaseNestedSet.php @@ -1,26 +1,4 @@ \ No newline at end of file +} \ No newline at end of file diff --git a/PhpRbac/NestedSet/ExtendedNestedSetInterface.php b/PhpRbac/NestedSet/ExtendedNestedSetInterface.php new file mode 100644 index 0000000..410112b --- /dev/null +++ b/PhpRbac/NestedSet/ExtendedNestedSetInterface.php @@ -0,0 +1,24 @@ + \ No newline at end of file +} \ No newline at end of file diff --git a/PhpRbac/NestedSet/NestedSetInterface.php b/PhpRbac/NestedSet/NestedSetInterface.php new file mode 100644 index 0000000..719d6df --- /dev/null +++ b/PhpRbac/NestedSet/NestedSetInterface.php @@ -0,0 +1,22 @@ +getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite"; - } - protected function isMySql() - { - $Adapter=get_class(Jf::$Db); - return $Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql"); - } -} - -/** - * Rbac base class, it contains operations that are essentially the same for - * permissions and roles - * and is inherited by both - * - * @author abiusx - * @version 1.0 - */ -abstract class BaseRbac extends JModel -{ - - function rootId() - { - return 1; - } - - /** - * Return type of current instance, e.g roles, permissions - * - * @return string - */ - abstract protected function type(); - - /** - * Adds a new role or permission - * Returns new entry's ID - * - * @param string $Title - * Title of the new entry - * @param string $Description - * Description of the new entry - * @param integer $ParentID - * optional ID of the parent node in the hierarchy - * @return integer ID of the new entry - */ - function add($Title, $Description, $ParentID = null) - { - if ($ParentID === null) - $ParentID = $this->rootId (); - return (int)$this->{$this->type ()}->insertChildData ( array ("Title" => $Title, "Description" => $Description ), "ID=?", $ParentID ); - } - - /** - * Adds a path and all its components. - * Will not replace or create siblings if a component exists. - * - * @param string $Path - * such as /some/role/some/where - Must begin with a / (slash) - * @param array $Descriptions - * array of descriptions (will add with empty description if not available) - * - * @return integer Number of nodes created (0 if none created) - */ - function addPath($Path, array $Descriptions = null) - { - if ($Path[0] !== "/") - throw new \Exception ("The path supplied is not valid."); - - $Path = substr ( $Path, 1 ); - $Parts = explode ( "/", $Path ); - $Parent = 1; - $index = 0; - $CurrentPath = ""; - $NodesCreated = 0; - - foreach ($Parts as $p) - { - if (isset ($Descriptions[$index])) - $Description = $Descriptions[$index]; - else - $Description = ""; - $CurrentPath .= "/{$p}"; - $t = $this->pathId($CurrentPath); - if (! $t) - { - $IID = $this->add($p, $Description, $Parent); - $Parent = $IID; - $NodesCreated++; - } - else - { - $Parent = $t; - } - - $index += 1; - } - - return (int)$NodesCreated; - } - - /** - * Return count of the entity - * - * @return integer - */ - function count() - { - $Res = Jf::sql ( "SELECT COUNT(*) FROM {$this->tablePrefix()}{$this->type()}" ); - return (int)$Res [0] ['COUNT(*)']; - } - - /** - * Returns ID of entity - * - * @param string $entity (Path or Title) - * - * @return mixed ID of entity or null - */ - public function returnId($entity = null) - { - if (substr ($entity, 0, 1) == "/") { - $entityID = $this->pathId($entity); - } else { - $entityID = $this->titleId($entity); - } - - return $entityID; - } - - /** - * Returns ID of a path - * - * @todo this has a limit of 1000 characters on $Path - * @param string $Path - * such as /role1/role2/role3 ( a single slash is root) - * @return integer NULL - */ - public function pathId($Path) - { - $Path = "root" . $Path; - - if ($Path [strlen ( $Path ) - 1] == "/") - $Path = substr ( $Path, 0, strlen ( $Path ) - 1 ); - $Parts = explode ( "/", $Path ); - - $Adapter = get_class(Jf::$Db); - if ($Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql")) { - $GroupConcat="GROUP_CONCAT(parent.Title ORDER BY parent.Lft SEPARATOR '/')"; - } elseif ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite") { - $GroupConcat="GROUP_CONCAT(parent.Title,'/')"; - } else { - throw new \Exception ("Unknown Group_Concat on this type of database: {$Adapter}"); - } - - $res = Jf::sql ( "SELECT node.ID,{$GroupConcat} AS Path - FROM {$this->tablePrefix()}{$this->type()} AS node, - {$this->tablePrefix()}{$this->type()} AS parent - WHERE node.Lft BETWEEN parent.Lft AND parent.Rght - AND node.Title=? - GROUP BY node.ID - HAVING Path = ? - ", $Parts [count ( $Parts ) - 1], $Path ); - - if ($res) - return $res [0] ['ID']; - else - return null; - // TODO: make the below SQL work, so that 1024 limit is over - - $QueryBase = ("SELECT n0.ID \nFROM {$this->tablePrefix()}{$this->type()} AS n0"); - $QueryCondition = "\nWHERE n0.Title=?"; - - for($i = 1; $i < count ( $Parts ); ++ $i) - { - $j = $i - 1; - $QueryBase .= "\nJOIN {$this->tablePrefix()}{$this->type()} AS n{$i} ON (n{$j}.Lft BETWEEN n{$i}.Lft+1 AND n{$i}.Rght)"; - $QueryCondition .= "\nAND n{$i}.Title=?"; - // Forcing middle elements - $QueryBase .= "\nLEFT JOIN {$this->tablePrefix()}{$this->type()} AS nn{$i} ON (nn{$i}.Lft BETWEEN n{$i}.Lft+1 AND n{$j}.Lft-1)"; - $QueryCondition .= "\nAND nn{$i}.Lft IS NULL"; - } - $Query = $QueryBase . $QueryCondition; - $PartsRev = array_reverse ( $Parts ); - array_unshift ( $PartsRev, $Query ); - - print_ ( $PartsRev ); - $res = call_user_func_array ( "Jf::sql", $PartsRev ); - - if ($res) - return $res [0] ['ID']; - else - return null; - } - - /** - * Returns ID belonging to a title, and the first one on that - * - * @param string $Title - * @return integer Id of specified Title - */ - public function titleId($Title) - { - return $this->{$this->type ()}->getID ( "Title=?", $Title ); - } - - /** - * Return the whole record of a single entry (including Rght and Lft fields) - * - * @param integer $ID - */ - protected function getRecord($ID) - { - $args = func_get_args (); - return call_user_func_array ( array ($this->{$this->type ()}, "getRecord" ), $args ); - } - - /** - * Returns title of entity - * - * @param integer $ID - * @return string NULL - */ - function getTitle($ID) - { - $r = $this->getRecord ( "ID=?", $ID ); - if ($r) - return $r ['Title']; - else - return null; - } - - /** - * Returns path of a node - * - * @param integer $ID - * @return string path - */ - function getPath($ID) - { - $res = $this->{$this->type ()}->pathConditional ( "ID=?", $ID ); - $out = null; - if (is_array ( $res )) - foreach ( $res as $r ) - if ($r ['ID'] == 1) - $out = '/'; - else - $out .= "/" . $r ['Title']; - if (strlen ( $out ) > 1) - return substr ( $out, 1 ); - else - return $out; - } - - /** - * Return description of entity - * - * @param integer $ID - * @return string NULL - */ - function getDescription($ID) - { - $r = $this->getRecord ( "ID=?", $ID ); - if ($r) - return $r ['Description']; - else - return null; - } - - /** - * Edits an entity, changing title and/or description. Maintains Id. - * - * @param integer $ID - * @param string $NewTitle - * @param string $NewDescription - * - */ - function edit($ID, $NewTitle = null, $NewDescription = null) - { - $Data = array (); - - if ($NewTitle !== null) - $Data ['Title'] = $NewTitle; - - if ($NewDescription !== null) - $Data ['Description'] = $NewDescription; - - return $this->{$this->type ()}->editData ( $Data, "ID=?", $ID ) == 1; - } - - /** - * Returns children of an entity - * - * @param integer $ID - * @return array - * - */ - function children($ID) - { - return $this->{$this->type ()}->childrenConditional ( "ID=?", $ID ); - } - - /** - * Returns descendants of a node, with their depths in integer - * - * @param integer $ID - * @return array with keys as titles and Title,ID, Depth and Description - * - */ - function descendants($ID) - { - $res = $this->{$this->type ()}->descendantsConditional(/* absolute depths*/false, "ID=?", $ID ); - $out = array (); - if (is_array ( $res )) - foreach ( $res as $v ) - $out [$v ['Title']] = $v; - return $out; - } - - /** - * Return depth of a node - * - * @param integer $ID - */ - function depth($ID) - { - return $this->{$this->type ()}->depthConditional ( "ID=?", $ID ); - } - - /** - * Returns parent of a node - * - * @param integer $ID - * @return array including Title, Description and ID - * - */ - function parentNode($ID) - { - return $this->{$this->type ()}->parentNodeConditional ( "ID=?", $ID ); - } - - /** - * Reset the table back to its initial state - * Keep in mind that this will not touch relations - * - * @param boolean $Ensure - * must be true to work, otherwise an \Exception is thrown - * @throws \Exception - * @return integer number of deleted entries - * - */ - function reset($Ensure = false) - { - if ($Ensure !== true) - { - throw new \Exception ("You must pass true to this function, otherwise it won't work."); - return; - } - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}{$this->type()}" ); - $Adapter = get_class(Jf::$Db); - if ($this->isMySql()) - Jf::sql ( "ALTER TABLE {$this->tablePrefix()}{$this->type()} AUTO_INCREMENT=1 " ); - elseif ($this->isSQLite()) - Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "{$this->type()}" ); - else - throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" ); - $iid = Jf::sql ( "INSERT INTO {$this->tablePrefix()}{$this->type()} (Title,Description,Lft,Rght) VALUES (?,?,?,?)", "root", "root",0,1 ); - return (int)$res; - } - - /** - * Assigns a role to a permission (or vice-verse) - * - * @param mixed $Role - * Id, Title and Path - * @param mixed $Permission - * Id, Title and Path - * @return boolean inserted or existing - * - * @todo: Check for valid permissions/roles - * @todo: Implement custom error handler - */ - function assign($Role, $Permission) - { - if (is_numeric($Role)) - { - $RoleID = $Role; - } else { - if (substr($Role, 0, 1) == "/") - $RoleID = Jf::$Rbac->Roles->pathId($Role); - else - $RoleID = Jf::$Rbac->Roles->titleId($Role); - } - - if (is_numeric($Permission)) - { - $PermissionID = $Permission; - } else { - if (substr($Permission, 0, 1) == "/") - $PermissionID = Jf::$Rbac->Permissions->pathId($Permission); - else - $PermissionID = Jf::$Rbac->Permissions->titleId($Permission); - } - - return Jf::sql("INSERT INTO {$this->tablePrefix()}rolepermissions - (RoleID,PermissionID,AssignmentDate) - VALUES (?,?,?)", $RoleID, $PermissionID, Jf::time()) >= 1; - } - - /** - * Unassigns a role-permission relation - * - * @param mixed $Role - * Id, Title and Path - * @param mixed $Permission: - * Id, Title and Path - * @return boolean - */ - function unassign($Role, $Permission) - { - if (is_numeric($Role)) - { - $RoleID = $Role; - } else { - if (substr($Role, 0, 1) == "/") - $RoleID = Jf::$Rbac->Roles->pathId($Role); - else - $RoleID = Jf::$Rbac->Roles->titleId($Role); - } - - if (is_numeric($Permission)) - { - $PermissionID = $Permission; - } else { - if (substr($Permission, 0, 1) == "/") - $PermissionID = Jf::$Rbac->Permissions->pathId($Permission); - else - $PermissionID = Jf::$Rbac->Permissions->titleId($Permission); - } - - return Jf::sql("DELETE FROM {$this->tablePrefix()}rolepermissions WHERE - RoleID=? AND PermissionID=?", $RoleID, $PermissionID) == 1; - } - - /** - * Remove all role-permission relations - * mostly used for testing - * - * @param boolean $Ensure - * must be set to true or throws an \Exception - * @return number of deleted assignments - */ - function resetAssignments($Ensure = false) - { - if ($Ensure !== true) - { - throw new \Exception ("You must pass true to this function, otherwise it won't work."); - return; - } - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions" ); - - $Adapter = get_class(Jf::$Db); - if ($this->isMySql()) - Jf::sql ( "ALTER TABLE {$this->tablePrefix()}rolepermissions AUTO_INCREMENT =1 " ); - elseif ($this->isSQLite()) - Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_rolepermissions" ); - else - throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" ); - $this->assign ( $this->rootId(), $this->rootId()); - return $res; - } -} - -/** - * @defgroup phprbac_manager Documentation regarding Rbac Manager Functionality - * @ingroup phprbac - * @{ - * - * Documentation regarding Rbac Manager functionality. - * - * Rbac Manager: Provides NIST Level 2 Standard Hierarchical Role Based Access Control - * - * Has three members, Roles, Users and Permissions for specific operations - * - * @author abiusx - * @version 1.0 - */ -class RbacManager extends JModel -{ - function __construct() - { - $this->Users = new RbacUserManager (); - $this->Roles = new RoleManager (); - $this->Permissions = new PermissionManager (); - } - - /** - * - * @var \Jf\PermissionManager - */ - public $Permissions; - - /** - * - * @var \Jf\RoleManager - */ - public $Roles; - - /** - * - * @var \Jf\RbacUserManager - */ - public $Users; - - /** - * Assign a role to a permission. - * Alias for what's in the base class - * - * @param string|integer $Role - * Id, Title or Path - * @param string|integer $Permission - * Id, Title or Path - * @return boolean - */ - function assign($Role, $Permission) - { - return $this->Roles->assign($Role, $Permission); - } - - /** - * Prepared statement for check query - * - * @var BaseDatabaseStatement - */ - private $ps_Check = null; - - /** - * Checks whether a user has a permission or not. - * - * @param string|integer $Permission - * you can provide a path like /some/permission, a title, or the - * permission ID. - * in case of ID, don't forget to provide integer (not a string - * containing a number) - * @param string|integer $UserID - * User ID of a user - * - * @throws RbacPermissionNotFoundException - * @throws RbacUserNotProvidedException - * @return boolean - */ - function check($Permission, $UserID = null) - { - if ($UserID === null) - throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); - - // convert permission to ID - if (is_numeric ( $Permission )) - { - $PermissionID = $Permission; - } - else - { - if (substr ( $Permission, 0, 1 ) == "/") - $PermissionID = $this->Permissions->pathId ( $Permission ); - else - $PermissionID = $this->Permissions->titleId ( $Permission ); - } - - // if invalid, throw exception - if ($PermissionID === null) - throw new RbacPermissionNotFoundException ( "The permission '{$Permission}' not found." ); - - if ($this->isSQLite()) - { - $LastPart="AS Temp ON ( TR.ID = Temp.RoleID) - WHERE - TUrel.UserID=? - AND - Temp.ID=?"; - } - else //mysql - { - $LastPart="ON ( TR.ID = TRel.RoleID) - WHERE - TUrel.UserID=? - AND - TPdirect.ID=?"; - } - $Res=Jf::sql ( "SELECT COUNT(*) AS Result - FROM - {$this->tablePrefix()}userroles AS TUrel - - JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUrel.RoleID) - JOIN {$this->tablePrefix()}roles AS TR ON ( TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) - JOIN - ( {$this->tablePrefix()}permissions AS TPdirect - JOIN {$this->tablePrefix()}permissions AS TP ON ( TPdirect.Lft BETWEEN TP.Lft AND TP.Rght) - JOIN {$this->tablePrefix()}rolepermissions AS TRel ON (TP.ID=TRel.PermissionID) - ) $LastPart", - $UserID, $PermissionID ); - - return $Res [0] ['Result'] >= 1; - } - - /** - * Enforce a permission on a user - * - * @param string|integer $Permission - * path or title or ID of permission - * - * @param integer $UserID - * - * @throws RbacUserNotProvidedException - */ - function enforce($Permission, $UserID = null) - { - if ($UserID === null) - throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); - - if (! $this->check($Permission, $UserID)) { - header('HTTP/1.1 403 Forbidden'); - die("Forbidden: You do not have permission to access this resource."); - } - - return true; - } - - /** - * Remove all roles, permissions and assignments - * mostly used for testing - * - * @param boolean $Ensure - * must set or throws error - * @return boolean - */ - function reset($Ensure = false) - { - if ($Ensure !== true) { - throw new \Exception ("You must pass true to this function, otherwise it won't work."); - return; - } - - $res = true; - $res = $res and $this->Roles->resetAssignments ( true ); - $res = $res and $this->Roles->reset ( true ); - $res = $res and $this->Permissions->reset ( true ); - $res = $res and $this->Users->resetAssignments ( true ); - - return $res; - } -} - -/** @} */ // End group phprbac_manager */ - -/** - * @defgroup phprbac_permission_manager Documentation regarding Permission Manager Functionality - * @ingroup phprbac - * @{ - * - * Documentation regarding Permission Manager functionality. - * - * Permission Manager: Contains functionality specific to Permissions - * - * @author abiusx - * @version 1.0 - */ -class PermissionManager extends BaseRbac -{ - /** - * Permissions Nested Set - * - * @var FullNestedSet - */ - protected $permissions; - - protected function type() - { - return "permissions"; - } - - function __construct() - { - $this->permissions = new FullNestedSet ( $this->tablePrefix () . "permissions", "ID", "Lft", "Rght" ); - } - - /** - * Remove permissions from system - * - * @param integer $ID - * permission id - * @param boolean $Recursive - * delete all descendants - * - */ - function remove($ID, $Recursive = false) - { - $this->unassignRoles ( $ID ); - if (! $Recursive) - return $this->permissions->deleteConditional ( "ID=?", $ID ); - else - return $this->permissions->deleteSubtreeConditional ( "ID=?", $ID ); - } - - /** - * Unassignes all roles of this permission, and returns their number - * - * @param integer $ID - * Permission Id - * @return integer - */ - function unassignRoles($ID) - { - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE - PermissionID=?", $ID ); - return (int)$res; - } - - /** - * Returns all roles assigned to a permission - * - * @param mixed $Permission - * Id, Title, Path - * @param boolean $OnlyIDs - * if true, result will be a 1D array of IDs - * @return Array 2D or 1D or null - */ - function roles($Permission, $OnlyIDs = true) - { - if (!is_numeric($Permission)) - $Permission = $this->returnId($Permission); - - if ($OnlyIDs) - { - $Res = Jf::sql ( "SELECT RoleID AS `ID` FROM - {$this->tablePrefix()}rolepermissions WHERE PermissionID=? ORDER BY RoleID", $Permission ); - - if (is_array ( $Res )) - { - $out = array (); - foreach ( $Res as $R ) - $out [] = $R ['ID']; - return $out; - } - else - return null; - } else { - return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}roles AS `TP` - LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.RoleID=`TP`.ID) - WHERE PermissionID=? ORDER BY TP.ID", $Permission ); - } - } -} - -/** @} */ // End group phprbac_permission_manager */ - -/** - * @defgroup phprbac_role_manager Documentation regarding Role Manager Functionality - * @ingroup phprbac - * @{ - * - * Documentation regarding Role Manager functionality. - * - * Role Manager: Contains functionality specific to Roles - * - * @author abiusx - * @version 1.0 - */ -class RoleManager extends BaseRbac -{ - /** - * Roles Nested Set - * - * @var FullNestedSet - */ - protected $roles = null; - - protected function type() - { - return "roles"; - } - - function __construct() - { - $this->type = "roles"; - $this->roles = new FullNestedSet ( $this->tablePrefix () . "roles", "ID", "Lft", "Rght" ); - } - - /** - * Remove roles from system - * - * @param integer $ID - * role id - * @param boolean $Recursive - * delete all descendants - * - */ - function remove($ID, $Recursive = false) - { - $this->unassignPermissions ( $ID ); - $this->unassignUsers ( $ID ); - if (! $Recursive) - return $this->roles->deleteConditional ( "ID=?", $ID ); - else - return $this->roles->deleteSubtreeConditional ( "ID=?", $ID ); - } - - /** - * Unassigns all permissions belonging to a role - * - * @param integer $ID - * role ID - * @return integer number of assignments deleted - */ - function unassignPermissions($ID) - { - $r = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE - RoleID=? ", $ID ); - return $r; - } - - /** - * Unassign all users that have a certain role - * - * @param integer $ID - * role ID - * @return integer number of deleted assignments - */ - function unassignUsers($ID) - { - return Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles WHERE - RoleID=?", $ID ); - } - - /** - * Checks to see if a role has a permission or not - * - * @param integer $Role - * ID - * @param integer $Permission - * ID - * @return boolean - * - * @todo: If we pass a Role that doesn't exist the method just returns false. We may want to check for a valid Role. - */ - function hasPermission($Role, $Permission) - { - $Res = Jf::sql ( " - SELECT COUNT(*) AS Result - FROM {$this->tablePrefix()}rolepermissions AS TRel - JOIN {$this->tablePrefix()}permissions AS TP ON ( TP.ID= TRel.PermissionID) - JOIN {$this->tablePrefix()}roles AS TR ON ( TR.ID = TRel.RoleID) - WHERE TR.Lft BETWEEN - (SELECT Lft FROM {$this->tablePrefix()}roles WHERE ID=?) - AND - (SELECT Rght FROM {$this->tablePrefix()}roles WHERE ID=?) - /* the above section means any row that is a descendants of our role (if descendant roles have some permission, then our role has it two) */ - AND TP.ID IN ( - SELECT parent.ID - FROM {$this->tablePrefix()}permissions AS node, - {$this->tablePrefix()}permissions AS parent - WHERE node.Lft BETWEEN parent.Lft AND parent.Rght - AND ( node.ID=? ) - ORDER BY parent.Lft - ); - /* - the above section returns all the parents of (the path to) our permission, so if one of our role or its descendants - has an assignment to any of them, we're good. - */ - ", $Role, $Role, $Permission ); - return $Res [0] ['Result'] >= 1; - } - - /** - * Returns all permissions assigned to a role - * - * @param integer $Role - * ID - * @param boolean $OnlyIDs - * if true, result would be a 1D array of IDs - * @return Array 2D or 1D or null - * the two dimensional array would have ID,Title and Description of permissions - */ - function permissions($Role, $OnlyIDs = true) - { - if (! is_numeric ($Role)) - $Role = $this->returnId($Role); - - if ($OnlyIDs) - { - $Res = Jf::sql ( "SELECT PermissionID AS `ID` FROM {$this->tablePrefix()}rolepermissions WHERE RoleID=? ORDER BY PermissionID", $Role ); - if (is_array ( $Res )) - { - $out = array (); - foreach ( $Res as $R ) - $out [] = $R ['ID']; - return $out; - } - else - return null; - } else { - return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}permissions AS `TP` - LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.PermissionID=`TP`.ID) - WHERE RoleID=? ORDER BY TP.ID", $Role ); - } - } -} - -/** @} */ // End group phprbac_role_manager */ - -/** - * @defgroup phprbac_user_manager Documentation regarding Rbac User Manager Functionality - * @ingroup phprbac - * @{ - * - * Documentation regarding Rbac User Manager functionality. - * - * Rbac User Manager: Contains functionality specific to Users - * - * @author abiusx - * @version 1.0 - */ -class RbacUserManager extends JModel -{ - /** - * Checks to see whether a user has a role or not - * - * @param integer|string $Role - * id, title or path - * @param integer $User - * UserID, not optional - * - * @throws RbacUserNotProvidedException - * @return boolean success - */ - function hasRole($Role, $UserID = null) - { - if ($UserID === null) - throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); - - if (is_numeric ( $Role )) - { - $RoleID = $Role; - } - else - { - if (substr ( $Role, 0, 1 ) == "/") - $RoleID = Jf::$Rbac->Roles->pathId ( $Role ); - else - $RoleID = Jf::$Rbac->Roles->titleId ( $Role ); - } - - $R = Jf::sql ( "SELECT * FROM {$this->tablePrefix()}userroles AS TUR - JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUR.RoleID) - JOIN {$this->tablePrefix()}roles AS TR ON (TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) - - WHERE - TUR.UserID=? AND TR.ID=?", $UserID, $RoleID ); - return $R !== null; - } - - /** - * Assigns a role to a user - * - * @param mixed $Role - * Id, Path or Title - * @param integer $UserID - * UserID (use 0 for guest) - * - * @throws RbacUserNotProvidedException - * @return boolean inserted or existing - */ - function assign($Role, $UserID = null) - { - if ($UserID === null) - throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); - - if (is_numeric($Role)) - { - $RoleID = $Role; - } else { - if (substr($Role, 0, 1) == "/") - $RoleID = Jf::$Rbac->Roles->pathId($Role); - else - $RoleID = Jf::$Rbac->Roles->titleId($Role); - } - - $res = Jf::sql ( "INSERT INTO {$this->tablePrefix()}userroles - (UserID,RoleID,AssignmentDate) - VALUES (?,?,?) - ", $UserID, $RoleID, Jf::time () ); - return $res >= 1; - } - - /** - * Unassigns a role from a user - * - * @param mixed $Role - * Id, Title, Path - * @param integer $UserID - * UserID (use 0 for guest) - * - * @throws RbacUserNotProvidedException - * @return boolean success - */ - function unassign($Role, $UserID = null) - { - if ($UserID === null) - throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); - - if (is_numeric($Role)) - { - $RoleID = $Role; - - } else { - - if (substr($Role, 0, 1) == "/") - $RoleID = Jf::$Rbac->Roles->pathId($Role); - else - $RoleID = Jf::$Rbac->Roles->titleId($Role); - } - - return Jf::sql("DELETE FROM {$this->tablePrefix()}userroles WHERE UserID=? AND RoleID=?", $UserID, $RoleID) >= 1; - } - - /** - * Returns all roles of a user - * - * @param integer $UserID - * Not optional - * - * @throws RbacUserNotProvidedException - * @return array null - * - */ - function allRoles($UserID = null) - { - if ($UserID === null) - throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); - - return Jf::sql ( "SELECT TR.* - FROM - {$this->tablePrefix()}userroles AS `TRel` - JOIN {$this->tablePrefix()}roles AS `TR` ON - (`TRel`.RoleID=`TR`.ID) - WHERE TRel.UserID=?", $UserID ); - } - - /** - * Return count of roles assigned to a user - * - * @param integer $UserID - * - * @throws RbacUserNotProvidedException - * @return integer Count of Roles assigned to a User - */ - function roleCount($UserID = null) - { - if ($UserID === null) - throw new \RbacUserNotProvidedException ("\$UserID is a required argument."); - - $Res = Jf::sql ( "SELECT COUNT(*) AS Result FROM {$this->tablePrefix()}userroles WHERE UserID=?", $UserID ); - return (int)$Res [0] ['Result']; - } - - /** - * Remove all role-user relations - * mostly used for testing - * - * @param boolean $Ensure - * must set to true or throws an Exception - * @return number of deleted relations - */ - function resetAssignments($Ensure = false) - { - if ($Ensure !== true) - { - throw new \Exception ("You must pass true to this function, otherwise it won't work."); - return; - } - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles" ); - - $Adapter = get_class(Jf::$Db); - if ($this->isMySql()) - Jf::sql ( "ALTER TABLE {$this->tablePrefix()}userroles AUTO_INCREMENT =1 " ); - elseif ($this->isSQLite()) - Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_userroles" ); - else - throw new \Exception ("Rbac can not reset table on this type of database: {$Adapter}"); - $this->assign ( "root", 1 /* root user */ ); - return $res; - } -} - -/** @} */ // End group phprbac_user_manager */ From d58501a91ed1f30d1ba1f354b7f4e2831904e715 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Fri, 9 Jan 2015 16:01:27 +0100 Subject: [PATCH 07/57] Add namespaces to the class files --- PhpRbac/Database/JModel.php | 6 ++++-- PhpRbac/Database/Jf.php | 8 ++++++-- PhpRbac/Exception/RbacException.php | 2 ++ .../RbacPermissionNotFoundException.php | 2 ++ PhpRbac/Exception/RbacRoleNotFoundException.php | 2 ++ .../Exception/RbacUserNotProvidedException.php | 2 ++ PhpRbac/Manager/BaseRbacManager.php | 4 ++++ PhpRbac/Manager/PermissionManager.php | 5 ++++- PhpRbac/Manager/RbacManager.php | 11 +++++++++-- .../{UserManager.php => RbacUserManager.php} | 17 ++++++++++++----- PhpRbac/Manager/RoleManager.php | 7 ++++++- PhpRbac/NestedSet/BaseNestedSet.php | 4 ++++ .../NestedSet/ExtendedNestedSetInterface.php | 3 ++- PhpRbac/NestedSet/FullNestedSet.php | 4 ++++ PhpRbac/NestedSet/NestedSetInterface.php | 2 ++ PhpRbac/Rbac.php | 9 ++++----- 16 files changed, 69 insertions(+), 19 deletions(-) rename PhpRbac/Manager/{UserManager.php => RbacUserManager.php} (88%) diff --git a/PhpRbac/Database/JModel.php b/PhpRbac/Database/JModel.php index d98f7b8..75f1aa9 100644 --- a/PhpRbac/Database/JModel.php +++ b/PhpRbac/Database/JModel.php @@ -1,5 +1,7 @@ getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite"; + return $Adapter == "PDO" and Jf::$Db->getAttribute(\PDO::ATTR_DRIVER_NAME)=="sqlite"; } protected function isMySql() { $Adapter=get_class(Jf::$Db); - return $Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql"); + return $Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(\PDO::ATTR_DRIVER_NAME)=="mysql"); } } \ No newline at end of file diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index 7ab9579..896808e 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -1,5 +1,9 @@ query ( $Query ); if ($result===false) return null; - $res=$result->fetchAll ( PDO::FETCH_ASSOC ); + $res=$result->fetchAll ( \PDO::FETCH_ASSOC ); if ($res===array()) return null; return $res; @@ -104,7 +108,7 @@ static function sqlPdo($Query) return $stmt->rowCount(); elseif ($type == "SELECT") { - $res=$stmt->fetchAll ( PDO::FETCH_ASSOC ); + $res=$stmt->fetchAll ( \PDO::FETCH_ASSOC ); if ($res===array()) return null; else diff --git a/PhpRbac/Exception/RbacException.php b/PhpRbac/Exception/RbacException.php index 6210951..b3835fe 100644 --- a/PhpRbac/Exception/RbacException.php +++ b/PhpRbac/Exception/RbacException.php @@ -1,5 +1,7 @@ check($Permission, $UserID)) { header('HTTP/1.1 403 Forbidden'); diff --git a/PhpRbac/Manager/UserManager.php b/PhpRbac/Manager/RbacUserManager.php similarity index 88% rename from PhpRbac/Manager/UserManager.php rename to PhpRbac/Manager/RbacUserManager.php index 76fa56c..decba17 100644 --- a/PhpRbac/Manager/UserManager.php +++ b/PhpRbac/Manager/RbacUserManager.php @@ -1,5 +1,12 @@ tablePrefix()}userroles WHERE UserID=?", $UserID ); return (int)$Res [0] ['Result']; diff --git a/PhpRbac/Manager/RoleManager.php b/PhpRbac/Manager/RoleManager.php index 3e66d82..bf5f47c 100644 --- a/PhpRbac/Manager/RoleManager.php +++ b/PhpRbac/Manager/RoleManager.php @@ -1,4 +1,9 @@ Permissions = Jf::$Rbac->Permissions; $this->Roles = Jf::$Rbac->Roles; $this->Users = Jf::$Rbac->Users; From 8b92561bfcd1aee0d561be098eeba206de357e83 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Fri, 9 Jan 2015 16:02:05 +0100 Subject: [PATCH 08/57] Update autoload parameters and gitignore --- .gitignore | 3 ++- composer.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d1c47ff..9309bde 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ *phprbac.sqlite3* *Doxygen* *phpdoc* -/nbproject/ \ No newline at end of file +/nbproject/ +/vendor/ \ No newline at end of file diff --git a/composer.json b/composer.json index e79fddb..bff0021 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ ], "autoload" : { "psr-0" : { - "PhpRbac" : "PhpRbac/src" + "PhpRbac" : "" } }, "repositories" : [{ From 0739b5aa5d673f5c64b024f6e0c05fd72bb6a91a Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Mon, 12 Jan 2015 10:20:50 +0100 Subject: [PATCH 09/57] Remove old config and set a config JSON file instead --- PhpRbac/Database/JModel.php | 8 +- PhpRbac/Database/Jf.php | 25 ++++-- PhpRbac/Database/database.config | 13 ---- PhpRbac/Database/database_config.json | 8 ++ PhpRbac/Manager/BaseRbacManager.php | 37 ++++----- PhpRbac/Manager/PermissionManager.php | 51 +++++++------ PhpRbac/Manager/RbacManager.php | 13 ++-- PhpRbac/Manager/RbacUserManager.php | 32 ++++---- PhpRbac/Manager/RoleManager.php | 97 +++++++++++------------ PhpRbac/NestedSet/FullNestedSet.php | 4 +- PhpRbac/Rbac.php | 106 ++++++++++++-------------- PhpRbac/index.php | 2 +- PhpRbac/setup.php | 8 ++ 13 files changed, 210 insertions(+), 194 deletions(-) delete mode 100644 PhpRbac/Database/database.config create mode 100644 PhpRbac/Database/database_config.json diff --git a/PhpRbac/Database/JModel.php b/PhpRbac/Database/JModel.php index eb4d66a..d791f4b 100644 --- a/PhpRbac/Database/JModel.php +++ b/PhpRbac/Database/JModel.php @@ -4,16 +4,12 @@ class JModel { - function tablePrefix() - { - return Jf::tablePrefix(); - } protected function isSQLite() { - return Jf::$Db instanceof \PDO && Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite"; + return Jf::$Db instanceof \PDO && Jf::$Db->getAttribute(\PDO::ATTR_DRIVER_NAME)=="sqlite"; } protected function isMySql() { - return Jf::$Db instanceof mysqli || (Jf::$Db instanceof \PDO && Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql"); + return Jf::$Db instanceof \mysqli || (Jf::$Db instanceof \PDO && Jf::$Db->getAttribute(\PDO::ATTR_DRIVER_NAME)=="mysql"); } } \ No newline at end of file diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index 87db286..027aaee 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -13,19 +13,28 @@ class Jf public static $Db = null; - public static $TABLE_PREFIX; - private static $groupConcatLimitChanged = false; + + private static $config; public static function setTablePrefix($tablePrefix) { self::$TABLE_PREFIX = $tablePrefix; } - - public static function tablePrefix() - { - return self::$TABLE_PREFIX; - } + + public static function loadConfig($file) + { + self::$config = json_decode(file_get_contents($file), true); + } + + public static function getConfig($key) + { + if(!isset(self::$config[$key])) + { + throw new \InvalidArgumentException("$key is not a valid configuration"); + } + return self::$config[$key]; + } /** * The Jf::sql function. The behavior of this function is as follows: @@ -205,6 +214,6 @@ static function time() } } -Jf::setTablePrefix($tablePrefix); +Jf::loadConfig(__DIR__.'/database_config.json'); Jf::$Rbac=new RbacManager(); require_once __DIR__."/../setup.php"; \ No newline at end of file diff --git a/PhpRbac/Database/database.config b/PhpRbac/Database/database.config deleted file mode 100644 index 7c81ca3..0000000 --- a/PhpRbac/Database/database.config +++ /dev/null @@ -1,13 +0,0 @@ -tablePrefix()}{$this->type()}" ); + $Res = Jf::sql ( "SELECT COUNT(*) FROM " . Jf::getConfig('table_prefix') . "{$this->type()}" ); return (int)$Res [0] ['COUNT(*)']; } @@ -147,9 +147,10 @@ public function pathId($Path) throw new \Exception ("Unknown Group_Concat on this type of database: {$Adapter}"); } + $tablePrefix = Jf::getConfig('table_prefix'); $res = Jf::sql ( "SELECT node.ID,{$GroupConcat} AS Path - FROM {$this->tablePrefix()}{$this->type()} AS node, - {$this->tablePrefix()}{$this->type()} AS parent + FROM {$tablePrefix}{$this->type()} AS node, + {$tablePrefix}{$this->type()} AS parent WHERE node.Lft BETWEEN parent.Lft AND parent.Rght AND node.Title=? GROUP BY node.ID @@ -162,16 +163,16 @@ public function pathId($Path) return null; // TODO: make the below SQL work, so that 1024 limit is over - $QueryBase = ("SELECT n0.ID \nFROM {$this->tablePrefix()}{$this->type()} AS n0"); + $QueryBase = ("SELECT n0.ID \nFROM {$tablePrefix}{$this->type()} AS n0"); $QueryCondition = "\nWHERE n0.Title=?"; for($i = 1; $i < count ( $Parts ); ++ $i) { $j = $i - 1; - $QueryBase .= "\nJOIN {$this->tablePrefix()}{$this->type()} AS n{$i} ON (n{$j}.Lft BETWEEN n{$i}.Lft+1 AND n{$i}.Rght)"; + $QueryBase .= "\nJOIN {$tablePrefix}{$this->type()} AS n{$i} ON (n{$j}.Lft BETWEEN n{$i}.Lft+1 AND n{$i}.Rght)"; $QueryCondition .= "\nAND n{$i}.Title=?"; // Forcing middle elements - $QueryBase .= "\nLEFT JOIN {$this->tablePrefix()}{$this->type()} AS nn{$i} ON (nn{$i}.Lft BETWEEN n{$i}.Lft+1 AND n{$j}.Lft-1)"; + $QueryBase .= "\nLEFT JOIN {$tablePrefix}{$this->type()} AS nn{$i} ON (nn{$i}.Lft BETWEEN n{$i}.Lft+1 AND n{$j}.Lft-1)"; $QueryCondition .= "\nAND nn{$i}.Lft IS NULL"; } $Query = $QueryBase . $QueryCondition; @@ -345,20 +346,21 @@ function parentNode($ID) */ function reset($Ensure = false) { + $tablePrefix = Jf::getConfig('table_prefix'); if ($Ensure !== true) { throw new \Exception ("You must pass true to this function, otherwise it won't work."); return; } - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}{$this->type()}" ); + $res = Jf::sql ( "DELETE FROM {$tablePrefix}{$this->type()}" ); $Adapter = get_class(Jf::$Db); if ($this->isMySql()) - Jf::sql ( "ALTER TABLE {$this->tablePrefix()}{$this->type()} AUTO_INCREMENT=1 " ); + Jf::sql ( "ALTER TABLE {$tablePrefix}{$this->type()} AUTO_INCREMENT=1 " ); elseif ($this->isSQLite()) - Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "{$this->type()}" ); + Jf::sql ( "delete from sqlite_sequence where name=? ", "{$tablePrefix}{$this->type()}" ); else throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" ); - $iid = Jf::sql ( "INSERT INTO {$this->tablePrefix()}{$this->type()} (Title,Description,Lft,Rght) VALUES (?,?,?,?)", "root", "root",0,1 ); + $iid = Jf::sql ( "INSERT INTO {$tablePrefix}{$this->type()} (Title,Description,Lft,Rght) VALUES (?,?,?,?)", "root", "root",0,1 ); return (int)$res; } @@ -396,9 +398,9 @@ function assign($Role, $Permission) $PermissionID = Jf::$Rbac->Permissions->titleId($Permission); } - return Jf::sql("INSERT INTO {$this->tablePrefix()}rolepermissions + return Jf::sql('INSERT INTO ' . Jf::getConfig('table_prefix') . 'rolepermissions (RoleID,PermissionID,AssignmentDate) - VALUES (?,?,?)", $RoleID, $PermissionID, Jf::time()) >= 1; + VALUES (?,?,?)', $RoleID, $PermissionID, Jf::time()) >= 1; } /** @@ -432,8 +434,8 @@ function unassign($Role, $Permission) $PermissionID = Jf::$Rbac->Permissions->titleId($Permission); } - return Jf::sql("DELETE FROM {$this->tablePrefix()}rolepermissions WHERE - RoleID=? AND PermissionID=?", $RoleID, $PermissionID) == 1; + return Jf::sql('DELETE FROM ' . Jf::getConfig('table_prefix') . 'rolepermissions WHERE + RoleID=? AND PermissionID=?', $RoleID, $PermissionID) == 1; } /** @@ -451,13 +453,14 @@ function resetAssignments($Ensure = false) throw new \Exception ("You must pass true to this function, otherwise it won't work."); return; } - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions" ); + $tablePrefix = Jf::getConfig('table_prefix'); + $res = Jf::sql ( "DELETE FROM {$tablePrefix}rolepermissions" ); $Adapter = get_class(Jf::$Db); if ($this->isMySql()) - Jf::sql ( "ALTER TABLE {$this->tablePrefix()}rolepermissions AUTO_INCREMENT =1 " ); + Jf::sql ( "ALTER TABLE {$tablePrefix}rolepermissions AUTO_INCREMENT =1 " ); elseif ($this->isSQLite()) - Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_rolepermissions" ); + Jf::sql ( "delete from sqlite_sequence where name=? ", "{$tablePrefix}_rolepermissions" ); else throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" ); $this->assign ( $this->rootId(), $this->rootId()); diff --git a/PhpRbac/Manager/PermissionManager.php b/PhpRbac/Manager/PermissionManager.php index a4633de..f3ef13b 100644 --- a/PhpRbac/Manager/PermissionManager.php +++ b/PhpRbac/Manager/PermissionManager.php @@ -31,7 +31,7 @@ protected function type() function __construct() { - $this->permissions = new FullNestedSet ( $this->tablePrefix () . "permissions", "ID", "Lft", "Rght" ); + $this->permissions = new FullNestedSet ( Jf::getConfig('table_prefix') . "permissions", "ID", "Lft", "Rght" ); } /** @@ -61,8 +61,8 @@ function remove($ID, $Recursive = false) */ function unassignRoles($ID) { - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE - PermissionID=?", $ID ); + $res = Jf::sql ( 'DELETE FROM ' . Jf::getConfig('table_prefix') . 'rolepermissions WHERE + PermissionID=?', $ID ); return (int)$res; } @@ -77,27 +77,30 @@ function unassignRoles($ID) */ function roles($Permission, $OnlyIDs = true) { - if (!is_numeric($Permission)) - $Permission = $this->returnId($Permission); + if (!is_numeric($Permission)) + { + $Permission = $this->returnId($Permission); + } + + $tablePrefix = Jf::getConfig('table_prefix'); + if ($OnlyIDs) + { + $Res = Jf::sql ( "SELECT RoleID AS `ID` FROM + {$tablePrefix}rolepermissions WHERE PermissionID=? ORDER BY RoleID", $Permission ); - if ($OnlyIDs) - { - $Res = Jf::sql ( "SELECT RoleID AS `ID` FROM - {$this->tablePrefix()}rolepermissions WHERE PermissionID=? ORDER BY RoleID", $Permission ); - - if (is_array ( $Res )) - { - $out = array (); - foreach ( $Res as $R ) - $out [] = $R ['ID']; - return $out; - } - else - return null; - } else { - return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}roles AS `TP` - LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.RoleID=`TP`.ID) - WHERE PermissionID=? ORDER BY TP.ID", $Permission ); - } + if (is_array ( $Res )) + { + $out = array (); + foreach ( $Res as $R ) + $out [] = $R ['ID']; + return $out; + } + else + return null; + } else { + return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$tablePrefix}roles AS `TP` + LEFT JOIN {$tablePrefix}rolepermissions AS `TR` ON (`TR`.RoleID=`TP`.ID) + WHERE PermissionID=? ORDER BY TP.ID", $Permission ); + } } } \ No newline at end of file diff --git a/PhpRbac/Manager/RbacManager.php b/PhpRbac/Manager/RbacManager.php index 168d31b..4d13db7 100644 --- a/PhpRbac/Manager/RbacManager.php +++ b/PhpRbac/Manager/RbacManager.php @@ -123,16 +123,17 @@ function check($Permission, $UserID = null) AND TPdirect.ID=?"; } + $tablePrefix = Jf::getConfig('table_prefix'); $Res=Jf::sql ( "SELECT COUNT(*) AS Result FROM - {$this->tablePrefix()}userroles AS TUrel + {$tablePrefix}userroles AS TUrel - JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUrel.RoleID) - JOIN {$this->tablePrefix()}roles AS TR ON ( TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) + JOIN {$tablePrefix}roles AS TRdirect ON (TRdirect.ID=TUrel.RoleID) + JOIN {$tablePrefix}roles AS TR ON ( TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) JOIN - ( {$this->tablePrefix()}permissions AS TPdirect - JOIN {$this->tablePrefix()}permissions AS TP ON ( TPdirect.Lft BETWEEN TP.Lft AND TP.Rght) - JOIN {$this->tablePrefix()}rolepermissions AS TRel ON (TP.ID=TRel.PermissionID) + ( {$tablePrefix}permissions AS TPdirect + JOIN {$tablePrefix}permissions AS TP ON ( TPdirect.Lft BETWEEN TP.Lft AND TP.Rght) + JOIN {$tablePrefix}rolepermissions AS TRel ON (TP.ID=TRel.PermissionID) ) $LastPart", $UserID, $PermissionID ); diff --git a/PhpRbac/Manager/RbacUserManager.php b/PhpRbac/Manager/RbacUserManager.php index decba17..2e956b4 100644 --- a/PhpRbac/Manager/RbacUserManager.php +++ b/PhpRbac/Manager/RbacUserManager.php @@ -48,10 +48,12 @@ function hasRole($Role, $UserID = null) else $RoleID = Jf::$Rbac->Roles->titleId ( $Role ); } + + $tablePrefix = Jf::getConfig('table_prefix'); - $R = Jf::sql ( "SELECT * FROM {$this->tablePrefix()}userroles AS TUR - JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUR.RoleID) - JOIN {$this->tablePrefix()}roles AS TR ON (TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) + $R = Jf::sql ( "SELECT * FROM {$tablePrefix}userroles AS TUR + JOIN {$tablePrefix}roles AS TRdirect ON (TRdirect.ID=TUR.RoleID) + JOIN {$tablePrefix}roles AS TR ON (TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght) WHERE TUR.UserID=? AND TR.ID=?", $UserID, $RoleID ); @@ -84,10 +86,10 @@ function assign($Role, $UserID = null) $RoleID = Jf::$Rbac->Roles->titleId($Role); } - $res = Jf::sql ( "INSERT INTO {$this->tablePrefix()}userroles + $res = Jf::sql ( 'INSERT INTO ' . Jf::getConfig('table_prefix') . 'userroles (UserID,RoleID,AssignmentDate) VALUES (?,?,?) - ", $UserID, $RoleID, Jf::time () ); + ', $UserID, $RoleID, Jf::time () ); return $res >= 1; } @@ -119,7 +121,7 @@ function unassign($Role, $UserID = null) $RoleID = Jf::$Rbac->Roles->titleId($Role); } - return Jf::sql("DELETE FROM {$this->tablePrefix()}userroles WHERE UserID=? AND RoleID=?", $UserID, $RoleID) >= 1; + return Jf::sql('DELETE FROM ' . Jf::getConfig('table_prefix') . 'userroles WHERE UserID=? AND RoleID=?', $UserID, $RoleID) >= 1; } /** @@ -137,10 +139,11 @@ function allRoles($UserID = null) if ($UserID === null) throw new RbacUserNotProvidedException ("\$UserID is a required argument."); + $tablePrefix = Jf::getConfig('table_prefix'); return Jf::sql ( "SELECT TR.* FROM - {$this->tablePrefix()}userroles AS `TRel` - JOIN {$this->tablePrefix()}roles AS `TR` ON + {$tablePrefix}userroles AS `TRel` + JOIN {$tablePrefix}roles AS `TR` ON (`TRel`.RoleID=`TR`.ID) WHERE TRel.UserID=?", $UserID ); } @@ -158,7 +161,7 @@ function roleCount($UserID = null) if ($UserID === null) throw new RbacUserNotProvidedException ("\$UserID is a required argument."); - $Res = Jf::sql ( "SELECT COUNT(*) AS Result FROM {$this->tablePrefix()}userroles WHERE UserID=?", $UserID ); + $Res = Jf::sql ('SELECT COUNT(*) AS Result FROM ' . Jf::getConfig('table_prefix') . 'userroles WHERE UserID=?', $UserID ); return (int)$Res [0] ['Result']; } @@ -174,16 +177,17 @@ function resetAssignments($Ensure = false) { if ($Ensure !== true) { - throw new \Exception ("You must pass true to this function, otherwise it won't work."); - return; + throw new \Exception ("You must pass true to this function, otherwise it won't work."); + return; } - $res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles" ); + $tablePrefix = Jf::getConfig('table_prefix'); + $res = Jf::sql ( "DELETE FROM {$tablePrefix}userroles" ); $Adapter = get_class(Jf::$Db); if ($this->isMySql()) - Jf::sql ( "ALTER TABLE {$this->tablePrefix()}userroles AUTO_INCREMENT =1 " ); + Jf::sql ( "ALTER TABLE {$tablePrefix}userroles AUTO_INCREMENT =1 " ); elseif ($this->isSQLite()) - Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_userroles" ); + Jf::sql ( "delete from sqlite_sequence where name=? ", "{$tablePrefix}_userroles" ); else throw new \Exception ("Rbac can not reset table on this type of database: {$Adapter}"); $this->assign ( "root", 1 /* root user */ ); diff --git a/PhpRbac/Manager/RoleManager.php b/PhpRbac/Manager/RoleManager.php index bf5f47c..93227e0 100644 --- a/PhpRbac/Manager/RoleManager.php +++ b/PhpRbac/Manager/RoleManager.php @@ -34,7 +34,7 @@ protected function type() function __construct() { $this->type = "roles"; - $this->roles = new FullNestedSet ( $this->tablePrefix () . "roles", "ID", "Lft", "Rght" ); + $this->roles = new FullNestedSet ( Jf::getConfig('table_prefix') . "roles", "ID", "Lft", "Rght" ); } /** @@ -65,8 +65,8 @@ function remove($ID, $Recursive = false) */ function unassignPermissions($ID) { - $r = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE - RoleID=? ", $ID ); + $r = Jf::sql ('DELETE FROM ' . Jf::getConfig('table_prefix') . 'rolepermissions WHERE + RoleID=?', $ID ); return $r; } @@ -79,8 +79,8 @@ function unassignPermissions($ID) */ function unassignUsers($ID) { - return Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles WHERE - RoleID=?", $ID ); + return Jf::sql ('DELETE FROM ' . Jf::getConfig('table_prefix') . 'userroles WHERE + RoleID=?', $ID ); } /** @@ -96,30 +96,30 @@ function unassignUsers($ID) */ function hasPermission($Role, $Permission) { - $Res = Jf::sql ( " - SELECT COUNT(*) AS Result - FROM {$this->tablePrefix()}rolepermissions AS TRel - JOIN {$this->tablePrefix()}permissions AS TP ON ( TP.ID= TRel.PermissionID) - JOIN {$this->tablePrefix()}roles AS TR ON ( TR.ID = TRel.RoleID) - WHERE TR.Lft BETWEEN - (SELECT Lft FROM {$this->tablePrefix()}roles WHERE ID=?) - AND - (SELECT Rght FROM {$this->tablePrefix()}roles WHERE ID=?) - /* the above section means any row that is a descendants of our role (if descendant roles have some permission, then our role has it two) */ - AND TP.ID IN ( - SELECT parent.ID - FROM {$this->tablePrefix()}permissions AS node, - {$this->tablePrefix()}permissions AS parent - WHERE node.Lft BETWEEN parent.Lft AND parent.Rght - AND ( node.ID=? ) - ORDER BY parent.Lft - ); - /* - the above section returns all the parents of (the path to) our permission, so if one of our role or its descendants - has an assignment to any of them, we're good. - */ - ", $Role, $Role, $Permission ); - return $Res [0] ['Result'] >= 1; + $tablePrefix = Jf::getConfig('table_prefix'); + $Res = Jf::sql ( "SELECT COUNT(*) AS Result + FROM {$tablePrefix}rolepermissions AS TRel + JOIN {$tablePrefix}permissions AS TP ON ( TP.ID= TRel.PermissionID) + JOIN {$tablePrefix}roles AS TR ON ( TR.ID = TRel.RoleID) + WHERE TR.Lft BETWEEN + (SELECT Lft FROM {$tablePrefix}roles WHERE ID=?) + AND + (SELECT Rght FROM {$tablePrefix}roles WHERE ID=?) + /* the above section means any row that is a descendants of our role (if descendant roles have some permission, then our role has it two) */ + AND TP.ID IN ( + SELECT parent.ID + FROM {$tablePrefix}permissions AS node, + {$tablePrefix}permissions AS parent + WHERE node.Lft BETWEEN parent.Lft AND parent.Rght + AND ( node.ID=? ) + ORDER BY parent.Lft + ); + /* + the above section returns all the parents of (the path to) our permission, so if one of our role or its descendants + has an assignment to any of them, we're good. + */ + ", $Role, $Role, $Permission); + return $Res [0] ['Result'] >= 1; } /** @@ -135,24 +135,27 @@ function hasPermission($Role, $Permission) function permissions($Role, $OnlyIDs = true) { if (! is_numeric ($Role)) - $Role = $this->returnId($Role); + { + $Role = $this->returnId($Role); + } - if ($OnlyIDs) - { - $Res = Jf::sql ( "SELECT PermissionID AS `ID` FROM {$this->tablePrefix()}rolepermissions WHERE RoleID=? ORDER BY PermissionID", $Role ); - if (is_array ( $Res )) - { - $out = array (); - foreach ( $Res as $R ) - $out [] = $R ['ID']; - return $out; - } - else - return null; - } else { - return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}permissions AS `TP` - LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.PermissionID=`TP`.ID) - WHERE RoleID=? ORDER BY TP.ID", $Role ); - } + $tablePrefix = Jf::getConfig('table_prefix'); + if ($OnlyIDs) + { + $Res = Jf::sql ( "SELECT PermissionID AS `ID` FROM {$tablePrefix}rolepermissions WHERE RoleID=? ORDER BY PermissionID", $Role ); + if (is_array ( $Res )) + { + $out = array (); + foreach ( $Res as $R ) + $out [] = $R ['ID']; + return $out; + } + else + return null; + } else { + return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$tablePrefix}permissions AS `TP` + LEFT JOIN {$tablePrefix}rolepermissions AS `TR` ON (`TR`.PermissionID=`TP`.ID) + WHERE RoleID=? ORDER BY TP.ID", $Role ); + } } } \ No newline at end of file diff --git a/PhpRbac/NestedSet/FullNestedSet.php b/PhpRbac/NestedSet/FullNestedSet.php index 41201b2..d23b873 100644 --- a/PhpRbac/NestedSet/FullNestedSet.php +++ b/PhpRbac/NestedSet/FullNestedSet.php @@ -51,7 +51,7 @@ function getID($ConditionString,$Rest=null) array_shift($args); $Query="SELECT {$this->id()} AS ID FROM {$this->table()} WHERE $ConditionString LIMIT 1"; array_unshift($args,$Query); - $Res=call_user_func_array(("Jf::sql"),$args); + $Res=call_user_func_array(("PhpRbac\Database\Jf::sql"),$args); if ($Res) return $Res[0]["ID"]; else @@ -70,7 +70,7 @@ function getRecord($ConditionString,$Rest=null) array_shift($args); $Query="SELECT * FROM {$this->table()} WHERE $ConditionString"; array_unshift($args,$Query); - $Res=call_user_func_array(("Jf::sql"),$args); + $Res=call_user_func_array(("PhpRbac\Database\Jf::sql"),$args); if ($Res) return $Res[0]; else diff --git a/PhpRbac/Rbac.php b/PhpRbac/Rbac.php index b296507..89e4cd3 100644 --- a/PhpRbac/Rbac.php +++ b/PhpRbac/Rbac.php @@ -1,56 +1,50 @@ -Permissions = Jf::$Rbac->Permissions; - $this->Roles = Jf::$Rbac->Roles; - $this->Users = Jf::$Rbac->Users; - } - - public function assign($role, $permission) - { - return Jf::$Rbac->assign($role, $permission); - } - - public function check($permission, $user_id) - { - return Jf::$Rbac->check($permission, $user_id); - } - - public function enforce($permission, $user_id) - { - return Jf::$Rbac->enforce($permission, $user_id); - } - - public function reset($ensure = false) - { - return Jf::$Rbac->reset($ensure); - } - - public function tablePrefix() - { - return Jf::$Rbac->tablePrefix(); - } -} - -/** @} */ // End group phprbac */ +Permissions = Jf::$Rbac->Permissions; + $this->Roles = Jf::$Rbac->Roles; + $this->Users = Jf::$Rbac->Users; + } + + public function assign($role, $permission) + { + return Jf::$Rbac->assign($role, $permission); + } + + public function check($permission, $user_id) + { + return Jf::$Rbac->check($permission, $user_id); + } + + public function enforce($permission, $user_id) + { + return Jf::$Rbac->enforce($permission, $user_id); + } + + public function reset($ensure = false) + { + return Jf::$Rbac->reset($ensure); + } + + public function tablePrefix() + { + return Jf::$Rbac->tablePrefix(); + } +} + +/** @} */ // End group phprbac */ diff --git a/PhpRbac/index.php b/PhpRbac/index.php index 55dfe6b..ab67b68 100644 --- a/PhpRbac/index.php +++ b/PhpRbac/index.php @@ -1,6 +1,6 @@ Date: Mon, 12 Jan 2015 14:42:50 +0100 Subject: [PATCH 10/57] Move tests files --- PhpRbac/Manager/BaseRbacManager.php | 1 + PhpRbac/Rbac.php | 14 +- PhpRbac/Tests/DatabaseTestCase.php | 38 + PhpRbac/Tests/{src => }/RbacBase.php | 1790 +++++++++-------- PhpRbac/Tests/{src => }/RbacManagerTest.php | 620 +++--- .../Tests/{src => }/RbacPermissionsTest.php | 466 ++--- PhpRbac/Tests/{src => }/RbacRolesTest.php | 620 +++--- PhpRbac/Tests/{src => }/RbacSetup.php | 112 +- PhpRbac/Tests/{src => }/RbacUsersTest.php | 840 ++++---- PhpRbac/Tests/bootstrap.php | 2 +- ...xpected_add_path_permissions_hierarchy.xml | 0 ...path_permissions_hierarchy_description.xml | 0 ...pected_add_path_permissions_sequential.xml | 0 ...ath_permissions_sequential_description.xml | 0 .../expected_add_path_permissions_single.xml | 0 ...dd_path_permissions_single_description.xml | 0 .../expected_add_path_roles_hierarchy.xml | 0 ...d_add_path_roles_hierarchy_description.xml | 0 .../expected_add_path_roles_sequential.xml | 0 ..._add_path_roles_sequential_description.xml | 0 .../base/expected_add_path_roles_single.xml | 0 ...cted_add_path_roles_single_description.xml | 0 .../expected_add_permissions_hierarchy.xml | 0 .../expected_add_permissions_sequential.xml | 0 .../base/expected_add_roles_hierarchy.xml | 0 .../base/expected_add_roles_sequential.xml | 0 .../base/expected_assign_permissions.xml | 0 .../datasets/base/expected_assign_roles.xml | 0 .../base/expected_edit_permissions_all.xml | 0 .../expected_edit_permissions_description.xml | 0 .../base/expected_edit_permissions_title.xml | 0 .../datasets/base/expected_edit_roles_all.xml | 0 .../base/expected_edit_roles_description.xml | 0 .../base/expected_edit_roles_title.xml | 0 ...expected_reset_assignments_permissions.xml | 0 .../base/expected_reset_assignments_roles.xml | 0 .../base/expected_reset_permissions.xml | 0 .../datasets/base/expected_reset_roles.xml | 0 .../base/expected_unassign_permissions.xml | 0 .../datasets/base/expected_unassign_roles.xml | 0 .../{src => }/datasets/database-seed.xml | 0 .../datasets/manager/expected_assign_id.xml | 0 .../datasets/manager/expected_assign_path.xml | 0 .../manager/expected_assign_title.xml | 0 .../datasets/manager/expected_reset.xml | 0 .../permissions/expected_remove_recursive.xml | 0 .../permissions/expected_remove_single.xml | 0 .../expected_remove_single_role.xml | 0 .../permissions/expected_unassign_roles.xml | 0 .../roles/expected_remove_recursive.xml | 0 .../datasets/roles/expected_remove_single.xml | 0 .../expected_remove_single_permission.xml | 0 .../roles/expected_unassign_permissions.xml | 0 .../roles/expected_unassign_users.xml | 0 .../datasets/users/expected_assign_no_id.xml | 0 .../users/expected_assign_with_id.xml | 0 .../users/expected_assign_with_path.xml | 0 .../users/expected_reset_assignments.xml | 0 .../datasets/users/expected_unassign.xml | 0 PhpRbac/Tests/phpunit_mysql.xml | 8 +- PhpRbac/Tests/phpunit_sqlite.xml | 2 +- .../src/Generic_Tests_DatabaseTestCase.php | 53 - PhpRbac/autoload.php | 22 - composer.json | 6 +- 64 files changed, 2279 insertions(+), 2315 deletions(-) create mode 100644 PhpRbac/Tests/DatabaseTestCase.php rename PhpRbac/Tests/{src => }/RbacBase.php (97%) rename PhpRbac/Tests/{src => }/RbacManagerTest.php (91%) rename PhpRbac/Tests/{src => }/RbacPermissionsTest.php (96%) rename PhpRbac/Tests/{src => }/RbacRolesTest.php (96%) rename PhpRbac/Tests/{src => }/RbacSetup.php (75%) rename PhpRbac/Tests/{src => }/RbacUsersTest.php (96%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_permissions_hierarchy.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_permissions_hierarchy_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_permissions_sequential.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_permissions_sequential_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_permissions_single.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_permissions_single_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_roles_hierarchy.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_roles_hierarchy_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_roles_sequential.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_roles_sequential_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_roles_single.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_path_roles_single_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_permissions_hierarchy.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_permissions_sequential.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_roles_hierarchy.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_add_roles_sequential.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_assign_permissions.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_assign_roles.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_edit_permissions_all.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_edit_permissions_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_edit_permissions_title.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_edit_roles_all.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_edit_roles_description.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_edit_roles_title.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_reset_assignments_permissions.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_reset_assignments_roles.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_reset_permissions.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_reset_roles.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_unassign_permissions.xml (100%) rename PhpRbac/Tests/{src => }/datasets/base/expected_unassign_roles.xml (100%) rename PhpRbac/Tests/{src => }/datasets/database-seed.xml (100%) rename PhpRbac/Tests/{src => }/datasets/manager/expected_assign_id.xml (100%) rename PhpRbac/Tests/{src => }/datasets/manager/expected_assign_path.xml (100%) rename PhpRbac/Tests/{src => }/datasets/manager/expected_assign_title.xml (100%) rename PhpRbac/Tests/{src => }/datasets/manager/expected_reset.xml (100%) rename PhpRbac/Tests/{src => }/datasets/permissions/expected_remove_recursive.xml (100%) rename PhpRbac/Tests/{src => }/datasets/permissions/expected_remove_single.xml (100%) rename PhpRbac/Tests/{src => }/datasets/permissions/expected_remove_single_role.xml (100%) rename PhpRbac/Tests/{src => }/datasets/permissions/expected_unassign_roles.xml (100%) rename PhpRbac/Tests/{src => }/datasets/roles/expected_remove_recursive.xml (100%) rename PhpRbac/Tests/{src => }/datasets/roles/expected_remove_single.xml (100%) rename PhpRbac/Tests/{src => }/datasets/roles/expected_remove_single_permission.xml (100%) rename PhpRbac/Tests/{src => }/datasets/roles/expected_unassign_permissions.xml (100%) rename PhpRbac/Tests/{src => }/datasets/roles/expected_unassign_users.xml (100%) rename PhpRbac/Tests/{src => }/datasets/users/expected_assign_no_id.xml (100%) rename PhpRbac/Tests/{src => }/datasets/users/expected_assign_with_id.xml (100%) rename PhpRbac/Tests/{src => }/datasets/users/expected_assign_with_path.xml (100%) rename PhpRbac/Tests/{src => }/datasets/users/expected_reset_assignments.xml (100%) rename PhpRbac/Tests/{src => }/datasets/users/expected_unassign.xml (100%) delete mode 100644 PhpRbac/Tests/src/Generic_Tests_DatabaseTestCase.php delete mode 100644 PhpRbac/autoload.php diff --git a/PhpRbac/Manager/BaseRbacManager.php b/PhpRbac/Manager/BaseRbacManager.php index c6f16db..7579b4c 100644 --- a/PhpRbac/Manager/BaseRbacManager.php +++ b/PhpRbac/Manager/BaseRbacManager.php @@ -40,6 +40,7 @@ abstract protected function type(); */ function add($Title, $Description, $ParentID = null) { + die('ok'); if ($ParentID === null) $ParentID = $this->rootId (); return (int)$this->{$this->type ()}->insertChildData ( array ("Title" => $Title, "Description" => $Description ), "ID=?", $ParentID ); diff --git a/PhpRbac/Rbac.php b/PhpRbac/Rbac.php index 89e4cd3..d713e33 100644 --- a/PhpRbac/Rbac.php +++ b/PhpRbac/Rbac.php @@ -4,17 +4,9 @@ use PhpRbac\Database\Jf; -/** - * @file - * Provides NIST Level 2 Standard Role Based Access Control functionality - * - * @defgroup phprbac Rbac Functionality - * @{ - * Documentation for all PhpRbac related functionality. - */ class Rbac { - public function __construct($unit_test = '') + public function __construct() { $this->Permissions = Jf::$Rbac->Permissions; $this->Roles = Jf::$Rbac->Roles; @@ -45,6 +37,4 @@ public function tablePrefix() { return Jf::$Rbac->tablePrefix(); } -} - -/** @} */ // End group phprbac */ +} \ No newline at end of file diff --git a/PhpRbac/Tests/DatabaseTestCase.php b/PhpRbac/Tests/DatabaseTestCase.php new file mode 100644 index 0000000..17ff519 --- /dev/null +++ b/PhpRbac/Tests/DatabaseTestCase.php @@ -0,0 +1,38 @@ +conn === null) { + if (self::$pdo == null) { + if ((string) Jf::getConfig('adapter') === 'pdo_sqlite') { + self::$pdo = new \PDO('sqlite:' . dirname(dirname(__FILE__)) . '/database/' . Jf::getConfig('dbname')); + + $sql = file_get_contents(dirname(dirname(__DIR__))."/database/sqlite.sql"); + $sql = str_replace("PREFIX_", Jf::getConfig('table_prefix'), $sql); + $statements = explode(";", $sql); + + if (is_array($statements)) + foreach ($statements as $query) + self::$pdo->query($query); + + } else { + self::$pdo = new \PDO("mysql:host=".Jf::getConfig('host').";dbname=".Jf::getConfig('dbname'), Jf::getConfig('user'), Jf::getConfig('pass')); + } + } + $this->conn = $this->createDefaultDBConnection(self::$pdo, Jf::getConfig('dbname')); + } + return $this->conn; + } +} diff --git a/PhpRbac/Tests/src/RbacBase.php b/PhpRbac/Tests/RbacBase.php similarity index 97% rename from PhpRbac/Tests/src/RbacBase.php rename to PhpRbac/Tests/RbacBase.php index df8a9ee..6d64238 100644 --- a/PhpRbac/Tests/src/RbacBase.php +++ b/PhpRbac/Tests/RbacBase.php @@ -1,894 +1,896 @@ -Instance()->add() - */ - - public function testAddNullTitle() - { - $dataSet = $this->getConnection()->createDataSet(); - - $type_id = $this->Instance()->add(null, $this->type() . ' Description'); - - $this->assertSame(0, $type_id); - } - - public function testAddNullDescription() - { - $dataSet = $this->getConnection()->createDataSet(); - - $type_id = $this->Instance()->add($this->type() . '_title', null); - - $this->assertSame(0, $type_id); - } - - public function testAddSequential() - { - $dataSet = $this->getConnection()->createDataSet(); - - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_' . $this->type() . '_sequential.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddHierarchy() - { - $dataSet = $this->getConnection()->createDataSet(); - - $type_1 = $this->Instance()->add('blog', 'Define ' . $this->type() . ' for the Blog'); - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1', $type_1); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2', $type_1); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3', $type_1); - - $type_2 = $this->Instance()->add('forum', 'Define ' . $this->type() . ' for the Forums'); - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1', $type_2); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2', $type_2); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3', $type_2); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_' . $this->type() . '_hierarchy.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - /* - * Tests for $this->Instance()->count() - */ - - public function testCount() - { - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); - - $type_count = $this->Instance()->count(); - - $this->assertSame(4, $type_count); - } - - /* - * Tests for $this->Instance()->returnId() - */ - - public function testReturnIdTitle() - { - $this->Instance()->addPath('/'. $this->type() . '_1/'. $this->type() . '_2'); - - $entityId = $this->Instance()->returnId($this->type() . '_2'); - - $this->assertEquals('3', $entityId); - } - - public function testReturnIdPath() - { - $this->Instance()->addPath('/'. $this->type() . '_1/'. $this->type() . '_2'); - - $entityId = $this->Instance()->returnId('/'. $this->type() . '_1/'. $this->type() . '_2'); - - $this->assertEquals('3', $entityId); - } - - public function testReturnIdNullBadParameters() - { - $entityId = $this->Instance()->returnId($this->type() . '_2'); - - $this->assertSame(null, $entityId); - } - - public function testReturnIdNullNoParameters() - { - $entityId = $this->Instance()->returnId(); - - $this->assertSame(null, $entityId); - } - - /* - * Tests for $this->Instance()->titleId() - */ - - public function testGetTitleId() - { - $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $title_id = $this->Instance()->titleId($this->type() . '_title'); - - $this->assertSame('2', $title_id); - } - - public function testGetTitleIdNull() - { - $title_id = $this->Instance()->titleId($this->type() . '_title'); - - $this->assertNull($title_id); - } - - /* - * Tests for $this->Instance()->getTitle() - */ - - public function testGetTitle() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $type_title = $this->Instance()->getTitle($type_id); - - $this->assertSame($this->type() . '_title', $type_title); - } - - public function testGetTitleNull() - { - $type_title = $this->Instance()->getTitle(intval(3)); - - $this->assertNull($type_title); - } - - /* - * Tests for $this->Instance()->getDescription() - */ - - public function testGetDescription() - { - $type_description = $this->Instance()->getDescription(intval(1)); - - $this->assertSame('root', $type_description); - } - - public function testGetDescriptionNull() - { - $type_description = $this->Instance()->getDescription(intval(2)); - - $this->assertNull($type_description); - } - - /* - * Tests for $this->Instance()->edit() - */ - - public function testEditTitle() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $this->Instance()->edit($type_id, $this->type() . '_title_edited'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_title.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testEditDescription() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $this->Instance()->edit($type_id, null, $this->type() . ' Description edited'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testEditAll() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $this->Instance()->edit($type_id, $this->type() . '_title_edited', $this->type() . ' Description edited'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_all.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testEditNullId() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $result = $this->Instance()->edit(intval(3), $this->type() . '_title', $this->type() . ' Description'); - - $this->assertFalse($result); - } - - public function testEditNullParameters() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $result = $this->Instance()->edit($type_id); - - $this->assertFalse($result); - } - - /* - * Tests for $this->Instance()->addPath() - */ - - public function testAddPathSingle() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_single.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathSingleDescription() - { - $descriptions = array( - $this->type() . ' Description 1', - $this->type() . ' Description 2', - $this->type() . ' Description 3', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_single_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathSequential() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_sequential.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathSequentialDescription() - { - $descriptions_1 = array( - $this->type() . ' Description 1', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/', $descriptions_1); - - $descriptions_2 = array( - null, - $this->type() . ' Description 2', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/', $descriptions_2); - - $descriptions_3 = array( - null, - null, - $this->type() . ' Description 3', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions_3); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_sequential_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathHierarchy() - { - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_4'); - - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_13/' . $this->type() . '_14'); - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_15/' . $this->type() . '_11'); - - $this->Instance()->addPath('/' . $this->type() . '_23/' . $this->type() . '_24/' . $this->type() . '_25'); - $this->Instance()->addPath('/' . $this->type() . '_33/' . $this->type() . '_34/' . $this->type() . '_35'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_hierarchy.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathHierarchyDescription() - { - $descriptions_1 = array( - $this->type() . ' Description 1', - $this->type() . ' Description 2', - $this->type() . ' Description 3', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions_1); - - $descriptions_2 = array( - null, - null, - $this->type() . ' Description 4', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_4', $descriptions_2); - - $descriptions_3 = array( - $this->type() . ' Description 12', - $this->type() . ' Description 13', - $this->type() . ' Description 14', - ); - - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_13/' . $this->type() . '_14', $descriptions_3); - - $descriptions_4 = array( - null, - $this->type() . ' Description 15', - $this->type() . ' Description 11', - ); - - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_15/' . $this->type() . '_11', $descriptions_4); - - $descriptions_5 = array( - $this->type() . ' Description 23', - $this->type() . ' Description 24', - $this->type() . ' Description 25', - ); - - $this->Instance()->addPath('/' . $this->type() . '_23/' . $this->type() . '_24/' . $this->type() . '_25', $descriptions_5); - - $descriptions_6 = array( - $this->type() . ' Description 33', - $this->type() . ' Description 34', - $this->type() . ' Description 35', - ); - - $this->Instance()->addPath('/' . $this->type() . '_33/' . $this->type() . '_34/' . $this->type() . '_35', $descriptions_6); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_hierarchy_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathReturnNodesCreatedCountTwoCreated() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $nodes_created = $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $this->assertSame(2, $nodes_created); - } - - public function testAddPathReturnNodesCreatedCountNoneCreated() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - $nodes_created = $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $this->assertSame(0, $nodes_created); - } - - - /** - * @expectedException Exception - */ - - public function testAddPathBadPath() - { - $this->Instance()->addPath('permissions_1/permissions_2//permissions_3'); - } - - /* - * Tests for $this->Instance()->pathId() - */ - - public function testPathID() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2'); - - $this->assertSame('3', $path_id); - } - - public function testPathIDNullBadPath() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_id = $this->Instance()->pathId($this->type() . '_2'); - - $this->assertNull($path_id); - } - - public function testPathIDGroupConcatMaxCharCountShortCount() - { - $this->Instance()->addPath('/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/final_109/first_depth11'); - $this->Instance()->addPath('/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109'); - - $path_id = $this->Instance()->pathId("/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/final_109"); - - $this->assertSame('13', $path_id); - } - - public function testPathIDGroupConcatMaxCharCountLongCount() - { - $this->Instance()->addPath('/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/first_depth11'); - $this->Instance()->addPath('/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109'); - - $path_id = $this->Instance()->pathId("/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109"); - - $this->assertSame('124', $path_id); - } - - /* - * Tests for $this->Instance()->getPath() - */ - - public function testPath() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_returned = $this->Instance()->getPath(intval(3)); - - $this->assertSame('/' . $this->type() . '_1/' . $this->type() . '_2', $path_returned); - } - - public function testgetPathNull() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_returned = $this->Instance()->getPath(intval(5)); - - $this->assertNull($path_returned); - } - - /* - * Tests for $this->Instance()->children() - */ - - public function testChildren() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $children = $this->Instance()->children($path_id); - - $expected = array( - array( - 'ID' => '5', - 'Lft' => '4', - 'Rght' => '7', - 'Title' => $this->type() . '_4', - 'Description' => '', - ), - array( - 'ID' => '7', - 'Lft' => '8', - 'Rght' => '11', - 'Title' => $this->type() . '_6', - 'Description' => '', - ) - ); - - $this->assertSame($expected, $children); - } - - public function testChildrenNullBadID() - { - $children = $this->Instance()->children(20); - - $this->assertNull($children); - } - - /* - * Tests for $this->Instance()->descendants() - */ - - public function testDescendants() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $descendants = $this->Instance()->descendants($path_id); - - $expected = array( - $this->type() . '_4' => array( - 'ID' => '5', - 'Lft' => '4', - 'Rght' => '7', - 'Title' => $this->type() . '_4', - 'Description' => '', - 'Depth' => '1', - ), - $this->type() . '_5' => array( - 'ID' => '6', - 'Lft' => '5', - 'Rght' => '6', - 'Title' => $this->type() . '_5', - 'Description' => '', - 'Depth' => '2', - ), - $this->type() . '_6' => array( - 'ID' => '7', - 'Lft' => '8', - 'Rght' => '11', - 'Title' => $this->type() . '_6', - 'Description' => '', - 'Depth' => '1', - ), - $this->type() . '_7' => array( - 'ID' => '8', - 'Lft' => '9', - 'Rght' => '10', - 'Title' => $this->type() . '_7', - 'Description' => '', - 'Depth' => '2', - ), - ); - - $this->assertSame($expected, $descendants); - } - - public function testDescendantsEmptyBadID() - { - $descendants = $this->Instance()->descendants(20); - - $this->assertEmpty($descendants); - } - - /* - * Tests for $this->Instance()->depth() - */ - - public function testDepth() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $depth = $this->Instance()->depth($path_id); - - $this->assertSame(3, $depth); - } - - public function testDepthBadID() - { - $depth = $this->Instance()->depth(20); - - $this->assertSame(-1, $depth); - } - - /* - * Tests for $this->Instance()->parentNode() - */ - - public function testParentNode() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $parent_node = $this->Instance()->parentNode($path_id); - - $expected = array( - 'ID' => '3', - 'Lft' => '2', - 'Rght' => '13', - 'Title' => $this->type() . '_2', - 'Description' => '', - ); - - $this->assertSame($expected, $parent_node); - } - - public function testParentNodeNullBadID() - { - $parent_node = $this->Instance()->parentNode(20); - - $this->assertNull($parent_node); - } - - /* - * Tests for $this->Instance()->assign() - */ - - public function testAssignWithId() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testAssignWithTitle() - { - self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign('roles_1', 'permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testAssignWithPath() - { - self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign('/roles_1', '/permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /* - * Tests for $this->Instance()->unassign() - */ - - public function testUnassignId() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - $this->Instance()->unassign($role_id, $perm_id); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUnassignTitle() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - $this->Instance()->unassign('roles_1', 'permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUnassignPath() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - $this->Instance()->unassign('/roles_1', '/permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /* - * Tests for $this->Instance()->resetAssignments() - */ - - public function testResetPermRoleAssignments() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_2, $perm_id_2); - $this->Instance()->assign($role_id_3, $perm_id_3); - - $this->Instance()->resetAssignments(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_reset_assignments_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testResetPermRoleAssignmentsException() - { - $this->Instance()->resetAssignments(); - } - - /* - * Tests for $this->Instance()->reset() - */ - - public function testReset() - { - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); - - $this->Instance()->reset(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - )); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_reset_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testResetException() - { - $this->Instance()->reset(); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_base */ +Instance()->add() + */ + + public function testAddNullTitle() + { + $dataSet = $this->getConnection()->createDataSet(); + + $type_id = $this->Instance()->add(null, $this->type() . ' Description'); + + $this->assertSame(0, $type_id); + } + + public function testAddNullDescription() + { + $dataSet = $this->getConnection()->createDataSet(); + + $type_id = $this->Instance()->add($this->type() . '_title', null); + + $this->assertSame(0, $type_id); + } + + public function testAddSequential() + { + $dataSet = $this->getConnection()->createDataSet(); + + $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); + $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); + $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_' . $this->type() . '_sequential.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testAddHierarchy() + { + $dataSet = $this->getConnection()->createDataSet(); + + $type_1 = $this->Instance()->add('blog', 'Define ' . $this->type() . ' for the Blog'); + $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1', $type_1); + $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2', $type_1); + $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3', $type_1); + + $type_2 = $this->Instance()->add('forum', 'Define ' . $this->type() . ' for the Forums'); + $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1', $type_2); + $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2', $type_2); + $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3', $type_2); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_' . $this->type() . '_hierarchy.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + /* + * Tests for $this->Instance()->count() + */ + + public function testCount() + { + $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); + $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); + $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); + + $type_count = $this->Instance()->count(); + + $this->assertSame(4, $type_count); + } + + /* + * Tests for $this->Instance()->returnId() + */ + + public function testReturnIdTitle() + { + $this->Instance()->addPath('/'. $this->type() . '_1/'. $this->type() . '_2'); + + $entityId = $this->Instance()->returnId($this->type() . '_2'); + + $this->assertEquals('3', $entityId); + } + + public function testReturnIdPath() + { + $this->Instance()->addPath('/'. $this->type() . '_1/'. $this->type() . '_2'); + + $entityId = $this->Instance()->returnId('/'. $this->type() . '_1/'. $this->type() . '_2'); + + $this->assertEquals('3', $entityId); + } + + public function testReturnIdNullBadParameters() + { + $entityId = $this->Instance()->returnId($this->type() . '_2'); + + $this->assertSame(null, $entityId); + } + + public function testReturnIdNullNoParameters() + { + $entityId = $this->Instance()->returnId(); + + $this->assertSame(null, $entityId); + } + + /* + * Tests for $this->Instance()->titleId() + */ + + public function testGetTitleId() + { + $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); + $title_id = $this->Instance()->titleId($this->type() . '_title'); + + $this->assertSame('2', $title_id); + } + + public function testGetTitleIdNull() + { + $title_id = $this->Instance()->titleId($this->type() . '_title'); + + $this->assertNull($title_id); + } + + /* + * Tests for $this->Instance()->getTitle() + */ + + public function testGetTitle() + { + $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); + $type_title = $this->Instance()->getTitle($type_id); + + $this->assertSame($this->type() . '_title', $type_title); + } + + public function testGetTitleNull() + { + $type_title = $this->Instance()->getTitle(intval(3)); + + $this->assertNull($type_title); + } + + /* + * Tests for $this->Instance()->getDescription() + */ + + public function testGetDescription() + { + $type_description = $this->Instance()->getDescription(intval(1)); + + $this->assertSame('root', $type_description); + } + + public function testGetDescriptionNull() + { + $type_description = $this->Instance()->getDescription(intval(2)); + + $this->assertNull($type_description); + } + + /* + * Tests for $this->Instance()->edit() + */ + + public function testEditTitle() + { + $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); + $this->Instance()->edit($type_id, $this->type() . '_title_edited'); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_title.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testEditDescription() + { + $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); + $this->Instance()->edit($type_id, null, $this->type() . ' Description edited'); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_description.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testEditAll() + { + $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); + $this->Instance()->edit($type_id, $this->type() . '_title_edited', $this->type() . ' Description edited'); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_all.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testEditNullId() + { + $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); + $result = $this->Instance()->edit(intval(3), $this->type() . '_title', $this->type() . ' Description'); + + $this->assertFalse($result); + } + + public function testEditNullParameters() + { + $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); + $result = $this->Instance()->edit($type_id); + + $this->assertFalse($result); + } + + /* + * Tests for $this->Instance()->addPath() + */ + + public function testAddPathSingle() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_single.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testAddPathSingleDescription() + { + $descriptions = array( + $this->type() . ' Description 1', + $this->type() . ' Description 2', + $this->type() . ' Description 3', + ); + + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_single_description.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testAddPathSequential() + { + $this->Instance()->addPath('/' . $this->type() . '_1/'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_sequential.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testAddPathSequentialDescription() + { + $descriptions_1 = array( + $this->type() . ' Description 1', + ); + + $this->Instance()->addPath('/' . $this->type() . '_1/', $descriptions_1); + + $descriptions_2 = array( + null, + $this->type() . ' Description 2', + ); + + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/', $descriptions_2); + + $descriptions_3 = array( + null, + null, + $this->type() . ' Description 3', + ); + + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions_3); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_sequential_description.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testAddPathHierarchy() + { + + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_4'); + + $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_13/' . $this->type() . '_14'); + $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_15/' . $this->type() . '_11'); + + $this->Instance()->addPath('/' . $this->type() . '_23/' . $this->type() . '_24/' . $this->type() . '_25'); + $this->Instance()->addPath('/' . $this->type() . '_33/' . $this->type() . '_34/' . $this->type() . '_35'); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_hierarchy.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testAddPathHierarchyDescription() + { + $descriptions_1 = array( + $this->type() . ' Description 1', + $this->type() . ' Description 2', + $this->type() . ' Description 3', + ); + + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions_1); + + $descriptions_2 = array( + null, + null, + $this->type() . ' Description 4', + ); + + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_4', $descriptions_2); + + $descriptions_3 = array( + $this->type() . ' Description 12', + $this->type() . ' Description 13', + $this->type() . ' Description 14', + ); + + $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_13/' . $this->type() . '_14', $descriptions_3); + + $descriptions_4 = array( + null, + $this->type() . ' Description 15', + $this->type() . ' Description 11', + ); + + $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_15/' . $this->type() . '_11', $descriptions_4); + + $descriptions_5 = array( + $this->type() . ' Description 23', + $this->type() . ' Description 24', + $this->type() . ' Description 25', + ); + + $this->Instance()->addPath('/' . $this->type() . '_23/' . $this->type() . '_24/' . $this->type() . '_25', $descriptions_5); + + $descriptions_6 = array( + $this->type() . ' Description 33', + $this->type() . ' Description 34', + $this->type() . ' Description 35', + ); + + $this->Instance()->addPath('/' . $this->type() . '_33/' . $this->type() . '_34/' . $this->type() . '_35', $descriptions_6); + + $queryTable = $this->getConnection()->createQueryTable( + $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() + ); + + $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_hierarchy_description.xml') + ->getTable($this->Instance()->tablePrefix() . $this->type()); + + $this->assertTablesEqual($expectedTable, $queryTable); + } + + public function testAddPathReturnNodesCreatedCountTwoCreated() + { + $this->Instance()->addPath('/' . $this->type() . '_1/'); + $nodes_created = $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $this->assertSame(2, $nodes_created); + } + + public function testAddPathReturnNodesCreatedCountNoneCreated() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + $nodes_created = $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $this->assertSame(0, $nodes_created); + } + + + /** + * @expectedException Exception + */ + + public function testAddPathBadPath() + { + $this->Instance()->addPath('permissions_1/permissions_2//permissions_3'); + } + + /* + * Tests for $this->Instance()->pathId() + */ + + public function testPathID() + { + $this->Instance()->addPath('/' . $this->type() . '_1/'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2'); + + $this->assertSame('3', $path_id); + } + + public function testPathIDNullBadPath() + { + $this->Instance()->addPath('/' . $this->type() . '_1/'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $path_id = $this->Instance()->pathId($this->type() . '_2'); + + $this->assertNull($path_id); + } + + public function testPathIDGroupConcatMaxCharCountShortCount() + { + $this->Instance()->addPath('/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/final_109/first_depth11'); + $this->Instance()->addPath('/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109'); + + $path_id = $this->Instance()->pathId("/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/final_109"); + + $this->assertSame('13', $path_id); + } + + public function testPathIDGroupConcatMaxCharCountLongCount() + { + $this->Instance()->addPath('/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/first_depth11'); + $this->Instance()->addPath('/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109'); + + $path_id = $this->Instance()->pathId("/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109"); + + $this->assertSame('124', $path_id); + } + + /* + * Tests for $this->Instance()->getPath() + */ + + public function testPath() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $path_returned = $this->Instance()->getPath(intval(3)); + + $this->assertSame('/' . $this->type() . '_1/' . $this->type() . '_2', $path_returned); + } + + public function testgetPathNull() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $path_returned = $this->Instance()->getPath(intval(5)); + + $this->assertNull($path_returned); + } + + /* + * Tests for $this->Instance()->children() + */ + + public function testChildren() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); + $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $children = $this->Instance()->children($path_id); + + $expected = array( + array( + 'ID' => '5', + 'Lft' => '4', + 'Rght' => '7', + 'Title' => $this->type() . '_4', + 'Description' => '', + ), + array( + 'ID' => '7', + 'Lft' => '8', + 'Rght' => '11', + 'Title' => $this->type() . '_6', + 'Description' => '', + ) + ); + + $this->assertSame($expected, $children); + } + + public function testChildrenNullBadID() + { + $children = $this->Instance()->children(20); + + $this->assertNull($children); + } + + /* + * Tests for $this->Instance()->descendants() + */ + + public function testDescendants() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); + $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $descendants = $this->Instance()->descendants($path_id); + + $expected = array( + $this->type() . '_4' => array( + 'ID' => '5', + 'Lft' => '4', + 'Rght' => '7', + 'Title' => $this->type() . '_4', + 'Description' => '', + 'Depth' => '1', + ), + $this->type() . '_5' => array( + 'ID' => '6', + 'Lft' => '5', + 'Rght' => '6', + 'Title' => $this->type() . '_5', + 'Description' => '', + 'Depth' => '2', + ), + $this->type() . '_6' => array( + 'ID' => '7', + 'Lft' => '8', + 'Rght' => '11', + 'Title' => $this->type() . '_6', + 'Description' => '', + 'Depth' => '1', + ), + $this->type() . '_7' => array( + 'ID' => '8', + 'Lft' => '9', + 'Rght' => '10', + 'Title' => $this->type() . '_7', + 'Description' => '', + 'Depth' => '2', + ), + ); + + $this->assertSame($expected, $descendants); + } + + public function testDescendantsEmptyBadID() + { + $descendants = $this->Instance()->descendants(20); + + $this->assertEmpty($descendants); + } + + /* + * Tests for $this->Instance()->depth() + */ + + public function testDepth() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); + $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $depth = $this->Instance()->depth($path_id); + + $this->assertSame(3, $depth); + } + + public function testDepthBadID() + { + $depth = $this->Instance()->depth(20); + + $this->assertSame(-1, $depth); + } + + /* + * Tests for $this->Instance()->parentNode() + */ + + public function testParentNode() + { + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); + $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); + $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); + + $parent_node = $this->Instance()->parentNode($path_id); + + $expected = array( + 'ID' => '3', + 'Lft' => '2', + 'Rght' => '13', + 'Title' => $this->type() . '_2', + 'Description' => '', + ); + + $this->assertSame($expected, $parent_node); + } + + public function testParentNodeNullBadID() + { + $parent_node = $this->Instance()->parentNode(20); + + $this->assertNull($parent_node); + } + + /* + * Tests for $this->Instance()->assign() + */ + + public function testAssignWithId() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign($role_id, $perm_id); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testAssignWithTitle() + { + self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign('roles_1', 'permissions_1'); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testAssignWithPath() + { + self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign('/roles_1', '/permissions_1'); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /* + * Tests for $this->Instance()->unassign() + */ + + public function testUnassignId() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign($role_id, $perm_id); + $this->Instance()->unassign($role_id, $perm_id); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'rolepermissions', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testUnassignTitle() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign($role_id, $perm_id); + $this->Instance()->unassign('roles_1', 'permissions_1'); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'rolepermissions', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testUnassignPath() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign($role_id, $perm_id); + $this->Instance()->unassign('/roles_1', '/permissions_1'); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'rolepermissions', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /* + * Tests for $this->Instance()->resetAssignments() + */ + + public function testResetPermRoleAssignments() + { + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); + $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); + + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + $this->Instance()->assign($role_id_2, $perm_id_2); + $this->Instance()->assign($role_id_3, $perm_id_3); + + $this->Instance()->resetAssignments(true); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'rolepermissions', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_reset_assignments_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /** + * @expectedException Exception + */ + + public function testResetPermRoleAssignmentsException() + { + $this->Instance()->resetAssignments(); + } + + /* + * Tests for $this->Instance()->reset() + */ + + public function testReset() + { + $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); + $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); + $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); + + $this->Instance()->reset(true); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . $this->type(), + )); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_reset_' . $this->type() . '.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /** + * @expectedException Exception + */ + + public function testResetException() + { + $this->Instance()->reset(); + } +} + +/** @} */ // End group phprbac_unit_test_wrapper_base */ diff --git a/PhpRbac/Tests/src/RbacManagerTest.php b/PhpRbac/Tests/RbacManagerTest.php similarity index 91% rename from PhpRbac/Tests/src/RbacManagerTest.php rename to PhpRbac/Tests/RbacManagerTest.php index 99bc9bd..521f93a 100644 --- a/PhpRbac/Tests/src/RbacManagerTest.php +++ b/PhpRbac/Tests/RbacManagerTest.php @@ -1,309 +1,311 @@ -assign() - */ - - public function testManagerAssignWithId() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->assign($role_id, $perm_id); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array(self::$rbac->tablePrefix() . 'userroles')); - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_id.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testManagerAssignWithTitle() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->assign('roles_1', 'permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array(self::$rbac->tablePrefix() . 'userroles')); - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_title.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testManagerAssignWithPath() - { - self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - - self::$rbac->assign('/roles_1/roles_2', '/permissions_1/permissions_2'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array(self::$rbac->tablePrefix() . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_path.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testManagerAssignWithNullRoleNullPermFalse() - { - $return = self::$rbac->assign(null, null); - - $this->assertFalse($return); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerAssignWithNullRoleNoPermError() - { - $return = self::$rbac->assign(null); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerAssignWithNoParametersError() - { - $return = self::$rbac->assign(null); - } - - /* - * Tests for self::$rbac->check() - */ - - public function testManagerCheckId() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->check($perm_id_1, 5); - - $this->assertTrue($result); - } - - public function testManagerCheckTitle() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->check('permissions_1', 5); - - $this->assertTrue($result); - } - - public function testManagerCheckPath() - { - self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); - $perm_id_1 = self::$rbac->Permissions->pathId('/permissions_1/permissions_2/permissions_3'); - - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id_1 = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Roles->assign($role_id_1, 3); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->check('/permissions_1/permissions_2', 5); - - $this->assertTrue($result); - } - - public function testManagerCheckBadPermBadUserFalse() - { - $result = self::$rbac->check(5, 5); - - $this->assertFalse($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testManagerCheckWithNullUserIdException() - { - self::$rbac->check(5, null); - } - - /** - * @expectedException RbacPermissionNotFoundException - */ - - public function testManagerCheckWithNullPermException() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->check(null, $perm_id); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerCheckWithNoUserIdException() - { - self::$rbac->check(5); - } - - /* - * Tests for self::$rbac->enforce() - */ - - public function testManagerEnforceId() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->enforce($perm_id_1, 5); - - $this->assertTrue($result); - } - - public function testManagerEnforceTitle() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->enforce('permissions_1', 5); - - $this->assertTrue($result); - } - - public function testManagerEnforcePath() - { - self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); - $perm_id_1 = self::$rbac->Permissions->pathId('/permissions_1/permissions_2/permissions_3'); - - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id_1 = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Roles->assign($role_id_1, 3); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->enforce('/permissions_1/permissions_2', 5); - - $this->assertTrue($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testManagerEnforceWithNullUserIdException() - { - self::$rbac->enforce(5, null); - } - - /** - * @expectedException RbacPermissionNotFoundException - */ - - public function testManagerEnforceWithNullPermException() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->enforce(null, $perm_id); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerEnforceWithNoUserIdException() - { - self::$rbac->enforce(5); - } - - /* - * Tests for self::$rbac->reset() - */ - - public function testManagerReset() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->reset(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_reset.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testManagerResetFalseException() - { - self::$rbac->reset(); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_manager */ +assign() + */ + + public function testManagerAssignWithId() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + self::$rbac->assign($role_id, $perm_id); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addExcludeTables(array(Jf::getConfig('table_prefix') . 'userroles')); + $filterDataSet->setExcludeColumnsForTable( + Jf::getConfig('table_prefix') . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_id.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testManagerAssignWithTitle() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + self::$rbac->assign('roles_1', 'permissions_1'); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addExcludeTables(array(Jf::getConfig('table_prefix') . 'userroles')); + $filterDataSet->setExcludeColumnsForTable( + Jf::getConfig('table_prefix') . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_title.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testManagerAssignWithPath() + { + self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); + self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); + + self::$rbac->assign('/roles_1/roles_2', '/permissions_1/permissions_2'); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addExcludeTables(array(Jf::getConfig('table_prefix') . 'userroles')); + + $filterDataSet->setExcludeColumnsForTable( + Jf::getConfig('table_prefix') . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_path.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testManagerAssignWithNullRoleNullPermFalse() + { + $return = self::$rbac->assign(null, null); + + $this->assertFalse($return); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testManagerAssignWithNullRoleNoPermError() + { + $return = self::$rbac->assign(null); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testManagerAssignWithNoParametersError() + { + $return = self::$rbac->assign(null); + } + + /* + * Tests for self::$rbac->check() + */ + + public function testManagerCheckId() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + + self::$rbac->Roles->assign($role_id_1, $perm_id_1); + self::$rbac->Users->assign($role_id_1, 5); + + $result = self::$rbac->check($perm_id_1, 5); + + $this->assertTrue($result); + } + + public function testManagerCheckTitle() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + + self::$rbac->Roles->assign($role_id_1, $perm_id_1); + self::$rbac->Users->assign($role_id_1, 5); + + $result = self::$rbac->check('permissions_1', 5); + + $this->assertTrue($result); + } + + public function testManagerCheckPath() + { + self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); + $perm_id_1 = self::$rbac->Permissions->pathId('/permissions_1/permissions_2/permissions_3'); + + self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); + $role_id_1 = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); + + self::$rbac->Roles->assign($role_id_1, 3); + self::$rbac->Users->assign($role_id_1, 5); + + $result = self::$rbac->check('/permissions_1/permissions_2', 5); + + $this->assertTrue($result); + } + + public function testManagerCheckBadPermBadUserFalse() + { + $result = self::$rbac->check(5, 5); + + $this->assertFalse($result); + } + + /** + * @expectedException RbacUserNotProvidedException + */ + + public function testManagerCheckWithNullUserIdException() + { + self::$rbac->check(5, null); + } + + /** + * @expectedException RbacPermissionNotFoundException + */ + + public function testManagerCheckWithNullPermException() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + self::$rbac->check(null, $perm_id); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testManagerCheckWithNoUserIdException() + { + self::$rbac->check(5); + } + + /* + * Tests for self::$rbac->enforce() + */ + + public function testManagerEnforceId() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + + self::$rbac->Roles->assign($role_id_1, $perm_id_1); + self::$rbac->Users->assign($role_id_1, 5); + + $result = self::$rbac->enforce($perm_id_1, 5); + + $this->assertTrue($result); + } + + public function testManagerEnforceTitle() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + + self::$rbac->Roles->assign($role_id_1, $perm_id_1); + self::$rbac->Users->assign($role_id_1, 5); + + $result = self::$rbac->enforce('permissions_1', 5); + + $this->assertTrue($result); + } + + public function testManagerEnforcePath() + { + self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); + $perm_id_1 = self::$rbac->Permissions->pathId('/permissions_1/permissions_2/permissions_3'); + + self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); + $role_id_1 = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); + + self::$rbac->Roles->assign($role_id_1, 3); + self::$rbac->Users->assign($role_id_1, 5); + + $result = self::$rbac->enforce('/permissions_1/permissions_2', 5); + + $this->assertTrue($result); + } + + /** + * @expectedException RbacUserNotProvidedException + */ + + public function testManagerEnforceWithNullUserIdException() + { + self::$rbac->enforce(5, null); + } + + /** + * @expectedException RbacPermissionNotFoundException + */ + + public function testManagerEnforceWithNullPermException() + { + $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + self::$rbac->enforce(null, $perm_id); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testManagerEnforceWithNoUserIdException() + { + self::$rbac->enforce(5); + } + + /* + * Tests for self::$rbac->reset() + */ + + public function testManagerReset() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + + self::$rbac->Roles->assign($role_id_1, $perm_id_1); + self::$rbac->Users->assign($role_id_1, 5); + + $result = self::$rbac->reset(true); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_reset.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /** + * @expectedException Exception + */ + + public function testManagerResetFalseException() + { + self::$rbac->reset(); + } +} + +/** @} */ // End group phprbac_unit_test_wrapper_manager */ diff --git a/PhpRbac/Tests/src/RbacPermissionsTest.php b/PhpRbac/Tests/RbacPermissionsTest.php similarity index 96% rename from PhpRbac/Tests/src/RbacPermissionsTest.php rename to PhpRbac/Tests/RbacPermissionsTest.php index 5793f4b..b926a19 100644 --- a/PhpRbac/Tests/src/RbacPermissionsTest.php +++ b/PhpRbac/Tests/RbacPermissionsTest.php @@ -1,232 +1,234 @@ -Permissions; - } - - protected function type() - { - return "permissions"; - } - - /* - * Test for proper object instantiation - */ - - public function testPermissionsInstance() { - $this->assertInstanceOf('PermissionManager', self::$rbac->Permissions); - } - - /* - * Tests for $this->Instance()->remove() - */ - - public function testPermissionsRemoveSingle() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->remove($perm_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - )); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsRemoveSingleRole() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - - $this->Instance()->remove($perm_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - $this->Instance()->tablePrefix() . 'rolepermissions', - $this->Instance()->tablePrefix() . 'roles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single_role.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsRemoveRecursive() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $perm_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2', $perm_id_1); - $perm_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3', $perm_id_1); - $perm_id_4 = $this->Instance()->add($this->type() . '_4', $this->type() . ' Description 4'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_2); - - $result = $this->Instance()->remove($perm_id_1, true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - $this->Instance()->tablePrefix() . 'rolepermissions', - $this->Instance()->tablePrefix() . 'roles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_recursive.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsRemoveFalse() - { - $result = $this->Instance()->remove(5); - - $this->assertFalse($result); - } - - /* - * Tests for $this->Instance()->roles() - */ - - public function testPermissionsRolesOnlyID() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_2, $perm_id_1); - $this->Instance()->assign($role_id_3, $perm_id_1); - - $result = $this->Instance()->roles($perm_id_1); - - $expected = array('2', '3', '4'); - - $this->assertSame($expected, $result); - } - - public function testPermissionsRolesBadIDNull() - { - $result = $this->Instance()->roles(20); - - $this->assertNull($result); - } - - public function testPermissionsRolesNotOnlyID() - { - self::$rbac->Roles->addPath("/roles_1/roles_2"); - self::$rbac->Permissions->addPath("/permissions_1/permissions_2"); - - self::$rbac->assign("/roles_1/roles_2", "/permissions_1/permissions_2"); - - $rolesAssigned = self::$rbac->Permissions->roles('/permissions_1/permissions_2', false); - - $expected = array( - array( - 'ID' => '3', - 'Title' => 'roles_2', - 'Description' => '', - ), - ); - - $this->assertSame($expected, $rolesAssigned); - } - - public function testPermissionsRolesNotOnlyIDNullBadParameters() - { - $rolesAssigned = self::$rbac->Permissions->roles('/permissions_1/permissions_2', false); - - $this->assertSame(null, $rolesAssigned); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testPermissionsRolesPassNothing() - { - $result = $this->Instance()->roles(); - } - - /* - * Tests for $this->Instance()->unassignRoles() - */ - - public function testPermissionsUnassignRoles() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_2, $perm_id_1); - $this->Instance()->assign($role_id_3, $perm_id_1); - - $result = $this->Instance()->unassignRoles($perm_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_roles.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsUnassignRolesBadID() - { - $result = $this->Instance()->unassignRoles(20); - - $this->assertSame(0, $result); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_permission_manager */ +Permissions; + } + + protected function type() + { + return "permissions"; + } + + /* + * Test for proper object instantiation + */ + + public function testPermissionsInstance() { + $this->assertInstanceOf('PermissionManager', self::$rbac->Permissions); + } + + /* + * Tests for $this->Instance()->remove() + */ + + public function testPermissionsRemoveSingle() + { + $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $this->Instance()->remove($perm_id_1); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . $this->type(), + )); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testPermissionsRemoveSingleRole() + { + $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + + $this->Instance()->remove($perm_id_1); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . $this->type(), + $this->Instance()->tablePrefix() . 'rolepermissions', + $this->Instance()->tablePrefix() . 'roles', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single_role.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testPermissionsRemoveRecursive() + { + $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + $perm_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2', $perm_id_1); + $perm_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3', $perm_id_1); + $perm_id_4 = $this->Instance()->add($this->type() . '_4', $this->type() . ' Description 4'); + + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + $this->Instance()->assign($role_id_1, $perm_id_2); + + $result = $this->Instance()->remove($perm_id_1, true); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . $this->type(), + $this->Instance()->tablePrefix() . 'rolepermissions', + $this->Instance()->tablePrefix() . 'roles', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_recursive.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testPermissionsRemoveFalse() + { + $result = $this->Instance()->remove(5); + + $this->assertFalse($result); + } + + /* + * Tests for $this->Instance()->roles() + */ + + public function testPermissionsRolesOnlyID() + { + $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + $this->Instance()->assign($role_id_2, $perm_id_1); + $this->Instance()->assign($role_id_3, $perm_id_1); + + $result = $this->Instance()->roles($perm_id_1); + + $expected = array('2', '3', '4'); + + $this->assertSame($expected, $result); + } + + public function testPermissionsRolesBadIDNull() + { + $result = $this->Instance()->roles(20); + + $this->assertNull($result); + } + + public function testPermissionsRolesNotOnlyID() + { + self::$rbac->Roles->addPath("/roles_1/roles_2"); + self::$rbac->Permissions->addPath("/permissions_1/permissions_2"); + + self::$rbac->assign("/roles_1/roles_2", "/permissions_1/permissions_2"); + + $rolesAssigned = self::$rbac->Permissions->roles('/permissions_1/permissions_2', false); + + $expected = array( + array( + 'ID' => '3', + 'Title' => 'roles_2', + 'Description' => '', + ), + ); + + $this->assertSame($expected, $rolesAssigned); + } + + public function testPermissionsRolesNotOnlyIDNullBadParameters() + { + $rolesAssigned = self::$rbac->Permissions->roles('/permissions_1/permissions_2', false); + + $this->assertSame(null, $rolesAssigned); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testPermissionsRolesPassNothing() + { + $result = $this->Instance()->roles(); + } + + /* + * Tests for $this->Instance()->unassignRoles() + */ + + public function testPermissionsUnassignRoles() + { + $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + $this->Instance()->assign($role_id_2, $perm_id_1); + $this->Instance()->assign($role_id_3, $perm_id_1); + + $result = $this->Instance()->unassignRoles($perm_id_1); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . 'rolepermissions', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_roles.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testPermissionsUnassignRolesBadID() + { + $result = $this->Instance()->unassignRoles(20); + + $this->assertSame(0, $result); + } +} + +/** @} */ // End group phprbac_unit_test_wrapper_permission_manager */ diff --git a/PhpRbac/Tests/src/RbacRolesTest.php b/PhpRbac/Tests/RbacRolesTest.php similarity index 96% rename from PhpRbac/Tests/src/RbacRolesTest.php rename to PhpRbac/Tests/RbacRolesTest.php index 6ab1966..fd8f002 100644 --- a/PhpRbac/Tests/src/RbacRolesTest.php +++ b/PhpRbac/Tests/RbacRolesTest.php @@ -1,309 +1,311 @@ -Roles; - } - - protected function type() - { - return "roles"; - } - - /* - * Test for proper object instantiation - */ - - public function testRolesInstance() { - $this->assertInstanceOf('RoleManager', self::$rbac->Roles); - } - - /* - * Tests for self::$rbac->Roles->permissions() - */ - - public function testRolesPermissionsIdOnly() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_1, $perm_id_2); - $this->Instance()->assign($role_id_1, $perm_id_3); - - $result = $this->Instance()->permissions($perm_id_1); - - $expected = array('2', '3', '4'); - - $this->assertSame($expected, $result); - } - - public function testRolesPermissionsNotOnlyID() - { - self::$rbac->Roles->addPath("/roles_1/roles_2"); - self::$rbac->Permissions->addPath("/permissions_1/permissions_2"); - - self::$rbac->assign("/roles_1/roles_2", "/permissions_1/permissions_2"); - - $permissionsAssigned = self::$rbac->Roles->permissions('/roles_1/roles_2', false); - - $expected = array( - array( - 'ID' => '3', - 'Title' => 'permissions_2', - 'Description' => '', - ), - ); - - $this->assertSame($expected, $permissionsAssigned); - } - - public function testRolesPermissionsNotOnlyIDNullBadParameters() - { - $rolesAssigned = self::$rbac->Roles->permissions('/roles_1/roles_2', false); - - $this->assertSame(null, $rolesAssigned); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testRolesPermissionsPassNothing() - { - $result = $this->Instance()->permissions(); - } - - /* - * Tests for self::$rbac->Roles->hasPermission() - */ - - public function testRolesHasPermission() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - - $result = self::$rbac->Roles->hasPermission($role_id_1, $perm_id_1); - - $this->assertTrue($result); - } - - public function testRolesHasPermissionFalse() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $result = self::$rbac->Roles->hasPermission($role_id_1, 4); - - $this->assertFalse($result); - } - - /* - * Tests for self::$rbac->Roles->unassignPermissions() - */ - - public function testRolesUnassignPermissions() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_1, $perm_id_2); - $this->Instance()->assign($role_id_1, $perm_id_3); - - $result = $this->Instance()->unassignPermissions($role_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_permissions.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesUnassignPermissionsBadID() - { - $result = $this->Instance()->unassignPermissions(20); - - $this->assertSame(0, $result); - } - - /* - * Tests for self::$rbac->Roles->unassignUsers() - */ - - public function testRolesUnassignUsers() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_2 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_3 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - $result = $this->Instance()->unassignUsers($role_id_2); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_users.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesUnassignUsersBadID() - { - $result = $this->Instance()->unassignUsers(20); - - $this->assertSame(0, $result); - } - - /* - * Tests for self::$rbac->Roles->remove() - */ - - public function testRolesRemoveSingle() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->remove($role_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - )); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesRemoveSinglePermission() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); - - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2'); - $role_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_1, $perm_id_2); - $this->Instance()->assign($role_id_1, $perm_id_3); - - self::$rbac->Users->assign($role_id_1, 5); - - $this->Instance()->remove($role_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array( - $this->Instance()->tablePrefix() . 'permissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single_permission.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesRemoveRecursive() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2', $role_id_1); - $role_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3', $role_id_1); - $role_id_4 = $this->Instance()->add($this->type() . '_4', $this->type() . ' Description 4'); - - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - - self::$rbac->Users->assign($role_id_1, 5); - - $result = $this->Instance()->remove($role_id_1, true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'rolepermissions', - $this->Instance()->tablePrefix() . $this->type(), - $this->Instance()->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_recursive.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesRemoveFalse() - { - $result = $this->Instance()->remove(5); - - $this->assertFalse($result); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_role_manager */ +Roles; + } + + protected function type() + { + return "roles"; + } + + /* + * Test for proper object instantiation + */ + + public function testRolesInstance() { + $this->assertInstanceOf('RoleManager', self::$rbac->Roles); + } + + /* + * Tests for self::$rbac->Roles->permissions() + */ + + public function testRolesPermissionsIdOnly() + { + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $perm_id_2 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $perm_id_3 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + $this->Instance()->assign($role_id_1, $perm_id_2); + $this->Instance()->assign($role_id_1, $perm_id_3); + + $result = $this->Instance()->permissions($perm_id_1); + + $expected = array('2', '3', '4'); + + $this->assertSame($expected, $result); + } + + public function testRolesPermissionsNotOnlyID() + { + self::$rbac->Roles->addPath("/roles_1/roles_2"); + self::$rbac->Permissions->addPath("/permissions_1/permissions_2"); + + self::$rbac->assign("/roles_1/roles_2", "/permissions_1/permissions_2"); + + $permissionsAssigned = self::$rbac->Roles->permissions('/roles_1/roles_2', false); + + $expected = array( + array( + 'ID' => '3', + 'Title' => 'permissions_2', + 'Description' => '', + ), + ); + + $this->assertSame($expected, $permissionsAssigned); + } + + public function testRolesPermissionsNotOnlyIDNullBadParameters() + { + $rolesAssigned = self::$rbac->Roles->permissions('/roles_1/roles_2', false); + + $this->assertSame(null, $rolesAssigned); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testRolesPermissionsPassNothing() + { + $result = $this->Instance()->permissions(); + } + + /* + * Tests for self::$rbac->Roles->hasPermission() + */ + + public function testRolesHasPermission() + { + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + + $result = self::$rbac->Roles->hasPermission($role_id_1, $perm_id_1); + + $this->assertTrue($result); + } + + public function testRolesHasPermissionFalse() + { + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $result = self::$rbac->Roles->hasPermission($role_id_1, 4); + + $this->assertFalse($result); + } + + /* + * Tests for self::$rbac->Roles->unassignPermissions() + */ + + public function testRolesUnassignPermissions() + { + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); + $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + $this->Instance()->assign($role_id_1, $perm_id_2); + $this->Instance()->assign($role_id_1, $perm_id_3); + + $result = $this->Instance()->unassignPermissions($role_id_1); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . 'rolepermissions', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_permissions.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testRolesUnassignPermissionsBadID() + { + $result = $this->Instance()->unassignPermissions(20); + + $this->assertSame(0, $result); + } + + /* + * Tests for self::$rbac->Roles->unassignUsers() + */ + + public function testRolesUnassignUsers() + { + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + $role_id_2 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + $role_id_3 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + self::$rbac->Users->assign($role_id_1, 5); + self::$rbac->Users->assign($role_id_2, 5); + self::$rbac->Users->assign($role_id_3, 5); + + $result = $this->Instance()->unassignUsers($role_id_2); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_users.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testRolesUnassignUsersBadID() + { + $result = $this->Instance()->unassignUsers(20); + + $this->assertSame(0, $result); + } + + /* + * Tests for self::$rbac->Roles->remove() + */ + + public function testRolesRemoveSingle() + { + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + + $this->Instance()->remove($role_id_1); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . $this->type(), + )); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testRolesRemoveSinglePermission() + { + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); + $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); + + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + $role_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2'); + $role_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + $this->Instance()->assign($role_id_1, $perm_id_2); + $this->Instance()->assign($role_id_1, $perm_id_3); + + self::$rbac->Users->assign($role_id_1, 5); + + $this->Instance()->remove($role_id_1); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addExcludeTables(array( + $this->Instance()->tablePrefix() . 'permissions', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single_permission.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testRolesRemoveRecursive() + { + $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); + $role_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2', $role_id_1); + $role_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3', $role_id_1); + $role_id_4 = $this->Instance()->add($this->type() . '_4', $this->type() . ' Description 4'); + + $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); + + $this->Instance()->assign($role_id_1, $perm_id_1); + + self::$rbac->Users->assign($role_id_1, 5); + + $result = $this->Instance()->remove($role_id_1, true); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + $this->Instance()->tablePrefix() . 'rolepermissions', + $this->Instance()->tablePrefix() . $this->type(), + $this->Instance()->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'rolepermissions', + array('AssignmentDate') + ); + + $filterDataSet->setExcludeColumnsForTable( + $this->Instance()->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_recursive.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testRolesRemoveFalse() + { + $result = $this->Instance()->remove(5); + + $this->assertFalse($result); + } +} + +/** @} */ // End group phprbac_unit_test_wrapper_role_manager */ diff --git a/PhpRbac/Tests/src/RbacSetup.php b/PhpRbac/Tests/RbacSetup.php similarity index 75% rename from PhpRbac/Tests/src/RbacSetup.php rename to PhpRbac/Tests/RbacSetup.php index 676a972..4266c89 100644 --- a/PhpRbac/Tests/src/RbacSetup.php +++ b/PhpRbac/Tests/RbacSetup.php @@ -1,54 +1,58 @@ -reset(true); - } - } - - protected function tearDown() - { - if ((string) $GLOBALS['DB_ADAPTER'] === 'pdo_sqlite') { - self::$rbac->reset(true); - } - } - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/datasets/database-seed.xml'); - } - - /* - * Tests for proper object instantiation - */ - - public function testRbacInstance() { - $this->assertInstanceOf('PhpRbac\Rbac', self::$rbac); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_setup */ +reset(true); + } + } + + protected function tearDown() + { + if (Jf::getConfig('adapter') === 'pdo_sqlite') { + self::$rbac->reset(true); + } + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/datasets/database-seed.xml'); + } + + /* + * Tests for proper object instantiation + */ + + public function testRbacInstance() { + $this->assertInstanceOf('PhpRbac\Rbac', self::$rbac); + } +} + +/** @} */ // End group phprbac_unit_test_wrapper_setup */ diff --git a/PhpRbac/Tests/src/RbacUsersTest.php b/PhpRbac/Tests/RbacUsersTest.php similarity index 96% rename from PhpRbac/Tests/src/RbacUsersTest.php rename to PhpRbac/Tests/RbacUsersTest.php index 63e4354..6c04f4e 100644 --- a/PhpRbac/Tests/src/RbacUsersTest.php +++ b/PhpRbac/Tests/RbacUsersTest.php @@ -1,419 +1,421 @@ -assertInstanceOf('RbacUserManager', self::$rbac->Users); - } - - /* - * Tests for self::$rbac->Users->assign() - */ - - public function testUsersAssignWithId() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_assign_with_id.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUsersAssignWithPath() - { - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Users->assign('/roles_1/roles_2', 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_assign_with_path.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersAssignNoUserID() - { - $result = self::$rbac->Users->assign(5); - - $this->assertFalse($result); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testUsersAssignPassNothing() - { - $result = self::$rbac->Users->assign(); - } - - /* - * Tests for self::$rbac->Users->hasRole() - */ - - public function testUsersHasRoleId() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole($role_id, 5); - - $this->assertTrue($result); - } - - public function testUsersHasRoleTitle() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole('roles_1', 5); - - $this->assertTrue($result); - } - - public function testUsersHasRolePath() - { - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole('/roles_1/roles_2/roles_3', 5); - - $this->assertTrue($result); - } - - public function testUsersHasRoleDoesNotHaveRole() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole(1, 5); - - $this->assertFalse($result); - } - - public function testUsersHasRoleNullRole() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole(null, 5); - - $this->assertFalse($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersHasRoleNoUserId() - { - $result = self::$rbac->Users->hasRole(5); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testUsersHasRolePassNothing() - { - $result = self::$rbac->Users->hasRole(); - } - - /* - * Tests for self::$rbac->Users->allRoles() - */ - - public function testUsersAllRoles() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - $result = self::$rbac->Users->allRoles(5); - - $expected = array( - array( - 'ID' => '2', - 'Lft' => '1', - 'Rght' => '2', - 'Title' => 'roles_1', - 'Description' => 'roles Description 1', - ), - array( - 'ID' => '3', - 'Lft' => '3', - 'Rght' => '4', - 'Title' => 'roles_2', - 'Description' => 'roles Description 2', - ), - array( - 'ID' => '4', - 'Lft' => '5', - 'Rght' => '6', - 'Title' => 'roles_3', - 'Description' => 'roles Description 3', - ), - ); - - $this->assertSame($expected, $result); - } - - public function testUsersAllRolesBadRoleNull() - { - $result = self::$rbac->Users->allRoles(10); - - $this->assertNull($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersAllRolesNoRolesEmpty() - { - $result = self::$rbac->Users->allRoles(); - } - - /* - * Tests for self::$rbac->Users->roleCount() - */ - - public function testUsersRoleCount() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - $result = self::$rbac->Users->roleCount(5); - - $this->assertSame(3, $result); - } - - public function testUsersRoleCountNoRoles() - { - $result = self::$rbac->Users->roleCount(10); - - $this->assertSame(0, $result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersRoleCountNoRolesEmpty() - { - $result = self::$rbac->Users->roleCount(); - } - - /* - * Tests for self::$rbac->Users->unassign() - */ - - public function testUsersUnassignId() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->unassign($role_id_2, 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUsersUnassignTitle() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->unassign('roles_2', 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUsersUnassignPath() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->unassign('/roles_2', 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersUnassignNoUserIdException() - { - $result = self::$rbac->Users->unassign(5); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testUsersUnassignNoRolesException() - { - $result = self::$rbac->Users->unassign(); - } - - /* - * Tests for self::$rbac->Users->resetAssignments() - */ - - public function testUsersResetAssignments() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->resetAssignments(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_reset_assignments.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testUsersResetAssignmentsException() - { - self::$rbac->Users->resetAssignments(); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_user_manager */ +assertInstanceOf('RbacUserManager', self::$rbac->Users); + } + + /* + * Tests for self::$rbac->Users->assign() + */ + + public function testUsersAssignWithId() + { + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + self::$rbac->Users->assign($role_id, 5); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->Users->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_assign_with_id.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testUsersAssignWithPath() + { + self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); + $role_id = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); + + self::$rbac->Users->assign('/roles_1/roles_2', 5); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->Users->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_assign_with_path.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /** + * @expectedException RbacUserNotProvidedException + */ + + public function testUsersAssignNoUserID() + { + $result = self::$rbac->Users->assign(5); + + $this->assertFalse($result); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testUsersAssignPassNothing() + { + $result = self::$rbac->Users->assign(); + } + + /* + * Tests for self::$rbac->Users->hasRole() + */ + + public function testUsersHasRoleId() + { + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + self::$rbac->Users->assign($role_id, 5); + + $result = self::$rbac->Users->hasRole($role_id, 5); + + $this->assertTrue($result); + } + + public function testUsersHasRoleTitle() + { + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + self::$rbac->Users->assign($role_id, 5); + + $result = self::$rbac->Users->hasRole('roles_1', 5); + + $this->assertTrue($result); + } + + public function testUsersHasRolePath() + { + self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); + $role_id = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); + + self::$rbac->Users->assign($role_id, 5); + + $result = self::$rbac->Users->hasRole('/roles_1/roles_2/roles_3', 5); + + $this->assertTrue($result); + } + + public function testUsersHasRoleDoesNotHaveRole() + { + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + self::$rbac->Users->assign($role_id, 5); + + $result = self::$rbac->Users->hasRole(1, 5); + + $this->assertFalse($result); + } + + public function testUsersHasRoleNullRole() + { + $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + + self::$rbac->Users->assign($role_id, 5); + + $result = self::$rbac->Users->hasRole(null, 5); + + $this->assertFalse($result); + } + + /** + * @expectedException RbacUserNotProvidedException + */ + + public function testUsersHasRoleNoUserId() + { + $result = self::$rbac->Users->hasRole(5); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testUsersHasRolePassNothing() + { + $result = self::$rbac->Users->hasRole(); + } + + /* + * Tests for self::$rbac->Users->allRoles() + */ + + public function testUsersAllRoles() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + self::$rbac->Users->assign($role_id_1, 5); + self::$rbac->Users->assign($role_id_2, 5); + self::$rbac->Users->assign($role_id_3, 5); + + $result = self::$rbac->Users->allRoles(5); + + $expected = array( + array( + 'ID' => '2', + 'Lft' => '1', + 'Rght' => '2', + 'Title' => 'roles_1', + 'Description' => 'roles Description 1', + ), + array( + 'ID' => '3', + 'Lft' => '3', + 'Rght' => '4', + 'Title' => 'roles_2', + 'Description' => 'roles Description 2', + ), + array( + 'ID' => '4', + 'Lft' => '5', + 'Rght' => '6', + 'Title' => 'roles_3', + 'Description' => 'roles Description 3', + ), + ); + + $this->assertSame($expected, $result); + } + + public function testUsersAllRolesBadRoleNull() + { + $result = self::$rbac->Users->allRoles(10); + + $this->assertNull($result); + } + + /** + * @expectedException RbacUserNotProvidedException + */ + + public function testUsersAllRolesNoRolesEmpty() + { + $result = self::$rbac->Users->allRoles(); + } + + /* + * Tests for self::$rbac->Users->roleCount() + */ + + public function testUsersRoleCount() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + self::$rbac->Users->assign($role_id_1, 5); + self::$rbac->Users->assign($role_id_2, 5); + self::$rbac->Users->assign($role_id_3, 5); + + $result = self::$rbac->Users->roleCount(5); + + $this->assertSame(3, $result); + } + + public function testUsersRoleCountNoRoles() + { + $result = self::$rbac->Users->roleCount(10); + + $this->assertSame(0, $result); + } + + /** + * @expectedException RbacUserNotProvidedException + */ + + public function testUsersRoleCountNoRolesEmpty() + { + $result = self::$rbac->Users->roleCount(); + } + + /* + * Tests for self::$rbac->Users->unassign() + */ + + public function testUsersUnassignId() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + self::$rbac->Users->assign($role_id_1, 5); + self::$rbac->Users->assign($role_id_2, 5); + self::$rbac->Users->assign($role_id_3, 5); + + self::$rbac->Users->unassign($role_id_2, 5); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->Users->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testUsersUnassignTitle() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + self::$rbac->Users->assign($role_id_1, 5); + self::$rbac->Users->assign($role_id_2, 5); + self::$rbac->Users->assign($role_id_3, 5); + + self::$rbac->Users->unassign('roles_2', 5); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->Users->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + public function testUsersUnassignPath() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + self::$rbac->Users->assign($role_id_1, 5); + self::$rbac->Users->assign($role_id_2, 5); + self::$rbac->Users->assign($role_id_3, 5); + + self::$rbac->Users->unassign('/roles_2', 5); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->Users->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /** + * @expectedException RbacUserNotProvidedException + */ + + public function testUsersUnassignNoUserIdException() + { + $result = self::$rbac->Users->unassign(5); + } + + /** + * @expectedException PHPUnit_Framework_Error + */ + + public function testUsersUnassignNoRolesException() + { + $result = self::$rbac->Users->unassign(); + } + + /* + * Tests for self::$rbac->Users->resetAssignments() + */ + + public function testUsersResetAssignments() + { + $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); + $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); + $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); + + self::$rbac->Users->assign($role_id_1, 5); + self::$rbac->Users->assign($role_id_2, 5); + self::$rbac->Users->assign($role_id_3, 5); + + self::$rbac->Users->resetAssignments(true); + + $dataSet = $this->getConnection()->createDataSet(); + + $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); + $filterDataSet->addIncludeTables(array( + self::$rbac->Users->tablePrefix() . 'userroles', + )); + + $filterDataSet->setExcludeColumnsForTable( + self::$rbac->Users->tablePrefix() . 'userroles', + array('AssignmentDate') + ); + + $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_reset_assignments.xml'); + + $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); + } + + /** + * @expectedException Exception + */ + + public function testUsersResetAssignmentsException() + { + self::$rbac->Users->resetAssignments(); + } +} + +/** @} */ // End group phprbac_unit_test_wrapper_user_manager */ diff --git a/PhpRbac/Tests/bootstrap.php b/PhpRbac/Tests/bootstrap.php index 121e833..66f88eb 100644 --- a/PhpRbac/Tests/bootstrap.php +++ b/PhpRbac/Tests/bootstrap.php @@ -3,4 +3,4 @@ error_reporting(E_ALL); // autoloader -require dirname(__DIR__) . '/autoload.php'; +require __DIR__ . '/../../vendor/autoload.php'; \ No newline at end of file diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_hierarchy.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_hierarchy_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_hierarchy_description.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_sequential.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_sequential_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_sequential_description.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_single.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_single.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_permissions_single.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_single_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_permissions_single_description.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_permissions_single_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_roles_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_roles_hierarchy.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_roles_hierarchy_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_roles_hierarchy_description.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_roles_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_roles_sequential.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_roles_sequential_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_roles_sequential_description.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_roles_single.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_single.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_roles_single.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_roles_single.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_path_roles_single_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_single_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_path_roles_single_description.xml rename to PhpRbac/Tests/datasets/base/expected_add_path_roles_single_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_permissions_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_permissions_hierarchy.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_permissions_hierarchy.xml rename to PhpRbac/Tests/datasets/base/expected_add_permissions_hierarchy.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_permissions_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_permissions_sequential.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_permissions_sequential.xml rename to PhpRbac/Tests/datasets/base/expected_add_permissions_sequential.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_roles_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_roles_hierarchy.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_roles_hierarchy.xml rename to PhpRbac/Tests/datasets/base/expected_add_roles_hierarchy.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_add_roles_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_roles_sequential.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_add_roles_sequential.xml rename to PhpRbac/Tests/datasets/base/expected_add_roles_sequential.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_assign_permissions.xml b/PhpRbac/Tests/datasets/base/expected_assign_permissions.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_assign_permissions.xml rename to PhpRbac/Tests/datasets/base/expected_assign_permissions.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_assign_roles.xml b/PhpRbac/Tests/datasets/base/expected_assign_roles.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_assign_roles.xml rename to PhpRbac/Tests/datasets/base/expected_assign_roles.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_edit_permissions_all.xml b/PhpRbac/Tests/datasets/base/expected_edit_permissions_all.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_edit_permissions_all.xml rename to PhpRbac/Tests/datasets/base/expected_edit_permissions_all.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_edit_permissions_description.xml b/PhpRbac/Tests/datasets/base/expected_edit_permissions_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_edit_permissions_description.xml rename to PhpRbac/Tests/datasets/base/expected_edit_permissions_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_edit_permissions_title.xml b/PhpRbac/Tests/datasets/base/expected_edit_permissions_title.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_edit_permissions_title.xml rename to PhpRbac/Tests/datasets/base/expected_edit_permissions_title.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_edit_roles_all.xml b/PhpRbac/Tests/datasets/base/expected_edit_roles_all.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_edit_roles_all.xml rename to PhpRbac/Tests/datasets/base/expected_edit_roles_all.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_edit_roles_description.xml b/PhpRbac/Tests/datasets/base/expected_edit_roles_description.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_edit_roles_description.xml rename to PhpRbac/Tests/datasets/base/expected_edit_roles_description.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_edit_roles_title.xml b/PhpRbac/Tests/datasets/base/expected_edit_roles_title.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_edit_roles_title.xml rename to PhpRbac/Tests/datasets/base/expected_edit_roles_title.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_reset_assignments_permissions.xml b/PhpRbac/Tests/datasets/base/expected_reset_assignments_permissions.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_reset_assignments_permissions.xml rename to PhpRbac/Tests/datasets/base/expected_reset_assignments_permissions.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_reset_assignments_roles.xml b/PhpRbac/Tests/datasets/base/expected_reset_assignments_roles.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_reset_assignments_roles.xml rename to PhpRbac/Tests/datasets/base/expected_reset_assignments_roles.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_reset_permissions.xml b/PhpRbac/Tests/datasets/base/expected_reset_permissions.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_reset_permissions.xml rename to PhpRbac/Tests/datasets/base/expected_reset_permissions.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_reset_roles.xml b/PhpRbac/Tests/datasets/base/expected_reset_roles.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_reset_roles.xml rename to PhpRbac/Tests/datasets/base/expected_reset_roles.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_unassign_permissions.xml b/PhpRbac/Tests/datasets/base/expected_unassign_permissions.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_unassign_permissions.xml rename to PhpRbac/Tests/datasets/base/expected_unassign_permissions.xml diff --git a/PhpRbac/Tests/src/datasets/base/expected_unassign_roles.xml b/PhpRbac/Tests/datasets/base/expected_unassign_roles.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/base/expected_unassign_roles.xml rename to PhpRbac/Tests/datasets/base/expected_unassign_roles.xml diff --git a/PhpRbac/Tests/src/datasets/database-seed.xml b/PhpRbac/Tests/datasets/database-seed.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/database-seed.xml rename to PhpRbac/Tests/datasets/database-seed.xml diff --git a/PhpRbac/Tests/src/datasets/manager/expected_assign_id.xml b/PhpRbac/Tests/datasets/manager/expected_assign_id.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/manager/expected_assign_id.xml rename to PhpRbac/Tests/datasets/manager/expected_assign_id.xml diff --git a/PhpRbac/Tests/src/datasets/manager/expected_assign_path.xml b/PhpRbac/Tests/datasets/manager/expected_assign_path.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/manager/expected_assign_path.xml rename to PhpRbac/Tests/datasets/manager/expected_assign_path.xml diff --git a/PhpRbac/Tests/src/datasets/manager/expected_assign_title.xml b/PhpRbac/Tests/datasets/manager/expected_assign_title.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/manager/expected_assign_title.xml rename to PhpRbac/Tests/datasets/manager/expected_assign_title.xml diff --git a/PhpRbac/Tests/src/datasets/manager/expected_reset.xml b/PhpRbac/Tests/datasets/manager/expected_reset.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/manager/expected_reset.xml rename to PhpRbac/Tests/datasets/manager/expected_reset.xml diff --git a/PhpRbac/Tests/src/datasets/permissions/expected_remove_recursive.xml b/PhpRbac/Tests/datasets/permissions/expected_remove_recursive.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/permissions/expected_remove_recursive.xml rename to PhpRbac/Tests/datasets/permissions/expected_remove_recursive.xml diff --git a/PhpRbac/Tests/src/datasets/permissions/expected_remove_single.xml b/PhpRbac/Tests/datasets/permissions/expected_remove_single.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/permissions/expected_remove_single.xml rename to PhpRbac/Tests/datasets/permissions/expected_remove_single.xml diff --git a/PhpRbac/Tests/src/datasets/permissions/expected_remove_single_role.xml b/PhpRbac/Tests/datasets/permissions/expected_remove_single_role.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/permissions/expected_remove_single_role.xml rename to PhpRbac/Tests/datasets/permissions/expected_remove_single_role.xml diff --git a/PhpRbac/Tests/src/datasets/permissions/expected_unassign_roles.xml b/PhpRbac/Tests/datasets/permissions/expected_unassign_roles.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/permissions/expected_unassign_roles.xml rename to PhpRbac/Tests/datasets/permissions/expected_unassign_roles.xml diff --git a/PhpRbac/Tests/src/datasets/roles/expected_remove_recursive.xml b/PhpRbac/Tests/datasets/roles/expected_remove_recursive.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/roles/expected_remove_recursive.xml rename to PhpRbac/Tests/datasets/roles/expected_remove_recursive.xml diff --git a/PhpRbac/Tests/src/datasets/roles/expected_remove_single.xml b/PhpRbac/Tests/datasets/roles/expected_remove_single.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/roles/expected_remove_single.xml rename to PhpRbac/Tests/datasets/roles/expected_remove_single.xml diff --git a/PhpRbac/Tests/src/datasets/roles/expected_remove_single_permission.xml b/PhpRbac/Tests/datasets/roles/expected_remove_single_permission.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/roles/expected_remove_single_permission.xml rename to PhpRbac/Tests/datasets/roles/expected_remove_single_permission.xml diff --git a/PhpRbac/Tests/src/datasets/roles/expected_unassign_permissions.xml b/PhpRbac/Tests/datasets/roles/expected_unassign_permissions.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/roles/expected_unassign_permissions.xml rename to PhpRbac/Tests/datasets/roles/expected_unassign_permissions.xml diff --git a/PhpRbac/Tests/src/datasets/roles/expected_unassign_users.xml b/PhpRbac/Tests/datasets/roles/expected_unassign_users.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/roles/expected_unassign_users.xml rename to PhpRbac/Tests/datasets/roles/expected_unassign_users.xml diff --git a/PhpRbac/Tests/src/datasets/users/expected_assign_no_id.xml b/PhpRbac/Tests/datasets/users/expected_assign_no_id.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/users/expected_assign_no_id.xml rename to PhpRbac/Tests/datasets/users/expected_assign_no_id.xml diff --git a/PhpRbac/Tests/src/datasets/users/expected_assign_with_id.xml b/PhpRbac/Tests/datasets/users/expected_assign_with_id.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/users/expected_assign_with_id.xml rename to PhpRbac/Tests/datasets/users/expected_assign_with_id.xml diff --git a/PhpRbac/Tests/src/datasets/users/expected_assign_with_path.xml b/PhpRbac/Tests/datasets/users/expected_assign_with_path.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/users/expected_assign_with_path.xml rename to PhpRbac/Tests/datasets/users/expected_assign_with_path.xml diff --git a/PhpRbac/Tests/src/datasets/users/expected_reset_assignments.xml b/PhpRbac/Tests/datasets/users/expected_reset_assignments.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/users/expected_reset_assignments.xml rename to PhpRbac/Tests/datasets/users/expected_reset_assignments.xml diff --git a/PhpRbac/Tests/src/datasets/users/expected_unassign.xml b/PhpRbac/Tests/datasets/users/expected_unassign.xml similarity index 100% rename from PhpRbac/Tests/src/datasets/users/expected_unassign.xml rename to PhpRbac/Tests/datasets/users/expected_unassign.xml diff --git a/PhpRbac/Tests/phpunit_mysql.xml b/PhpRbac/Tests/phpunit_mysql.xml index f8258a6..946a890 100644 --- a/PhpRbac/Tests/phpunit_mysql.xml +++ b/PhpRbac/Tests/phpunit_mysql.xml @@ -1,14 +1,10 @@ - ./src + . - - - - - + diff --git a/PhpRbac/Tests/phpunit_sqlite.xml b/PhpRbac/Tests/phpunit_sqlite.xml index d577ec7..b7e52b8 100644 --- a/PhpRbac/Tests/phpunit_sqlite.xml +++ b/PhpRbac/Tests/phpunit_sqlite.xml @@ -1,7 +1,7 @@ - ./src + . diff --git a/PhpRbac/Tests/src/Generic_Tests_DatabaseTestCase.php b/PhpRbac/Tests/src/Generic_Tests_DatabaseTestCase.php deleted file mode 100644 index 68feb5d..0000000 --- a/PhpRbac/Tests/src/Generic_Tests_DatabaseTestCase.php +++ /dev/null @@ -1,53 +0,0 @@ -conn === null) { - if (self::$pdo == null) { - if ((string) $GLOBALS['DB_ADAPTER'] === 'pdo_sqlite') { - self::$pdo = new PDO('sqlite:' . dirname(dirname(__FILE__)) . '/database/' . $GLOBALS['DB_DBNAME']); - - $sql = file_get_contents(dirname(dirname(__DIR__))."/database/sqlite.sql"); - $sql = str_replace("PREFIX_", $GLOBALS['DB_PREFIX'], $sql); - $statements = explode(";", $sql); - - if (is_array($statements)) - foreach ($statements as $query) - self::$pdo->query($query); - - } else { - self::$pdo = new PDO( $GLOBALS['DB_DSN'], $GLOBALS['DB_USER'], $GLOBALS['DB_PASSWD'] ); - } - } - $this->conn = $this->createDefaultDBConnection(self::$pdo, $GLOBALS['DB_DBNAME']); - } - - return $this->conn; - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_generic */ diff --git a/PhpRbac/autoload.php b/PhpRbac/autoload.php deleted file mode 100644 index c668107..0000000 --- a/PhpRbac/autoload.php +++ /dev/null @@ -1,22 +0,0 @@ - Date: Mon, 12 Jan 2015 14:46:12 +0100 Subject: [PATCH 11/57] Add possibility to set database configuration with an array --- PhpRbac/Database/Jf.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index 027aaee..ee78965 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -22,9 +22,20 @@ public static function setTablePrefix($tablePrefix) self::$TABLE_PREFIX = $tablePrefix; } - public static function loadConfig($file) + public static function loadConfig($data) { - self::$config = json_decode(file_get_contents($file), true); + if(is_file($data)) + { + self::$config = json_decode(file_get_contents($data), true); + } + elseif(is_array($data)) + { + self::$config = $data; + } + else + { + throw new \InvalidArgumentException('$data must be a JSON file or an array'); + } } public static function getConfig($key) From 9948ada515556546648c867379b61293f67e7bfc Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Mon, 12 Jan 2015 14:58:10 +0100 Subject: [PATCH 12/57] Fix call_user_func() on Jf and remove useless statement --- PhpRbac/Manager/BaseRbacManager.php | 1 - PhpRbac/NestedSet/FullNestedSet.php | 20 ++-- PhpRbac/index.php | 146 +++++++++++++++++++++++++++- 3 files changed, 155 insertions(+), 12 deletions(-) diff --git a/PhpRbac/Manager/BaseRbacManager.php b/PhpRbac/Manager/BaseRbacManager.php index 7579b4c..c6f16db 100644 --- a/PhpRbac/Manager/BaseRbacManager.php +++ b/PhpRbac/Manager/BaseRbacManager.php @@ -40,7 +40,6 @@ abstract protected function type(); */ function add($Title, $Description, $ParentID = null) { - die('ok'); if ($ParentID === null) $ParentID = $this->rootId (); return (int)$this->{$this->type ()}->insertChildData ( array ("Title" => $Title, "Description" => $Description ), "ID=?", $ParentID ); diff --git a/PhpRbac/NestedSet/FullNestedSet.php b/PhpRbac/NestedSet/FullNestedSet.php index d23b873..55f0b62 100644 --- a/PhpRbac/NestedSet/FullNestedSet.php +++ b/PhpRbac/NestedSet/FullNestedSet.php @@ -148,7 +148,7 @@ function deleteConditional($ConditionString,$Rest=null) WHERE $ConditionString LIMIT 1"; array_unshift($Arguments,$Query); - $Info=call_user_func_array("Jf::sql",$Arguments); + $Info=call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); if (!$Info) { $this->unlock(); @@ -180,7 +180,7 @@ function deleteSubtreeConditional($ConditionString,$Rest=null) WHERE $ConditionString"; array_unshift($Arguments,$Query); - $Info=call_user_func_array("Jf::sql",$Arguments); + $Info=call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); $Info=$Info[0]; @@ -235,7 +235,7 @@ function descendantsConditional($AbsoluteDepths=false,$ConditionString,$Rest=nul ORDER BY node.{$this->left()}"; array_unshift($Arguments,$Query); - $Res=call_user_func_array("Jf::sql",$Arguments); + $Res=call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); return $Res; } @@ -274,7 +274,7 @@ function childrenConditional($ConditionString,$Rest=null) ORDER BY node.{$this->left()}"; array_unshift($Arguments,$Query); - $Res=call_user_func_array("Jf::sql",$Arguments); + $Res=call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); if ($Res) foreach ($Res as &$v) unset($v["Depth"]); @@ -300,7 +300,7 @@ function pathConditional($ConditionString,$Rest=null) ORDER BY parent.{$this->left()}"; array_unshift($Arguments,$Query); - $Res=call_user_func_array("Jf::sql",$Arguments); + $Res=call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); return $Res; } @@ -329,7 +329,7 @@ function leavesConditional($ConditionString=null,$Rest=null) $Arguments=array_merge($Arguments,$Arguments); array_unshift($Arguments,$Query); - $Res=call_user_func_array("Jf::sql",$Arguments); + $Res=call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); } else $Res=Jf::sql("SELECT * @@ -384,7 +384,7 @@ function insertSiblingData($FieldValueArray=array(),$ConditionString=null,$Rest= array_unshift($Values,$Sibl["Right"]+1); array_unshift($Values,$Query); - $Res=call_user_func_array("Jf::sql",$Values); + $Res=call_user_func_array("PhpRbac\Database\Jf::sql",$Values); $this->unlock(); return $Res; } @@ -407,7 +407,7 @@ function insertChildData($FieldValueArray=array(),$ConditionString=null,$Rest=nu $Query="SELECT {$this->right()} AS `Right`, {$this->left()} AS `Left`". " FROM {$this->table()} $ConditionString"; array_unshift($Arguments,$Query); - $Parent=call_user_func_array("Jf::sql",$Arguments); + $Parent=call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); $Parent=$Parent[0]; if ($Parent==null) @@ -432,7 +432,7 @@ function insertChildData($FieldValueArray=array(),$ConditionString=null,$Rest=nu array_unshift($Values,$Parent["Right"]+1); array_unshift($Values,$Parent["Right"]); array_unshift($Values,$Query); - $Res=call_user_func_array("Jf::sql",$Values); + $Res=call_user_func_array("PhpRbac\Database\Jf::sql",$Values); $this->unlock(); return $Res; } @@ -468,7 +468,7 @@ function editData($FieldValueArray=array(),$ConditionString=null,$Rest=null) array_unshift($Values,$Query); $Arguments=array_merge($Values,$Arguments); - return call_user_func_array("Jf::sql",$Arguments); + return call_user_func_array("PhpRbac\Database\Jf::sql",$Arguments); } } \ No newline at end of file diff --git a/PhpRbac/index.php b/PhpRbac/index.php index ab67b68..5b5e339 100644 --- a/PhpRbac/index.php +++ b/PhpRbac/index.php @@ -4,4 +4,148 @@ $rbac = new PhpRbac\Rbac(); -$rbac->reset(true); \ No newline at end of file +$rbac->reset(true); +$commonPerms = [ + 'intent-to-leave', + 'referrals-public-view', + 'referrals-teams-view', +]; + +$role1Perms = [ + 'access level-individual_aggregate'. + 'risk-indicator', + 'profile-blocks-1', + 'profile-blocks-4', + 'profile-blocks-n', + 'profile-items-2', + 'profile-items-n', + 'survey-blocks-2', + 'survey-blocks-4', + 'survey-blocks-n', + 'survey-items-2', + 'survey-items-n', + 'notes-public-view', + 'notes-teams-view', + 'contacts-public-view', + 'contacts-teams-view', + 'booking-public-view', + 'booking-teams-view', +]; + +$role2Perms = [ + 'access-level_aggregate', + 'profile-blocks-2', + 'profile-blocks-4', + 'profile-blocks-n', + 'profile-items-2', + 'profile-items-n', + 'survey-blocks-2', + 'survey-blocks-4', + 'survey-blocks-n', + 'survey-items-2', + 'survey-items-n', + 'notes-public-create', + 'notes-teams-create', + 'contacts-public-view', + 'contacts-private-create', + 'contacts-teams-view', + 'booking-public-create', + 'booking-teams-create', + 'referrals-private-create', +]; + +$role3Perms = [ + 'access-level_individual_aggregate', + 'risk-indicator', + 'referrals-public-create', + 'referrals-private-create', + 'referrals-teams-create', + 'receive-referrals', +]; + + +$commonRoleId = $rbac->Roles->add('common_role', 'Common permissions for all users'); + +foreach ($commonPerms as $info) { + $permId = $rbac->Permissions->add($info, 'Default description', $commonRoleId); + $rbac->Roles->assign('common_role', $permId); +} + +$role1Id = $rbac->Roles->add('role1', 'Role 1', $commonRoleId); + +foreach ($role1Perms as $permName) { + $rbac->Permissions->add($permName, 'Default description', $role1Id); + $rbac->Roles->assign('role1', $permName); +} + +$role2Id = $rbac->Roles->add('role2', 'Role 2', $commonRoleId); + +foreach ($role2Perms as $permName) { + $rbac->Permissions->add($permName, 'Default description', $role2Id); + $rbac->Roles->assign('role2', $permName); +} + + +// Create User +$users = [ + [ + 'id' => 1, + 'username' => 'admin', + 'roles' => [ + 'role1' + ] + ], + [ + 'id' => 2, + 'username' => 'editor', + 'roles' => [ + 'common_role', + 'role2' + ] + ], +]; + +// Assign the proper roles. +foreach ($users as $user) { + if (!empty($user['roles']) && is_array($user['roles'])) { + foreach ($user['roles'] as $role) { + $rbac->Users->assign($role, $user['id']); + } + } +} + + +$tests = [ + $users[0]['id'] => [ + 'intent to leave' => true, + 'profile-blocks-1' => true, + 'profile-blocks-2' => false, + 'survey items-3' => false, + ], + $users[1]['id'] => [ + 'intent to leave' => true, + 'profile-blocks-1' => false, + 'profile-blocks-n' => true, + 'survey items-3' => false, + ], +]; + + +// Validate if a user has a particular permission. +foreach ($tests as $userId => $test) { + foreach ($test as $permission => $hasPermission) { + $permissionVerb = $hasPermission ? 'has' : 'doesn\'t have'; + $noPermissionVerb = $hasPermission ? 'doesn\'t have' : 'has'; + try { + if ($rbac->check($permission, $userId) === $hasPermission) { + echo "Success: User {$userId} $permissionVerb the '{$permission}' permission.\n"; + } else { + echo "Failure! User {$userId} $noPermissionVerb the '{$permission}' permission.\n"; + } + } + catch(Exception $e) { + $status = $hasPermission ? 'Failure' : 'Success'; + echo "$status! '{$permission}' is an unknown/invalid permission.\n"; + } + } +} \ No newline at end of file From d0f20502e95a108be17444fbc551832f7af72f14 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Mon, 12 Jan 2015 15:10:19 +0100 Subject: [PATCH 13/57] Delete useless setup scripts --- PhpRbac/install.php | 181 -------------------------------------------- PhpRbac/setup.php | 77 ------------------- 2 files changed, 258 deletions(-) delete mode 100644 PhpRbac/install.php delete mode 100644 PhpRbac/setup.php diff --git a/PhpRbac/install.php b/PhpRbac/install.php deleted file mode 100644 index e956336..0000000 --- a/PhpRbac/install.php +++ /dev/null @@ -1,181 +0,0 @@ - null, - 'host' => null, - 'name' => null, - 'table_prefix' => null, - 'user' => null, - 'password' => null - ]; - - $adapters = [ - 'pdo_mysql' => '"%s"', - 'mysqli' => '"%s"', - 'pdo_sqlite' => '__DIR__ . "/%s.sqlite3"' - ]; - - do{ - $retry = true; - - setAdapters($database, $adapters); - setHost($database); - setName($database); - setTablePrefix($database); - setUser($database); - setPassword($database); - - if(confirm($database) === false) - { - fputs(STDOUT, 'Cleaning the previous data..' . PHP_EOL); - continue; - } - - generateConfig($database, $adapters); - generateDatabase(); - - if(tryConnection($database) === false) - { - $retry = true; - continue; - } - - $retry = false; - }while($retry === true); - - function setAdapters(&$database, $adapters) - { - fputs(STDOUT, 'Please select one DB adapter' . PHP_EOL); - fputs(STDOUT, 'Available adapters' . PHP_EOL); - - reset($adapters); - while($key = key($adapters)) - { - fputs(STDOUT, "- $key".PHP_EOL); - next($adapters); - } - - fputs(STDOUT, 'Database adapter [pdo_mysql] : '); - $adapter = trim(fgets(STDIN)); - - $database['adapter'] = (!empty($adapter)) ? $adapter : 'pdo_mysql'; - - if(!isset($adapters[$database['adapter']])) - { - fputs(STDOUT, 'A wrong adapter has been chosen. Please correct it.' . PHP_EOL); - setAdapters($database, $adapters); - return true; - } - } - - function setHost(&$database) - { - fputs(STDOUT, 'Database host (ex. 127.0.0.1) : '); - - $database['host'] = trim(fgets(STDIN)); - } - - function setName(&$database) - { - fputs(STDOUT, 'Database name : '); - - $database['name'] = trim(fgets(STDIN)); - } - - function setTablePrefix(&$database) - { - fputs(STDOUT, 'Table prefix [phprbac_] : '); - - $prefix = trim(fgets(STDIN)); - $database['table_prefix'] = (!empty($prefix)) ? $prefix : 'phprbac_'; - } - - function setUser(&$database) - { - fputs(STDOUT, 'Database user : '); - - $database['user'] = trim(fgets(STDIN)); - } - - function setPassword(&$database) - { - fputs(STDOUT, 'Database password : '); - - $database['password'] = trim(fgets(STDIN)); - } - - function confirm($database) - { - fputs(STDOUT, PHP_EOL); - fputs(STDOUT, "The host is {$database['host']}" . PHP_EOL); - fputs(STDOUT, "The database name is {$database['name']} with {$database['adapter']} driver" . PHP_EOL); - fputs(STDOUT, "All the RBAC tables will be prefixed with {$database['table_prefix']}" . PHP_EOL); - fputs(STDOUT, "The credentials are {$database['user']}:{$database['password']}" . PHP_EOL); - fputs(STDOUT, "Do you confirm this is the expected configuration [Y/n] (Y) ?" . PHP_EOL); - - return (trim(fgets(STDIN)) !== 'n'); - } - - function tryConnection($database) - { - try{ - new PDO( - "mysql:host={$database['host']}; dbname={$database['name']}", - $database['user'], - $database['password'], - [ - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION - ] - ); - fputs(STDOUT, 'Test connection success.' . PHP_EOL); - return true; - } - catch (PDOException $ex) - { - fputs(STDOUT, 'The connection failed. Please try again.' . PHP_EOL); - return false; - } - } - - function generateConfig($database, $adapters) - { - $data = - 'reset(true); - - fputs(STDOUT, 'Database is generated.' . PHP_EOL); - } \ No newline at end of file diff --git a/PhpRbac/setup.php b/PhpRbac/setup.php deleted file mode 100644 index 2ca8453..0000000 --- a/PhpRbac/setup.php +++ /dev/null @@ -1,77 +0,0 @@ -getCode()==1049) //database not found - installPdoMysql($host,$user,$pass,$dbname); - else - throw $e; - } -} -elseif ($adapter=="pdo_sqlite") -{ - if (!file_exists($dbname)) - installPdoSqlite($host,$user,$pass,$dbname); - else - Jf::$Db=new PDO("sqlite:{$dbname}",$user,$pass); -// Jf::$Db=new PDO("sqlite::memory:",$user,$pass); -} -else # default to mysqli -{ - @Jf::$Db=new mysqli($host,$user,$pass,$dbname); - if(jf::$Db->connect_errno==1049) - installMysqli($host,$user,$pass,$dbname); -} -function getSqls($dbms) -{ - $sql=file_get_contents(dirname(dirname(dirname(__DIR__))) . "/database/{$dbms}.sql"); - $sql=str_replace("PREFIX_",Jf::tablePrefix(),$sql); - return explode(";",$sql); -} -function installPdoMysql($host,$user,$pass,$dbname) -{ - $sqls=getSqls("mysql"); - $db=new PDO("mysql:host={$host};",$user,$pass); - $db->query("CREATE DATABASE {$dbname}"); - $db->query("USE {$dbname}"); - if (is_array($sqls)) - foreach ($sqls as $query) - $db->query($query); - Jf::$Db=new PDO("mysql:host={$host};dbname={$dbname}",$user,$pass); - Jf::$Rbac->reset(true); -} -function installPdoSqlite($host,$user,$pass,$dbname) -{ - Jf::$Db=new PDO("sqlite:{$dbname}",$user,$pass); - $sqls=getSqls("sqlite"); - if (is_array($sqls)) - foreach ($sqls as $query) - Jf::$Db->query($query); - Jf::$Rbac->reset(true); -} -function installMysqli($host,$user,$pass,$dbname) -{ - $sqls=getSqls("mysql"); - $db=new mysqli($host,$user,$pass); - $db->query("CREATE DATABASE {$dbname}"); - $db->select_db($dbname); - if (is_array($sqls)) - foreach ($sqls as $query) - $db->query($query); - Jf::$Db=new mysqli($host,$user,$pass,$dbname); - Jf::$Rbac->reset(true); -} From 21a071eac5c9ec3510d198e26221785570a2bccb Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Mon, 12 Jan 2015 15:40:03 +0100 Subject: [PATCH 14/57] Change repository name in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b508158..222cf11 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name" : "owasp/phprbac", + "name" : "kilix/rbac", "type" : "library", "description" : "PHP-RBAC is the de-facto authorization library for PHP. It provides developers with NIST Level 2 Standard Role Based Access Control and more, in the fastest implementation yet.", "keywords" : [ From 01c588a33964fb28d994f364588879e639f06396 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Mon, 12 Jan 2015 17:44:55 +0100 Subject: [PATCH 15/57] Add Installers to replace the old setup.php file --- PhpRbac/Database/Installer/BasicInstaller.php | 34 +++++++++++++ .../Database/Installer/InstallerInterface.php | 35 +++++++++++++ .../Database/Installer/MysqliInstaller.php | 50 ++++++++++++++++++ .../Database/Installer/PdoMysqlInstaller.php | 51 +++++++++++++++++++ .../Database/Installer/PdoSqliteInstaller.php | 40 +++++++++++++++ PhpRbac/Database/Jf.php | 26 +++++++++- 6 files changed, 234 insertions(+), 2 deletions(-) create mode 100644 PhpRbac/Database/Installer/BasicInstaller.php create mode 100644 PhpRbac/Database/Installer/InstallerInterface.php create mode 100644 PhpRbac/Database/Installer/MysqliInstaller.php create mode 100644 PhpRbac/Database/Installer/PdoMysqlInstaller.php create mode 100644 PhpRbac/Database/Installer/PdoSqliteInstaller.php diff --git a/PhpRbac/Database/Installer/BasicInstaller.php b/PhpRbac/Database/Installer/BasicInstaller.php new file mode 100644 index 0000000..3d69a44 --- /dev/null +++ b/PhpRbac/Database/Installer/BasicInstaller.php @@ -0,0 +1,34 @@ +getCode()==1049) + { + $this->install($host, $user, $pass, $dbname); + return true; + } + throw $e; + } + } + + /** + * {@inheritdoc} + */ + public function install($host, $user, $pass, $dbname) + { + $queries = $this->getSqlQueries('mysql'); + + $db = new \mysqli($host, $user, $pass); + $db->query("CREATE DATABASE $dbname"); + $db->select_db($dbname); + + if (is_array($queries)) + { + foreach ($queries as $query) + { + $db->query($query); + } + } + Jf::$Db = new \mysqli($host, $user, $pass, $dbname); + Jf::$Rbac->reset(true); + } +} \ No newline at end of file diff --git a/PhpRbac/Database/Installer/PdoMysqlInstaller.php b/PhpRbac/Database/Installer/PdoMysqlInstaller.php new file mode 100644 index 0000000..c2825ce --- /dev/null +++ b/PhpRbac/Database/Installer/PdoMysqlInstaller.php @@ -0,0 +1,51 @@ +getCode()==1049) + { + $this->install($host, $user, $pass, $dbname); + return true; + } + throw $e; + } + } + + /** + * {@inheritdoc} + */ + public function install($host, $user, $pass, $dbname) + { + $queries = $this->getSqlQueries('mysql'); + + $db = new \PDO("mysql:host={$host};", $user, $pass); + + $db->query("CREATE DATABASE {$dbname}"); + $db->query("USE {$dbname}"); + + if (is_array($queries)) + { + foreach ($sqls as $query) + { + $db->query($query); + } + } + Jf::$Db=new PDO("mysql:host={$host};dbname={$dbname}", $user, $pass); + Jf::$Rbac->reset(true); + } +} \ No newline at end of file diff --git a/PhpRbac/Database/Installer/PdoSqliteInstaller.php b/PhpRbac/Database/Installer/PdoSqliteInstaller.php new file mode 100644 index 0000000..da10652 --- /dev/null +++ b/PhpRbac/Database/Installer/PdoSqliteInstaller.php @@ -0,0 +1,40 @@ +install($host, $user, $pass, $dbname); + return true; + } + Jf::$Db = new \PDO("sqlite:{$dbname}", $user, $pass); + } + + /** + * {@inheritdoc} + */ + public function install($host, $user, $pass, $dbname) + { + Jf::$Db=new PDO("sqlite:{$dbname}", $user, $pass); + + $queries = $this->getSqlQueries('sqlite'); + + if (is_array($queries)) + { + foreach ($queries as $query) + { + Jf::$Db->query($query); + } + } + Jf::$Rbac->reset(true); + } +} \ No newline at end of file diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index ee78965..707ae8f 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -16,6 +16,12 @@ class Jf private static $groupConcatLimitChanged = false; private static $config; + + private static $installers = [ + 'mysql' => 'MysqliInstaller', + 'pdo_mysql' => 'PdoMysqlInstaller', + 'pdo_sqlite'=> 'PdoSqliteInstaller' + ]; public static function setTablePrefix($tablePrefix) { @@ -38,6 +44,22 @@ public static function loadConfig($data) } } + public static function loadConnection() + { + if(!isset(self::$installers[self::$config['adapter']])) + { + throw new \ErrorException('The given adapter does not match any installer'); + } + $installerClass = 'PhpRbac\\Database\\Installer\\' . self::$installers[self::$config['adapter']]; + $installer = new $installerClass(); + $installer->init( + self::$config['host'], + self::$config['user'], + self::$config['pass'], + self::$config['dbname'] + ); + } + public static function getConfig($key) { if(!isset(self::$config[$key])) @@ -226,5 +248,5 @@ static function time() } Jf::loadConfig(__DIR__.'/database_config.json'); -Jf::$Rbac=new RbacManager(); -require_once __DIR__."/../setup.php"; \ No newline at end of file +Jf::loadConnection(); +Jf::$Rbac = new RbacManager(); \ No newline at end of file From dd5a7eac812b4f13b09173617e27bdf53430807d Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Tue, 13 Jan 2015 10:15:56 +0100 Subject: [PATCH 16/57] Hotfix: Inverse conditions to avoid error on is_file() function --- PhpRbac/Database/Jf.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index 707ae8f..2dbe88a 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -30,13 +30,13 @@ public static function setTablePrefix($tablePrefix) public static function loadConfig($data) { - if(is_file($data)) + if(is_array($data)) { - self::$config = json_decode(file_get_contents($data), true); + self::$config = $data; } - elseif(is_array($data)) + elseif(is_file($data)) { - self::$config = $data; + self::$config = json_decode(file_get_contents($data), true); } else { From 97837975873c87e41f3ecdbee5483798161340a9 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 08:33:17 +0100 Subject: [PATCH 17/57] Remove old tests --- PhpRbac/Tests/DatabaseTestCase.php | 38 -- PhpRbac/Tests/RbacBase.php | 896 -------------------------- PhpRbac/Tests/RbacManagerTest.php | 311 --------- PhpRbac/Tests/RbacPermissionsTest.php | 234 ------- PhpRbac/Tests/RbacRolesTest.php | 311 --------- PhpRbac/Tests/RbacSetup.php | 58 -- PhpRbac/Tests/RbacUsersTest.php | 421 ------------ 7 files changed, 2269 deletions(-) delete mode 100644 PhpRbac/Tests/DatabaseTestCase.php delete mode 100644 PhpRbac/Tests/RbacBase.php delete mode 100644 PhpRbac/Tests/RbacManagerTest.php delete mode 100644 PhpRbac/Tests/RbacPermissionsTest.php delete mode 100644 PhpRbac/Tests/RbacRolesTest.php delete mode 100644 PhpRbac/Tests/RbacSetup.php delete mode 100644 PhpRbac/Tests/RbacUsersTest.php diff --git a/PhpRbac/Tests/DatabaseTestCase.php b/PhpRbac/Tests/DatabaseTestCase.php deleted file mode 100644 index 17ff519..0000000 --- a/PhpRbac/Tests/DatabaseTestCase.php +++ /dev/null @@ -1,38 +0,0 @@ -conn === null) { - if (self::$pdo == null) { - if ((string) Jf::getConfig('adapter') === 'pdo_sqlite') { - self::$pdo = new \PDO('sqlite:' . dirname(dirname(__FILE__)) . '/database/' . Jf::getConfig('dbname')); - - $sql = file_get_contents(dirname(dirname(__DIR__))."/database/sqlite.sql"); - $sql = str_replace("PREFIX_", Jf::getConfig('table_prefix'), $sql); - $statements = explode(";", $sql); - - if (is_array($statements)) - foreach ($statements as $query) - self::$pdo->query($query); - - } else { - self::$pdo = new \PDO("mysql:host=".Jf::getConfig('host').";dbname=".Jf::getConfig('dbname'), Jf::getConfig('user'), Jf::getConfig('pass')); - } - } - $this->conn = $this->createDefaultDBConnection(self::$pdo, Jf::getConfig('dbname')); - } - return $this->conn; - } -} diff --git a/PhpRbac/Tests/RbacBase.php b/PhpRbac/Tests/RbacBase.php deleted file mode 100644 index 6d64238..0000000 --- a/PhpRbac/Tests/RbacBase.php +++ /dev/null @@ -1,896 +0,0 @@ -Instance()->add() - */ - - public function testAddNullTitle() - { - $dataSet = $this->getConnection()->createDataSet(); - - $type_id = $this->Instance()->add(null, $this->type() . ' Description'); - - $this->assertSame(0, $type_id); - } - - public function testAddNullDescription() - { - $dataSet = $this->getConnection()->createDataSet(); - - $type_id = $this->Instance()->add($this->type() . '_title', null); - - $this->assertSame(0, $type_id); - } - - public function testAddSequential() - { - $dataSet = $this->getConnection()->createDataSet(); - - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_' . $this->type() . '_sequential.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddHierarchy() - { - $dataSet = $this->getConnection()->createDataSet(); - - $type_1 = $this->Instance()->add('blog', 'Define ' . $this->type() . ' for the Blog'); - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1', $type_1); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2', $type_1); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3', $type_1); - - $type_2 = $this->Instance()->add('forum', 'Define ' . $this->type() . ' for the Forums'); - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1', $type_2); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2', $type_2); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3', $type_2); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_' . $this->type() . '_hierarchy.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - /* - * Tests for $this->Instance()->count() - */ - - public function testCount() - { - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); - - $type_count = $this->Instance()->count(); - - $this->assertSame(4, $type_count); - } - - /* - * Tests for $this->Instance()->returnId() - */ - - public function testReturnIdTitle() - { - $this->Instance()->addPath('/'. $this->type() . '_1/'. $this->type() . '_2'); - - $entityId = $this->Instance()->returnId($this->type() . '_2'); - - $this->assertEquals('3', $entityId); - } - - public function testReturnIdPath() - { - $this->Instance()->addPath('/'. $this->type() . '_1/'. $this->type() . '_2'); - - $entityId = $this->Instance()->returnId('/'. $this->type() . '_1/'. $this->type() . '_2'); - - $this->assertEquals('3', $entityId); - } - - public function testReturnIdNullBadParameters() - { - $entityId = $this->Instance()->returnId($this->type() . '_2'); - - $this->assertSame(null, $entityId); - } - - public function testReturnIdNullNoParameters() - { - $entityId = $this->Instance()->returnId(); - - $this->assertSame(null, $entityId); - } - - /* - * Tests for $this->Instance()->titleId() - */ - - public function testGetTitleId() - { - $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $title_id = $this->Instance()->titleId($this->type() . '_title'); - - $this->assertSame('2', $title_id); - } - - public function testGetTitleIdNull() - { - $title_id = $this->Instance()->titleId($this->type() . '_title'); - - $this->assertNull($title_id); - } - - /* - * Tests for $this->Instance()->getTitle() - */ - - public function testGetTitle() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $type_title = $this->Instance()->getTitle($type_id); - - $this->assertSame($this->type() . '_title', $type_title); - } - - public function testGetTitleNull() - { - $type_title = $this->Instance()->getTitle(intval(3)); - - $this->assertNull($type_title); - } - - /* - * Tests for $this->Instance()->getDescription() - */ - - public function testGetDescription() - { - $type_description = $this->Instance()->getDescription(intval(1)); - - $this->assertSame('root', $type_description); - } - - public function testGetDescriptionNull() - { - $type_description = $this->Instance()->getDescription(intval(2)); - - $this->assertNull($type_description); - } - - /* - * Tests for $this->Instance()->edit() - */ - - public function testEditTitle() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $this->Instance()->edit($type_id, $this->type() . '_title_edited'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_title.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testEditDescription() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $this->Instance()->edit($type_id, null, $this->type() . ' Description edited'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testEditAll() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $this->Instance()->edit($type_id, $this->type() . '_title_edited', $this->type() . ' Description edited'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() . ' WHERE ID=2' - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_edit_' . $this->type() . '_all.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testEditNullId() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $result = $this->Instance()->edit(intval(3), $this->type() . '_title', $this->type() . ' Description'); - - $this->assertFalse($result); - } - - public function testEditNullParameters() - { - $type_id = $this->Instance()->add($this->type() . '_title', $this->type() . ' Description'); - $result = $this->Instance()->edit($type_id); - - $this->assertFalse($result); - } - - /* - * Tests for $this->Instance()->addPath() - */ - - public function testAddPathSingle() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_single.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathSingleDescription() - { - $descriptions = array( - $this->type() . ' Description 1', - $this->type() . ' Description 2', - $this->type() . ' Description 3', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_single_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathSequential() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_sequential.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathSequentialDescription() - { - $descriptions_1 = array( - $this->type() . ' Description 1', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/', $descriptions_1); - - $descriptions_2 = array( - null, - $this->type() . ' Description 2', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/', $descriptions_2); - - $descriptions_3 = array( - null, - null, - $this->type() . ' Description 3', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions_3); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_sequential_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathHierarchy() - { - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_4'); - - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_13/' . $this->type() . '_14'); - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_15/' . $this->type() . '_11'); - - $this->Instance()->addPath('/' . $this->type() . '_23/' . $this->type() . '_24/' . $this->type() . '_25'); - $this->Instance()->addPath('/' . $this->type() . '_33/' . $this->type() . '_34/' . $this->type() . '_35'); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_hierarchy.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathHierarchyDescription() - { - $descriptions_1 = array( - $this->type() . ' Description 1', - $this->type() . ' Description 2', - $this->type() . ' Description 3', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3', $descriptions_1); - - $descriptions_2 = array( - null, - null, - $this->type() . ' Description 4', - ); - - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_4', $descriptions_2); - - $descriptions_3 = array( - $this->type() . ' Description 12', - $this->type() . ' Description 13', - $this->type() . ' Description 14', - ); - - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_13/' . $this->type() . '_14', $descriptions_3); - - $descriptions_4 = array( - null, - $this->type() . ' Description 15', - $this->type() . ' Description 11', - ); - - $this->Instance()->addPath('/' . $this->type() . '_12/' . $this->type() . '_15/' . $this->type() . '_11', $descriptions_4); - - $descriptions_5 = array( - $this->type() . ' Description 23', - $this->type() . ' Description 24', - $this->type() . ' Description 25', - ); - - $this->Instance()->addPath('/' . $this->type() . '_23/' . $this->type() . '_24/' . $this->type() . '_25', $descriptions_5); - - $descriptions_6 = array( - $this->type() . ' Description 33', - $this->type() . ' Description 34', - $this->type() . ' Description 35', - ); - - $this->Instance()->addPath('/' . $this->type() . '_33/' . $this->type() . '_34/' . $this->type() . '_35', $descriptions_6); - - $queryTable = $this->getConnection()->createQueryTable( - $this->Instance()->tablePrefix() . $this->type(), 'SELECT * FROM ' . $this->Instance()->tablePrefix() . $this->type() - ); - - $expectedTable = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_add_path_' . $this->type() . '_hierarchy_description.xml') - ->getTable($this->Instance()->tablePrefix() . $this->type()); - - $this->assertTablesEqual($expectedTable, $queryTable); - } - - public function testAddPathReturnNodesCreatedCountTwoCreated() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $nodes_created = $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $this->assertSame(2, $nodes_created); - } - - public function testAddPathReturnNodesCreatedCountNoneCreated() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - $nodes_created = $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $this->assertSame(0, $nodes_created); - } - - - /** - * @expectedException Exception - */ - - public function testAddPathBadPath() - { - $this->Instance()->addPath('permissions_1/permissions_2//permissions_3'); - } - - /* - * Tests for $this->Instance()->pathId() - */ - - public function testPathID() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2'); - - $this->assertSame('3', $path_id); - } - - public function testPathIDNullBadPath() - { - $this->Instance()->addPath('/' . $this->type() . '_1/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_id = $this->Instance()->pathId($this->type() . '_2'); - - $this->assertNull($path_id); - } - - public function testPathIDGroupConcatMaxCharCountShortCount() - { - $this->Instance()->addPath('/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/final_109/first_depth11'); - $this->Instance()->addPath('/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109'); - - $path_id = $this->Instance()->pathId("/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/final_109"); - - $this->assertSame('13', $path_id); - } - - public function testPathIDGroupConcatMaxCharCountLongCount() - { - $this->Instance()->addPath('/first_depth0/first_depth1/first_depth2/first_depth3/first_depth4/first_depth5/first_depth6/first_depth7/first_depth8/first_depth9/first_depth10/first_depth11'); - $this->Instance()->addPath('/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109'); - - $path_id = $this->Instance()->pathId("/second_depth0/second_depth1/second_depth2/second_depth3/second_depth4/second_depth5/second_depth6/second_depth7/second_depth8/second_depth9/second_depth10/second_depth11/second_depth12/second_depth13/second_depth14/second_depth15/second_depth16/second_depth17/second_depth18/second_depth19/second_depth20/second_depth21/second_depth22/second_depth23/second_depth24/second_depth25/second_depth26/second_depth27/second_depth28/second_depth29/second_depth30/second_depth31/second_depth32/second_depth33/second_depth34/second_depth35/second_depth36/second_depth37/second_depth38/second_depth39/second_depth40/second_depth41/second_depth42/second_depth43/second_depth44/second_depth45/second_depth46/second_depth47/second_depth48/second_depth49/second_depth50/second_depth51/second_depth52/second_depth53/second_depth54/second_depth55/second_depth56/second_depth57/second_depth58/second_depth59/second_depth60/second_depth61/second_depth62/second_depth63/second_depth64/second_depth65/second_depth66/second_depth67/second_depth68/second_depth69/second_depth70/second_depth71/second_depth72/second_depth73/second_depth74/second_depth75/second_depth76/second_depth77/second_depth78/second_depth79/second_depth80/second_depth81/second_depth82/second_depth83/second_depth84/second_depth85/second_depth86/second_depth87/second_depth88/second_depth89/second_depth90/second_depth91/second_depth92/second_depth93/second_depth94/second_depth95/second_depth96/second_depth97/second_depth98/second_depth99/second_depth100/second_depth101/second_depth102/second_depth103/second_depth104/second_depth105/second_depth106/second_depth107/second_depth108/second_depth109/final_109"); - - $this->assertSame('124', $path_id); - } - - /* - * Tests for $this->Instance()->getPath() - */ - - public function testPath() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_returned = $this->Instance()->getPath(intval(3)); - - $this->assertSame('/' . $this->type() . '_1/' . $this->type() . '_2', $path_returned); - } - - public function testgetPathNull() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $path_returned = $this->Instance()->getPath(intval(5)); - - $this->assertNull($path_returned); - } - - /* - * Tests for $this->Instance()->children() - */ - - public function testChildren() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $children = $this->Instance()->children($path_id); - - $expected = array( - array( - 'ID' => '5', - 'Lft' => '4', - 'Rght' => '7', - 'Title' => $this->type() . '_4', - 'Description' => '', - ), - array( - 'ID' => '7', - 'Lft' => '8', - 'Rght' => '11', - 'Title' => $this->type() . '_6', - 'Description' => '', - ) - ); - - $this->assertSame($expected, $children); - } - - public function testChildrenNullBadID() - { - $children = $this->Instance()->children(20); - - $this->assertNull($children); - } - - /* - * Tests for $this->Instance()->descendants() - */ - - public function testDescendants() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $descendants = $this->Instance()->descendants($path_id); - - $expected = array( - $this->type() . '_4' => array( - 'ID' => '5', - 'Lft' => '4', - 'Rght' => '7', - 'Title' => $this->type() . '_4', - 'Description' => '', - 'Depth' => '1', - ), - $this->type() . '_5' => array( - 'ID' => '6', - 'Lft' => '5', - 'Rght' => '6', - 'Title' => $this->type() . '_5', - 'Description' => '', - 'Depth' => '2', - ), - $this->type() . '_6' => array( - 'ID' => '7', - 'Lft' => '8', - 'Rght' => '11', - 'Title' => $this->type() . '_6', - 'Description' => '', - 'Depth' => '1', - ), - $this->type() . '_7' => array( - 'ID' => '8', - 'Lft' => '9', - 'Rght' => '10', - 'Title' => $this->type() . '_7', - 'Description' => '', - 'Depth' => '2', - ), - ); - - $this->assertSame($expected, $descendants); - } - - public function testDescendantsEmptyBadID() - { - $descendants = $this->Instance()->descendants(20); - - $this->assertEmpty($descendants); - } - - /* - * Tests for $this->Instance()->depth() - */ - - public function testDepth() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $depth = $this->Instance()->depth($path_id); - - $this->assertSame(3, $depth); - } - - public function testDepthBadID() - { - $depth = $this->Instance()->depth(20); - - $this->assertSame(-1, $depth); - } - - /* - * Tests for $this->Instance()->parentNode() - */ - - public function testParentNode() - { - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_4/' . $this->type() . '_5'); - $this->Instance()->addPath('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3/' . $this->type() . '_6/' . $this->type() . '_7'); - $path_id = $this->Instance()->pathId('/' . $this->type() . '_1/' . $this->type() . '_2/' . $this->type() . '_3'); - - $parent_node = $this->Instance()->parentNode($path_id); - - $expected = array( - 'ID' => '3', - 'Lft' => '2', - 'Rght' => '13', - 'Title' => $this->type() . '_2', - 'Description' => '', - ); - - $this->assertSame($expected, $parent_node); - } - - public function testParentNodeNullBadID() - { - $parent_node = $this->Instance()->parentNode(20); - - $this->assertNull($parent_node); - } - - /* - * Tests for $this->Instance()->assign() - */ - - public function testAssignWithId() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testAssignWithTitle() - { - self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign('roles_1', 'permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testAssignWithPath() - { - self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign('/roles_1', '/permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array($this->Instance()->tablePrefix() . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_assign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /* - * Tests for $this->Instance()->unassign() - */ - - public function testUnassignId() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - $this->Instance()->unassign($role_id, $perm_id); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUnassignTitle() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - $this->Instance()->unassign('roles_1', 'permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUnassignPath() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id, $perm_id); - $this->Instance()->unassign('/roles_1', '/permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_unassign_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /* - * Tests for $this->Instance()->resetAssignments() - */ - - public function testResetPermRoleAssignments() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_2, $perm_id_2); - $this->Instance()->assign($role_id_3, $perm_id_3); - - $this->Instance()->resetAssignments(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_reset_assignments_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testResetPermRoleAssignmentsException() - { - $this->Instance()->resetAssignments(); - } - - /* - * Tests for $this->Instance()->reset() - */ - - public function testReset() - { - $this->Instance()->add($this->type() . '_title_1', $this->type() . ' Description 1'); - $this->Instance()->add($this->type() . '_title_2', $this->type() . ' Description 2'); - $this->Instance()->add($this->type() . '_title_3', $this->type() . ' Description 3'); - - $this->Instance()->reset(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - )); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/base/expected_reset_' . $this->type() . '.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testResetException() - { - $this->Instance()->reset(); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_base */ diff --git a/PhpRbac/Tests/RbacManagerTest.php b/PhpRbac/Tests/RbacManagerTest.php deleted file mode 100644 index 521f93a..0000000 --- a/PhpRbac/Tests/RbacManagerTest.php +++ /dev/null @@ -1,311 +0,0 @@ -assign() - */ - - public function testManagerAssignWithId() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->assign($role_id, $perm_id); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array(Jf::getConfig('table_prefix') . 'userroles')); - $filterDataSet->setExcludeColumnsForTable( - Jf::getConfig('table_prefix') . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_id.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testManagerAssignWithTitle() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->assign('roles_1', 'permissions_1'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array(Jf::getConfig('table_prefix') . 'userroles')); - $filterDataSet->setExcludeColumnsForTable( - Jf::getConfig('table_prefix') . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_title.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testManagerAssignWithPath() - { - self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - - self::$rbac->assign('/roles_1/roles_2', '/permissions_1/permissions_2'); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array(Jf::getConfig('table_prefix') . 'userroles')); - - $filterDataSet->setExcludeColumnsForTable( - Jf::getConfig('table_prefix') . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_assign_path.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testManagerAssignWithNullRoleNullPermFalse() - { - $return = self::$rbac->assign(null, null); - - $this->assertFalse($return); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerAssignWithNullRoleNoPermError() - { - $return = self::$rbac->assign(null); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerAssignWithNoParametersError() - { - $return = self::$rbac->assign(null); - } - - /* - * Tests for self::$rbac->check() - */ - - public function testManagerCheckId() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->check($perm_id_1, 5); - - $this->assertTrue($result); - } - - public function testManagerCheckTitle() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->check('permissions_1', 5); - - $this->assertTrue($result); - } - - public function testManagerCheckPath() - { - self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); - $perm_id_1 = self::$rbac->Permissions->pathId('/permissions_1/permissions_2/permissions_3'); - - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id_1 = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Roles->assign($role_id_1, 3); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->check('/permissions_1/permissions_2', 5); - - $this->assertTrue($result); - } - - public function testManagerCheckBadPermBadUserFalse() - { - $result = self::$rbac->check(5, 5); - - $this->assertFalse($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testManagerCheckWithNullUserIdException() - { - self::$rbac->check(5, null); - } - - /** - * @expectedException RbacPermissionNotFoundException - */ - - public function testManagerCheckWithNullPermException() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->check(null, $perm_id); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerCheckWithNoUserIdException() - { - self::$rbac->check(5); - } - - /* - * Tests for self::$rbac->enforce() - */ - - public function testManagerEnforceId() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->enforce($perm_id_1, 5); - - $this->assertTrue($result); - } - - public function testManagerEnforceTitle() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->enforce('permissions_1', 5); - - $this->assertTrue($result); - } - - public function testManagerEnforcePath() - { - self::$rbac->Permissions->addPath('/permissions_1/permissions_2/permissions_3'); - $perm_id_1 = self::$rbac->Permissions->pathId('/permissions_1/permissions_2/permissions_3'); - - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id_1 = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Roles->assign($role_id_1, 3); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->enforce('/permissions_1/permissions_2', 5); - - $this->assertTrue($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testManagerEnforceWithNullUserIdException() - { - self::$rbac->enforce(5, null); - } - - /** - * @expectedException RbacPermissionNotFoundException - */ - - public function testManagerEnforceWithNullPermException() - { - $perm_id = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - self::$rbac->enforce(null, $perm_id); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testManagerEnforceWithNoUserIdException() - { - self::$rbac->enforce(5); - } - - /* - * Tests for self::$rbac->reset() - */ - - public function testManagerReset() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - self::$rbac->Roles->assign($role_id_1, $perm_id_1); - self::$rbac->Users->assign($role_id_1, 5); - - $result = self::$rbac->reset(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/manager/expected_reset.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testManagerResetFalseException() - { - self::$rbac->reset(); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_manager */ diff --git a/PhpRbac/Tests/RbacPermissionsTest.php b/PhpRbac/Tests/RbacPermissionsTest.php deleted file mode 100644 index b926a19..0000000 --- a/PhpRbac/Tests/RbacPermissionsTest.php +++ /dev/null @@ -1,234 +0,0 @@ -Permissions; - } - - protected function type() - { - return "permissions"; - } - - /* - * Test for proper object instantiation - */ - - public function testPermissionsInstance() { - $this->assertInstanceOf('PermissionManager', self::$rbac->Permissions); - } - - /* - * Tests for $this->Instance()->remove() - */ - - public function testPermissionsRemoveSingle() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->remove($perm_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - )); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsRemoveSingleRole() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - - $this->Instance()->remove($perm_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - $this->Instance()->tablePrefix() . 'rolepermissions', - $this->Instance()->tablePrefix() . 'roles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single_role.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsRemoveRecursive() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $perm_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2', $perm_id_1); - $perm_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3', $perm_id_1); - $perm_id_4 = $this->Instance()->add($this->type() . '_4', $this->type() . ' Description 4'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_2); - - $result = $this->Instance()->remove($perm_id_1, true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - $this->Instance()->tablePrefix() . 'rolepermissions', - $this->Instance()->tablePrefix() . 'roles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_recursive.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsRemoveFalse() - { - $result = $this->Instance()->remove(5); - - $this->assertFalse($result); - } - - /* - * Tests for $this->Instance()->roles() - */ - - public function testPermissionsRolesOnlyID() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_2, $perm_id_1); - $this->Instance()->assign($role_id_3, $perm_id_1); - - $result = $this->Instance()->roles($perm_id_1); - - $expected = array('2', '3', '4'); - - $this->assertSame($expected, $result); - } - - public function testPermissionsRolesBadIDNull() - { - $result = $this->Instance()->roles(20); - - $this->assertNull($result); - } - - public function testPermissionsRolesNotOnlyID() - { - self::$rbac->Roles->addPath("/roles_1/roles_2"); - self::$rbac->Permissions->addPath("/permissions_1/permissions_2"); - - self::$rbac->assign("/roles_1/roles_2", "/permissions_1/permissions_2"); - - $rolesAssigned = self::$rbac->Permissions->roles('/permissions_1/permissions_2', false); - - $expected = array( - array( - 'ID' => '3', - 'Title' => 'roles_2', - 'Description' => '', - ), - ); - - $this->assertSame($expected, $rolesAssigned); - } - - public function testPermissionsRolesNotOnlyIDNullBadParameters() - { - $rolesAssigned = self::$rbac->Permissions->roles('/permissions_1/permissions_2', false); - - $this->assertSame(null, $rolesAssigned); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testPermissionsRolesPassNothing() - { - $result = $this->Instance()->roles(); - } - - /* - * Tests for $this->Instance()->unassignRoles() - */ - - public function testPermissionsUnassignRoles() - { - $perm_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_2, $perm_id_1); - $this->Instance()->assign($role_id_3, $perm_id_1); - - $result = $this->Instance()->unassignRoles($perm_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_roles.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testPermissionsUnassignRolesBadID() - { - $result = $this->Instance()->unassignRoles(20); - - $this->assertSame(0, $result); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_permission_manager */ diff --git a/PhpRbac/Tests/RbacRolesTest.php b/PhpRbac/Tests/RbacRolesTest.php deleted file mode 100644 index fd8f002..0000000 --- a/PhpRbac/Tests/RbacRolesTest.php +++ /dev/null @@ -1,311 +0,0 @@ -Roles; - } - - protected function type() - { - return "roles"; - } - - /* - * Test for proper object instantiation - */ - - public function testRolesInstance() { - $this->assertInstanceOf('RoleManager', self::$rbac->Roles); - } - - /* - * Tests for self::$rbac->Roles->permissions() - */ - - public function testRolesPermissionsIdOnly() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_1, $perm_id_2); - $this->Instance()->assign($role_id_1, $perm_id_3); - - $result = $this->Instance()->permissions($perm_id_1); - - $expected = array('2', '3', '4'); - - $this->assertSame($expected, $result); - } - - public function testRolesPermissionsNotOnlyID() - { - self::$rbac->Roles->addPath("/roles_1/roles_2"); - self::$rbac->Permissions->addPath("/permissions_1/permissions_2"); - - self::$rbac->assign("/roles_1/roles_2", "/permissions_1/permissions_2"); - - $permissionsAssigned = self::$rbac->Roles->permissions('/roles_1/roles_2', false); - - $expected = array( - array( - 'ID' => '3', - 'Title' => 'permissions_2', - 'Description' => '', - ), - ); - - $this->assertSame($expected, $permissionsAssigned); - } - - public function testRolesPermissionsNotOnlyIDNullBadParameters() - { - $rolesAssigned = self::$rbac->Roles->permissions('/roles_1/roles_2', false); - - $this->assertSame(null, $rolesAssigned); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testRolesPermissionsPassNothing() - { - $result = $this->Instance()->permissions(); - } - - /* - * Tests for self::$rbac->Roles->hasPermission() - */ - - public function testRolesHasPermission() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - - $result = self::$rbac->Roles->hasPermission($role_id_1, $perm_id_1); - - $this->assertTrue($result); - } - - public function testRolesHasPermissionFalse() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $result = self::$rbac->Roles->hasPermission($role_id_1, 4); - - $this->assertFalse($result); - } - - /* - * Tests for self::$rbac->Roles->unassignPermissions() - */ - - public function testRolesUnassignPermissions() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_1, $perm_id_2); - $this->Instance()->assign($role_id_1, $perm_id_3); - - $result = $this->Instance()->unassignPermissions($role_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'rolepermissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_permissions.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesUnassignPermissionsBadID() - { - $result = $this->Instance()->unassignPermissions(20); - - $this->assertSame(0, $result); - } - - /* - * Tests for self::$rbac->Roles->unassignUsers() - */ - - public function testRolesUnassignUsers() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_2 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_3 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - $result = $this->Instance()->unassignUsers($role_id_2); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_unassign_users.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesUnassignUsersBadID() - { - $result = $this->Instance()->unassignUsers(20); - - $this->assertSame(0, $result); - } - - /* - * Tests for self::$rbac->Roles->remove() - */ - - public function testRolesRemoveSingle() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - - $this->Instance()->remove($role_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . $this->type(), - )); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesRemoveSinglePermission() - { - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - $perm_id_2 = self::$rbac->Permissions->add('permissions_2', 'permissions Description 2'); - $perm_id_3 = self::$rbac->Permissions->add('permissions_3', 'permissions Description 3'); - - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2'); - $role_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - $this->Instance()->assign($role_id_1, $perm_id_2); - $this->Instance()->assign($role_id_1, $perm_id_3); - - self::$rbac->Users->assign($role_id_1, 5); - - $this->Instance()->remove($role_id_1); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addExcludeTables(array( - $this->Instance()->tablePrefix() . 'permissions', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_single_permission.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesRemoveRecursive() - { - $role_id_1 = $this->Instance()->add($this->type() . '_1', $this->type() . ' Description 1'); - $role_id_2 = $this->Instance()->add($this->type() . '_2', $this->type() . ' Description 2', $role_id_1); - $role_id_3 = $this->Instance()->add($this->type() . '_3', $this->type() . ' Description 3', $role_id_1); - $role_id_4 = $this->Instance()->add($this->type() . '_4', $this->type() . ' Description 4'); - - $perm_id_1 = self::$rbac->Permissions->add('permissions_1', 'permissions Description 1'); - - $this->Instance()->assign($role_id_1, $perm_id_1); - - self::$rbac->Users->assign($role_id_1, 5); - - $result = $this->Instance()->remove($role_id_1, true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - $this->Instance()->tablePrefix() . 'rolepermissions', - $this->Instance()->tablePrefix() . $this->type(), - $this->Instance()->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'rolepermissions', - array('AssignmentDate') - ); - - $filterDataSet->setExcludeColumnsForTable( - $this->Instance()->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/' . $this->type() . '/expected_remove_recursive.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testRolesRemoveFalse() - { - $result = $this->Instance()->remove(5); - - $this->assertFalse($result); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_role_manager */ diff --git a/PhpRbac/Tests/RbacSetup.php b/PhpRbac/Tests/RbacSetup.php deleted file mode 100644 index 4266c89..0000000 --- a/PhpRbac/Tests/RbacSetup.php +++ /dev/null @@ -1,58 +0,0 @@ -reset(true); - } - } - - protected function tearDown() - { - if (Jf::getConfig('adapter') === 'pdo_sqlite') { - self::$rbac->reset(true); - } - } - - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/datasets/database-seed.xml'); - } - - /* - * Tests for proper object instantiation - */ - - public function testRbacInstance() { - $this->assertInstanceOf('PhpRbac\Rbac', self::$rbac); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_setup */ diff --git a/PhpRbac/Tests/RbacUsersTest.php b/PhpRbac/Tests/RbacUsersTest.php deleted file mode 100644 index 6c04f4e..0000000 --- a/PhpRbac/Tests/RbacUsersTest.php +++ /dev/null @@ -1,421 +0,0 @@ -assertInstanceOf('RbacUserManager', self::$rbac->Users); - } - - /* - * Tests for self::$rbac->Users->assign() - */ - - public function testUsersAssignWithId() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_assign_with_id.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUsersAssignWithPath() - { - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Users->assign('/roles_1/roles_2', 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_assign_with_path.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersAssignNoUserID() - { - $result = self::$rbac->Users->assign(5); - - $this->assertFalse($result); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testUsersAssignPassNothing() - { - $result = self::$rbac->Users->assign(); - } - - /* - * Tests for self::$rbac->Users->hasRole() - */ - - public function testUsersHasRoleId() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole($role_id, 5); - - $this->assertTrue($result); - } - - public function testUsersHasRoleTitle() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole('roles_1', 5); - - $this->assertTrue($result); - } - - public function testUsersHasRolePath() - { - self::$rbac->Roles->addPath('/roles_1/roles_2/roles_3'); - $role_id = self::$rbac->Roles->pathId('/roles_1/roles_2/roles_3'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole('/roles_1/roles_2/roles_3', 5); - - $this->assertTrue($result); - } - - public function testUsersHasRoleDoesNotHaveRole() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole(1, 5); - - $this->assertFalse($result); - } - - public function testUsersHasRoleNullRole() - { - $role_id = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - - self::$rbac->Users->assign($role_id, 5); - - $result = self::$rbac->Users->hasRole(null, 5); - - $this->assertFalse($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersHasRoleNoUserId() - { - $result = self::$rbac->Users->hasRole(5); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testUsersHasRolePassNothing() - { - $result = self::$rbac->Users->hasRole(); - } - - /* - * Tests for self::$rbac->Users->allRoles() - */ - - public function testUsersAllRoles() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - $result = self::$rbac->Users->allRoles(5); - - $expected = array( - array( - 'ID' => '2', - 'Lft' => '1', - 'Rght' => '2', - 'Title' => 'roles_1', - 'Description' => 'roles Description 1', - ), - array( - 'ID' => '3', - 'Lft' => '3', - 'Rght' => '4', - 'Title' => 'roles_2', - 'Description' => 'roles Description 2', - ), - array( - 'ID' => '4', - 'Lft' => '5', - 'Rght' => '6', - 'Title' => 'roles_3', - 'Description' => 'roles Description 3', - ), - ); - - $this->assertSame($expected, $result); - } - - public function testUsersAllRolesBadRoleNull() - { - $result = self::$rbac->Users->allRoles(10); - - $this->assertNull($result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersAllRolesNoRolesEmpty() - { - $result = self::$rbac->Users->allRoles(); - } - - /* - * Tests for self::$rbac->Users->roleCount() - */ - - public function testUsersRoleCount() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - $result = self::$rbac->Users->roleCount(5); - - $this->assertSame(3, $result); - } - - public function testUsersRoleCountNoRoles() - { - $result = self::$rbac->Users->roleCount(10); - - $this->assertSame(0, $result); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersRoleCountNoRolesEmpty() - { - $result = self::$rbac->Users->roleCount(); - } - - /* - * Tests for self::$rbac->Users->unassign() - */ - - public function testUsersUnassignId() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->unassign($role_id_2, 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUsersUnassignTitle() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->unassign('roles_2', 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - public function testUsersUnassignPath() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->unassign('/roles_2', 5); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_unassign.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException RbacUserNotProvidedException - */ - - public function testUsersUnassignNoUserIdException() - { - $result = self::$rbac->Users->unassign(5); - } - - /** - * @expectedException PHPUnit_Framework_Error - */ - - public function testUsersUnassignNoRolesException() - { - $result = self::$rbac->Users->unassign(); - } - - /* - * Tests for self::$rbac->Users->resetAssignments() - */ - - public function testUsersResetAssignments() - { - $role_id_1 = self::$rbac->Roles->add('roles_1', 'roles Description 1'); - $role_id_2 = self::$rbac->Roles->add('roles_2', 'roles Description 2'); - $role_id_3 = self::$rbac->Roles->add('roles_3', 'roles Description 3'); - - self::$rbac->Users->assign($role_id_1, 5); - self::$rbac->Users->assign($role_id_2, 5); - self::$rbac->Users->assign($role_id_3, 5); - - self::$rbac->Users->resetAssignments(true); - - $dataSet = $this->getConnection()->createDataSet(); - - $filterDataSet = new \PHPUnit_Extensions_Database_DataSet_DataSetFilter($dataSet); - $filterDataSet->addIncludeTables(array( - self::$rbac->Users->tablePrefix() . 'userroles', - )); - - $filterDataSet->setExcludeColumnsForTable( - self::$rbac->Users->tablePrefix() . 'userroles', - array('AssignmentDate') - ); - - $expectedDataSet = $this->createFlatXmlDataSet(dirname(__FILE__) . '/datasets/users/expected_reset_assignments.xml'); - - $this->assertDataSetsEqual($expectedDataSet, $filterDataSet); - } - - /** - * @expectedException Exception - */ - - public function testUsersResetAssignmentsException() - { - self::$rbac->Users->resetAssignments(); - } -} - -/** @} */ // End group phprbac_unit_test_wrapper_user_manager */ From ed9792390be94020f798b23a2e4e07b5c0277480 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 08:38:19 +0100 Subject: [PATCH 18/57] Set Table prefix as property to make the test work --- PhpRbac/Database/Jf.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index 2dbe88a..3c5399f 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -15,6 +15,8 @@ class Jf private static $groupConcatLimitChanged = false; + public static $TABLE_PREFIX; + private static $config; private static $installers = [ From 2ab407f8c693e0ea702e964e6e0194be2bee6785 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 10:34:59 +0100 Subject: [PATCH 19/57] Fix sqlPdo method --- PhpRbac/Database/Jf.php | 76 +++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index 3c5399f..dc7f0a7 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -115,50 +115,38 @@ static function sqlPdo($Query) $args = func_get_args (); - if (count ( $args ) == 1) - { - $result = self::$Db->query ( $Query ); - if ($result===false) - return null; - $res=$result->fetchAll ( \PDO::FETCH_ASSOC ); - if ($res===array()) - return null; - return $res; - } - else - { - if (! $stmt = self::$Db->prepare ( $Query )) - { - return false; - } - array_shift ( $args ); // remove $Query from args - $i = 0; - foreach ( $args as &$v ) - $stmt->bindValue ( ++ $i, $v ); - - $success=$stmt->execute (); - - $type = substr ( trim ( strtoupper ( $Query ) ), 0, 6 ); - if ($type == "INSERT") - { - if (!$success) - return null; - $res = self::$Db->lastInsertId (); - if ($res == 0) - return $stmt->rowCount (); - return $res; - } - elseif ($type == "DELETE" or $type == "UPDATE" or $type == "REPLACE") - return $stmt->rowCount(); - elseif ($type == "SELECT") - { - $res=$stmt->fetchAll ( \PDO::FETCH_ASSOC ); - if ($res===array()) - return null; - else - return $res; - } - } + if (! $stmt = self::$Db->prepare ( $Query )) { + return false; + } + if (count ( $args ) > 1) { + array_shift ( $args ); // remove $Query from args + $i = 0; + foreach ( $args as &$v ) { + $stmt->bindValue ( ++ $i, $v ); + } + } + $success=$stmt->execute (); + + $type = substr ( trim ( strtoupper ( $Query ) ), 0, 6 ); + if ($type == "INSERT") + { + if (!$success) + return null; + $res = self::$Db->lastInsertId (); + if ($res == 0) + return $stmt->rowCount (); + return $res; + } + elseif ($type == "DELETE" or $type == "UPDATE" or $type == "REPLACE") + return $stmt->rowCount(); + elseif ($type == "SELECT") + { + $res=$stmt->fetchAll ( \PDO::FETCH_ASSOC ); + if ($res===array()) + return null; + else + return $res; + } } static function sqlMysqli( $Query) From b4d33b3723815522aa77ffd7242906dc1a0dfa00 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 10:35:21 +0100 Subject: [PATCH 20/57] Fix some installer functions --- PhpRbac/Database/Installer/BasicInstaller.php | 2 +- PhpRbac/Database/Installer/PdoSqliteInstaller.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PhpRbac/Database/Installer/BasicInstaller.php b/PhpRbac/Database/Installer/BasicInstaller.php index 3d69a44..3a1ece0 100644 --- a/PhpRbac/Database/Installer/BasicInstaller.php +++ b/PhpRbac/Database/Installer/BasicInstaller.php @@ -19,7 +19,7 @@ abstract public function install($host, $user, $pass, $dbname); */ function getSqlQueries($dbms) { - $file = dirname(dirname(dirname(__DIR__))) . "/database/{$dbms}.sql"; + $file = dirname(dirname(dirname(__DIR__))) . "/{$dbms}.sql"; if(!is_file($file)) { diff --git a/PhpRbac/Database/Installer/PdoSqliteInstaller.php b/PhpRbac/Database/Installer/PdoSqliteInstaller.php index da10652..cf44922 100644 --- a/PhpRbac/Database/Installer/PdoSqliteInstaller.php +++ b/PhpRbac/Database/Installer/PdoSqliteInstaller.php @@ -24,7 +24,7 @@ public function init($host, $user, $pass, $dbname) */ public function install($host, $user, $pass, $dbname) { - Jf::$Db=new PDO("sqlite:{$dbname}", $user, $pass); + Jf::$Db=new \PDO("sqlite:{$dbname}", $user, $pass); $queries = $this->getSqlQueries('sqlite'); From b3141cc410e47133e841cd86c1707273ee54c0ff Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 10:49:31 +0100 Subject: [PATCH 21/57] Fix msqli Installer --- PhpRbac/Database/Installer/MysqliInstaller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhpRbac/Database/Installer/MysqliInstaller.php b/PhpRbac/Database/Installer/MysqliInstaller.php index 54450cc..3ab496e 100644 --- a/PhpRbac/Database/Installer/MysqliInstaller.php +++ b/PhpRbac/Database/Installer/MysqliInstaller.php @@ -13,7 +13,7 @@ public function init($host, $user, $pass, $dbname) { try { - Jf::$Db = new mysqli($host, $user, $pass, $dbname); + Jf::$Db = new \mysqli($host, $user, $pass, $dbname); } catch (Exception $ex) { From 0a6d72f9c4dde729e480705af0b6f29748219567 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 11:36:22 +0100 Subject: [PATCH 22/57] Fix installers and Jf class --- PhpRbac/Database/Installer/BasicInstaller.php | 4 +++- PhpRbac/Database/Installer/MysqliInstaller.php | 8 ++++---- PhpRbac/Database/Jf.php | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/PhpRbac/Database/Installer/BasicInstaller.php b/PhpRbac/Database/Installer/BasicInstaller.php index 3a1ece0..fab6576 100644 --- a/PhpRbac/Database/Installer/BasicInstaller.php +++ b/PhpRbac/Database/Installer/BasicInstaller.php @@ -2,6 +2,8 @@ namespace PhpRbac\Database\Installer; +use PhpRbac\Database\Jf; + abstract class BasicInstaller implements InstallerInterface { /** @@ -19,7 +21,7 @@ abstract public function install($host, $user, $pass, $dbname); */ function getSqlQueries($dbms) { - $file = dirname(dirname(dirname(__DIR__))) . "/{$dbms}.sql"; + $file = dirname(__DIR__) . "/{$dbms}.sql"; if(!is_file($file)) { diff --git a/PhpRbac/Database/Installer/MysqliInstaller.php b/PhpRbac/Database/Installer/MysqliInstaller.php index 3ab496e..7a85f41 100644 --- a/PhpRbac/Database/Installer/MysqliInstaller.php +++ b/PhpRbac/Database/Installer/MysqliInstaller.php @@ -15,14 +15,14 @@ public function init($host, $user, $pass, $dbname) { Jf::$Db = new \mysqli($host, $user, $pass, $dbname); } - catch (Exception $ex) + catch (\Exception $ex) { - if ($e->getCode()==1049) + if ($ex->getCode() === 2) { $this->install($host, $user, $pass, $dbname); return true; } - throw $e; + throw $ex; } } @@ -34,7 +34,7 @@ public function install($host, $user, $pass, $dbname) $queries = $this->getSqlQueries('mysql'); $db = new \mysqli($host, $user, $pass); - $db->query("CREATE DATABASE $dbname"); + $db->query("CREATE DATABASE IF NOT EXISTS $dbname"); $db->select_db($dbname); if (is_array($queries)) diff --git a/PhpRbac/Database/Jf.php b/PhpRbac/Database/Jf.php index dc7f0a7..22a63d8 100644 --- a/PhpRbac/Database/Jf.php +++ b/PhpRbac/Database/Jf.php @@ -93,10 +93,10 @@ static function sql($Query) if (self::$Db instanceof \PDO) return call_user_func_array ( "self::sqlPdo", $args ); else - if (self::$Db instanceof mysqli) + if (self::$Db instanceof \mysqli) return call_user_func_array ( "self::sqlMysqli", $args ); else - throw new Exception ( "Unknown database interface type." ); + throw new \Exception ( "Unknown database interface type." ); } static function sqlPdo($Query) From 97d5b43f7e257a934af065e99fcda9fa60e1ea04 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 11:36:37 +0100 Subject: [PATCH 23/57] Add tests for Jf --- .../Installer/MysqliInstallerTest.php | 8 ++ .../Installer/PdoMysqlInstallerTest.php | 8 ++ .../Installer/PdoSqliteInstallerTest.php | 8 ++ PhpRbac/Tests/Database/JfTest.php | 126 ++++++++++++++++++ 4 files changed, 150 insertions(+) create mode 100644 PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php create mode 100644 PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php create mode 100644 PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php create mode 100644 PhpRbac/Tests/Database/JfTest.php diff --git a/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php b/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php new file mode 100644 index 0000000..3ac00fa --- /dev/null +++ b/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php @@ -0,0 +1,8 @@ +assertNull(Jf::$TABLE_PREFIX); + + Jf::setTablePrefix('test_table_prefix'); + + $this->assertEquals('test_table_prefix', Jf::$TABLE_PREFIX); + } + + /** + * @dataProvider configProvider + */ + public function testLoadConfigWithArray($config) + { + Jf::loadConfig($config); + + $this->assertEquals('localhost', Jf::getConfig('host')); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testInvalidLoadconfig() + { + Jf::loadConfig('configuration'); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testInvalidGetConfig() + { + Jf::getConfig('false_key'); + } + + /** + * @expectedException ErrorException + */ + public function testInvalidLoadConnection() + { + Jf::loadConnection(); + } + + public function testSqlQuery() + { + $query = Jf::sql('SELECT table_name, table_type, engine FROM information_schema.tables LIMIT 3'); + + $this->assertInternalType('array', $query); + $this->assertCount(3, $query); + } + + public function testSqlPrepare() + { + $query = Jf::sql('SELECT table_name, ?, engine FROM information_schema.tables LIMIT 3', 'table_type'); + + $this->assertInternalType('array', $query); + $this->assertCount(3, $query); + } + + public function testGetTime() + { + $time = Jf::time(); + + $this->assertEquals(date('G:m'), date('G:m', $time)); + } + + /** + * @dataProvider configProvider + */ + public function testSqlQueryMysqlite($config) + { + $rbac = new Rbac(); + + $config['adapter'] = 'mysql'; + Jf::loadConfig($config); + Jf::loadConnection(); + + $query = Jf::sql('SELECT * FROM kilix_rbac_roles'); + + $this->assertInternalType('array', $query); + $this->assertCount(1, $query); + } + + /** + * @dataProvider configProvider + */ + public function testSqlPrepareMysqlite($config) + { + $rbac = new Rbac(); + + $config['adapter'] = 'mysql'; + Jf::loadConfig($config); + Jf::loadConnection(); + + $query = Jf::sql('SELECT * FROM kilix_rbac_roles WHERE ID = ?;', 1); + + $this->assertInternalType('array', $query); + $this->assertCount(1, $query); + } + + public function configProvider() + { + return [ + [ + [ + 'adapter' => 'fakeAdapter', + 'host' => 'localhost', + 'user' => 'root', + 'pass' => 'vagrant', + 'dbname'=> 'kilix_rbac_test', + 'table_prefix' => 'kilix_rbac_' + ] + ] + ]; + } +} \ No newline at end of file From 8a5c304184db609574e1948e8aa1e70522aa60d1 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 17:17:46 +0100 Subject: [PATCH 24/57] Final fix of the installers --- PhpRbac/Database/Installer/MysqliInstaller.php | 1 + PhpRbac/Database/Installer/PdoMysqlInstaller.php | 8 ++++---- PhpRbac/Database/Installer/PdoSqliteInstaller.php | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/PhpRbac/Database/Installer/MysqliInstaller.php b/PhpRbac/Database/Installer/MysqliInstaller.php index 7a85f41..cd60541 100644 --- a/PhpRbac/Database/Installer/MysqliInstaller.php +++ b/PhpRbac/Database/Installer/MysqliInstaller.php @@ -14,6 +14,7 @@ public function init($host, $user, $pass, $dbname) try { Jf::$Db = new \mysqli($host, $user, $pass, $dbname); + return true; } catch (\Exception $ex) { diff --git a/PhpRbac/Database/Installer/PdoMysqlInstaller.php b/PhpRbac/Database/Installer/PdoMysqlInstaller.php index c2825ce..7da5ae9 100644 --- a/PhpRbac/Database/Installer/PdoMysqlInstaller.php +++ b/PhpRbac/Database/Installer/PdoMysqlInstaller.php @@ -15,9 +15,9 @@ public function init($host, $user, $pass, $dbname) { Jf::$Db = new \PDO("mysql:host={$host};dbname={$dbname}",$user,$pass); } - catch (PDOException $e) + catch (\PDOException $e) { - if ($e->getCode()==1049) + if ($e->getCode() === 1049) { $this->install($host, $user, $pass, $dbname); return true; @@ -40,12 +40,12 @@ public function install($host, $user, $pass, $dbname) if (is_array($queries)) { - foreach ($sqls as $query) + foreach ($queries as $query) { $db->query($query); } } - Jf::$Db=new PDO("mysql:host={$host};dbname={$dbname}", $user, $pass); + Jf::$Db = new \PDO("mysql:host={$host};dbname={$dbname}", $user, $pass); Jf::$Rbac->reset(true); } } \ No newline at end of file diff --git a/PhpRbac/Database/Installer/PdoSqliteInstaller.php b/PhpRbac/Database/Installer/PdoSqliteInstaller.php index cf44922..8620108 100644 --- a/PhpRbac/Database/Installer/PdoSqliteInstaller.php +++ b/PhpRbac/Database/Installer/PdoSqliteInstaller.php @@ -17,6 +17,7 @@ public function init($host, $user, $pass, $dbname) return true; } Jf::$Db = new \PDO("sqlite:{$dbname}", $user, $pass); + return true; } /** @@ -35,6 +36,7 @@ public function install($host, $user, $pass, $dbname) Jf::$Db->query($query); } } + Jf::$Rbac->reset(true); } } \ No newline at end of file From ad7437d383ceeaa988aef636d7f8b83c71fdd5ba Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 17:18:05 +0100 Subject: [PATCH 25/57] Change table prefix in config --- PhpRbac/Database/database_config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PhpRbac/Database/database_config.json b/PhpRbac/Database/database_config.json index 9069751..04860ae 100644 --- a/PhpRbac/Database/database_config.json +++ b/PhpRbac/Database/database_config.json @@ -4,5 +4,5 @@ "user" : "root", "pass" : "vagrant", "dbname" : "rbac", - "table_prefix" : "phprbac_" + "table_prefix" : "kilix_rbac_" } From b789ee76715532c9693153a1a4d28111a63d5dad Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 17:18:22 +0100 Subject: [PATCH 26/57] Achieve tests on database --- .../Installer/MysqliInstallerTest.php | 50 +++++++++++++-- .../Installer/PdoMysqlInstallerTest.php | 50 +++++++++++++-- .../Installer/PdoSqliteInstallerTest.php | 61 +++++++++++++++++-- PhpRbac/Tests/Database/JfTest.php | 11 +++- 4 files changed, 156 insertions(+), 16 deletions(-) diff --git a/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php b/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php index 3ac00fa..e7b08aa 100644 --- a/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php +++ b/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php @@ -1,8 +1,48 @@ query('DROP DATABASE kilix_rbac_test'); + } + + /** + * @dataProvider configurationProvider + */ + public function test($config) + { + Jf::loadConfig($config); + + $installer = new MysqliInstaller(); + $installationSuccess = $installer->init( + $config['host'], + $config['user'], + $config['pass'], + $config['dbname'] + ); + + $this->assertTrue($installationSuccess); + } + + public function configurationProvider() + { + return [ + [ + [ + 'host' => 'localhost', + 'user' => 'root', + 'pass' => 'vagrant', + 'dbname' => 'kilix_rbac_test', + 'table_prefix' => 'kilix_rbac_' + ] + ] + ]; + } +} \ No newline at end of file diff --git a/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php b/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php index 3ac00fa..60f80d3 100644 --- a/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php +++ b/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php @@ -1,8 +1,48 @@ query('DROP DATABASE kilix_rbac_test'); + } + + /** + * @dataProvider configurationProvider + */ + public function test($config) + { + Jf::loadConfig($config); + + $installer = new PdoMysqlInstaller(); + $installationSuccess = $installer->init( + $config['host'], + $config['user'], + $config['pass'], + $config['dbname'] + ); + + $this->assertTrue($installationSuccess); + } + + public function configurationProvider() + { + return [ + [ + [ + 'host' => 'localhost', + 'user' => 'root', + 'pass' => 'vagrant', + 'dbname' => 'kilix_rbac_test', + 'table_prefix' => 'kilix_rbac_' + ] + ] + ]; + } +} \ No newline at end of file diff --git a/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php b/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php index 3ac00fa..d32f439 100644 --- a/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php +++ b/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php @@ -1,8 +1,59 @@ query('DROP DATABASE kilix_rbac_test'); + unlink('kilix_rbac_test'); + } + + /** + * @dataProvider configurationProvider + */ + public function test($config) + { + Jf::loadConfig($config); + + $installer = new PdoSqliteInstaller(); + // DB file will be created + $installationSuccess = $installer->init( + $config['host'], + $config['user'], + $config['pass'], + $config['dbname'] + ); + + $this->assertTrue($installationSuccess); + // File exists + $installationSuccess02 = $installer->init( + $config['host'], + $config['user'], + $config['pass'], + $config['dbname'] + ); + + $this->assertTrue($installationSuccess02); + } + + public function configurationProvider() + { + return [ + [ + [ + 'host' => 'localhost', + 'user' => 'root', + 'pass' => 'vagrant', + 'dbname' => 'kilix_rbac_test', + 'table_prefix' => 'kilix_rbac_' + ] + ] + ]; + } +} \ No newline at end of file diff --git a/PhpRbac/Tests/Database/JfTest.php b/PhpRbac/Tests/Database/JfTest.php index 921a066..6231e87 100644 --- a/PhpRbac/Tests/Database/JfTest.php +++ b/PhpRbac/Tests/Database/JfTest.php @@ -8,6 +8,15 @@ class JfTest extends \PHPUnit_Framework_TestCase { + public static function setUpBeforeClass() + { + $config = self::configProvider()[0][0]; + $config['adapter'] = 'pdo_mysql'; + + Jf::loadConfig($config); + Jf::loadConnection(); + } + public function testSetTablePrefix() { $this->assertNull(Jf::$TABLE_PREFIX); @@ -108,7 +117,7 @@ public function testSqlPrepareMysqlite($config) $this->assertCount(1, $query); } - public function configProvider() + public static function configProvider() { return [ [ From 75d3b79fc8438deccfbcc77d27cf70b00c7c126c Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Wed, 21 Jan 2015 17:19:55 +0100 Subject: [PATCH 27/57] Fix the managers --- PhpRbac/Manager/PermissionManager.php | 4 ++-- PhpRbac/Manager/RbacUserManager.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PhpRbac/Manager/PermissionManager.php b/PhpRbac/Manager/PermissionManager.php index f3ef13b..5f329fc 100644 --- a/PhpRbac/Manager/PermissionManager.php +++ b/PhpRbac/Manager/PermissionManager.php @@ -26,12 +26,12 @@ class PermissionManager extends BaseRbacManager protected function type() { - return "permissions"; + return "permissions"; } function __construct() { - $this->permissions = new FullNestedSet ( Jf::getConfig('table_prefix') . "permissions", "ID", "Lft", "Rght" ); + $this->permissions = new FullNestedSet ( Jf::getConfig('table_prefix') . "permissions", "ID", "Lft", "Rght" ); } /** diff --git a/PhpRbac/Manager/RbacUserManager.php b/PhpRbac/Manager/RbacUserManager.php index 2e956b4..75cb3e8 100644 --- a/PhpRbac/Manager/RbacUserManager.php +++ b/PhpRbac/Manager/RbacUserManager.php @@ -180,7 +180,7 @@ function resetAssignments($Ensure = false) throw new \Exception ("You must pass true to this function, otherwise it won't work."); return; } - $tablePrefix = Jf::getConfig('table_prefix'); + $tablePrefix = Jf::getConfig('table_prefix'); $res = Jf::sql ( "DELETE FROM {$tablePrefix}userroles" ); $Adapter = get_class(Jf::$Db); From c8f050fd5850b82f1594fef4d61ea1015c7643e6 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Thu, 22 Jan 2015 11:55:58 +0100 Subject: [PATCH 28/57] Adapt UserManager name to other managers name --- PhpRbac/Manager/{RbacUserManager.php => UserManager.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PhpRbac/Manager/{RbacUserManager.php => UserManager.php} (100%) diff --git a/PhpRbac/Manager/RbacUserManager.php b/PhpRbac/Manager/UserManager.php similarity index 100% rename from PhpRbac/Manager/RbacUserManager.php rename to PhpRbac/Manager/UserManager.php From ff6a5384bbafa5ac7968aa16ad4aef3fa80abe1b Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Thu, 22 Jan 2015 13:47:59 +0100 Subject: [PATCH 29/57] Final fixes to the managers --- PhpRbac/Manager/BaseRbacManager.php | 4 ++-- PhpRbac/Manager/RbacManager.php | 13 ++++++------- PhpRbac/Manager/UserManager.php | 4 ++-- PhpRbac/Rbac.php | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/PhpRbac/Manager/BaseRbacManager.php b/PhpRbac/Manager/BaseRbacManager.php index c6f16db..7043b20 100644 --- a/PhpRbac/Manager/BaseRbacManager.php +++ b/PhpRbac/Manager/BaseRbacManager.php @@ -139,9 +139,9 @@ public function pathId($Path) $Parts = explode ( "/", $Path ); $Adapter = get_class(Jf::$Db); - if ($Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="mysql")) { + if ($Adapter == "mysqli" or ($Adapter == "PDO" and Jf::$Db->getAttribute(\PDO::ATTR_DRIVER_NAME)=="mysql")) { $GroupConcat="GROUP_CONCAT(parent.Title ORDER BY parent.Lft SEPARATOR '/')"; - } elseif ($Adapter == "PDO" and Jf::$Db->getAttribute(PDO::ATTR_DRIVER_NAME)=="sqlite") { + } elseif ($Adapter == "PDO" and Jf::$Db->getAttribute(\PDO::ATTR_DRIVER_NAME)=="sqlite") { $GroupConcat="GROUP_CONCAT(parent.Title,'/')"; } else { throw new \Exception ("Unknown Group_Concat on this type of database: {$Adapter}"); diff --git a/PhpRbac/Manager/RbacManager.php b/PhpRbac/Manager/RbacManager.php index 4d13db7..13fc4c6 100644 --- a/PhpRbac/Manager/RbacManager.php +++ b/PhpRbac/Manager/RbacManager.php @@ -25,7 +25,7 @@ class RbacManager extends JModel { function __construct() { - $this->Users = new RbacUserManager (); + $this->Users = new UserManager (); $this->Roles = new RoleManager (); $this->Permissions = new PermissionManager (); } @@ -150,18 +150,17 @@ function check($Permission, $UserID = null) * * @throws RbacUserNotProvidedException */ - function enforce($Permission, $UserID = null) - { + function enforce($Permission, $UserID = null) + { if ($UserID === null) - throw new RbacUserNotProvidedException ("\$UserID is a required argument."); + throw new RbacUserNotProvidedException ("\$UserID is a required argument."); - if (! $this->check($Permission, $UserID)) { + if (! $this->check($Permission, $UserID)) { header('HTTP/1.1 403 Forbidden'); die("Forbidden: You do not have permission to access this resource."); } - return true; - } + } /** * Remove all roles, permissions and assignments diff --git a/PhpRbac/Manager/UserManager.php b/PhpRbac/Manager/UserManager.php index 75cb3e8..a7ec28e 100644 --- a/PhpRbac/Manager/UserManager.php +++ b/PhpRbac/Manager/UserManager.php @@ -19,7 +19,7 @@ * @author abiusx * @version 1.0 */ -class RbacUserManager extends JModel +class UserManager extends JModel { /** * Checks to see whether a user has a role or not @@ -107,7 +107,7 @@ function assign($Role, $UserID = null) function unassign($Role, $UserID = null) { if ($UserID === null) - throw new RbacUserNotProvidedException ("\$UserID is a required argument."); + throw new RbacUserNotProvidedException ("\$UserID is a required argument."); if (is_numeric($Role)) { diff --git a/PhpRbac/Rbac.php b/PhpRbac/Rbac.php index d713e33..77dfb53 100644 --- a/PhpRbac/Rbac.php +++ b/PhpRbac/Rbac.php @@ -35,6 +35,6 @@ public function reset($ensure = false) public function tablePrefix() { - return Jf::$Rbac->tablePrefix(); + return Jf::getConfig('table_prefix'); } } \ No newline at end of file From 1cdc5a7e2193d57c2a99f40272beca266af54ff5 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Thu, 22 Jan 2015 13:48:19 +0100 Subject: [PATCH 30/57] Add Tests for the library --- .../Tests/Manager/PermissionManagerTest.php | 126 ++++++++++++++++++ PhpRbac/Tests/Manager/RbacManagerTest.php | 104 +++++++++++++++ PhpRbac/Tests/Manager/RoleManagerTest.php | 125 +++++++++++++++++ PhpRbac/Tests/Manager/UserManagerTest.php | 86 ++++++++++++ PhpRbac/Tests/RbacTest.php | 63 +++++++++ 5 files changed, 504 insertions(+) create mode 100644 PhpRbac/Tests/Manager/PermissionManagerTest.php create mode 100644 PhpRbac/Tests/Manager/RbacManagerTest.php create mode 100644 PhpRbac/Tests/Manager/RoleManagerTest.php create mode 100644 PhpRbac/Tests/Manager/UserManagerTest.php create mode 100644 PhpRbac/Tests/RbacTest.php diff --git a/PhpRbac/Tests/Manager/PermissionManagerTest.php b/PhpRbac/Tests/Manager/PermissionManagerTest.php new file mode 100644 index 0000000..5cf88fd --- /dev/null +++ b/PhpRbac/Tests/Manager/PermissionManagerTest.php @@ -0,0 +1,126 @@ +configurationProvider()[0][0]); + Jf::loadConnection(); + + $rbac->reset(true); + + $this->manager = new PermissionManager(); + } + + public function testAdd() + { + $this->manager->add('read-article', 'Lire un article'); + + $nbPermissions = $this->manager->count(); + + $this->assertEquals(2, $nbPermissions); + } + + public function testAddPath() + { + $this->manager->addPath('/connect-admin'); + + $permissions = $this->manager->children(1); + + $this->assertCount(1, $permissions); + $this->assertEquals('connect-admin', $permissions[0]['Title']); + } + + public function testAssign() + { + $this->manager->addPath('/connect-admin'); + $this->manager->assign(1, 'connect-admin'); + + $this->assertCount(1, $this->manager->roles('connect-admin')); + } + + public function testRemove() + { + $this->manager->addPath('/connect-admin'); + $this->manager->assign(1, 'connect-admin'); + + $return = $this->manager->remove($this->manager->titleId('connect-admin')); + + $this->assertTrue($return); + $this->assertEquals(1, $this->manager->count()); + } + + public function testRoles() + { + $this->manager->addPath('/connect-admin'); + $this->manager->assign(1, 'connect-admin'); + + $roles = $this->manager->roles('connect-admin', false); + + $this->assertCount(1, $roles); + $this->assertEquals('root', $roles[0]['Title']); + } + + public function testDepth() + { + $this->manager->addPath('/register-admin/connect-admin'); + $this->manager->depth($this->manager->titleId('register-admin')); + } + + public function testGetTitle() + { + $this->assertEquals('root', $this->manager->getTitle(1)); + } + + public function testGetDescription() + { + $this->assertEquals('root', $this->manager->getDescription(1)); + } + + public function testGetPath() + { + $this->assertEquals('/', $this->manager->getPath(1)); + } + + public function testUnassign() + { + $this->assertEquals(1, $this->manager->unassignRoles(1)); + $this->assertNull($this->manager->roles(1)); + } + + public function testEdit() + { + $this->manager->addPath('/log'); + + $this->manager->edit($this->manager->titleId('log'), 'file-log', 'Log into files'); + + $this->assertEquals('file-log', $this->manager->descendants(1)['file-log']['Title']); + } + + public function configurationProvider() + { + return [ + [ + [ + "adapter" => "pdo_mysql", + "host" => "localhost", + "user" => "root", + "pass" => "vagrant", + "dbname" => "kilix_rbac_test", + "table_prefix" => "kilix_rbac_" + ] + ] + ]; + } +} \ No newline at end of file diff --git a/PhpRbac/Tests/Manager/RbacManagerTest.php b/PhpRbac/Tests/Manager/RbacManagerTest.php new file mode 100644 index 0000000..d9e0a66 --- /dev/null +++ b/PhpRbac/Tests/Manager/RbacManagerTest.php @@ -0,0 +1,104 @@ +configurationProvider()[0][0]); + Jf::loadConnection(); + + $rbac->reset(true); + + $this->manager = new RbacManager(); + } + + public function testAssign() + { + $this->manager->assign(1, 1); + + $this->assertCount(1, $this->manager->Permissions->roles(1)); + } + + public function testCheckWithInexactData() + { + $this->assertFalse($this->manager->check(1, 2)); + } + + public function testCheckWithExactData() + { + $this->assertTrue($this->manager->check('/', 1)); + } + + public function testCheckWithPermissionTitle() + { + $this->assertTrue($this->manager->check('root', 1)); + } + + /** + * @expectedException PhpRbac\Exception\RbacUserNotProvidedException + */ + public function testInvalidCheck() + { + $this->manager->check(1); + } + + public function testEnforceWithExactData() + { + $this->assertTrue($this->manager->enforce(1, 1)); + } + + /** + * @expectedException PhpRbac\Exception\RbacUserNotProvidedException + */ + public function testInvalidEnforce() + { + $this->manager->enforce(1); + } + + /** + * @runInSeparateProcess + */ + public function testEnforceWithInexactData() + { + $this->markTestIncomplete('Need to fix the PHPUnit_Framework_Error'); + $this->manager->enforce(1, 2); + } + + /** + * @expectedException Exception + */ + public function testInvalidReset() + { + $this->manager->reset(); + } + + public function configurationProvider() + { + return [ + [ + [ + "adapter" => "pdo_mysql", + "host" => "localhost", + "user" => "root", + "pass" => "vagrant", + "dbname" => "kilix_rbac_test", + "table_prefix" => "kilix_rbac_" + ] + ] + ]; + } +} \ No newline at end of file diff --git a/PhpRbac/Tests/Manager/RoleManagerTest.php b/PhpRbac/Tests/Manager/RoleManagerTest.php new file mode 100644 index 0000000..9091d8e --- /dev/null +++ b/PhpRbac/Tests/Manager/RoleManagerTest.php @@ -0,0 +1,125 @@ +configurationProvider()[0][0]); + Jf::loadConnection(); + + $rbac->reset(true); + + $this->manager = new RoleManager(); + } + + public function testRecursiveRemove() + { + $this->manager->addPath('/administrator/moderator'); + + $this->manager->remove($this->manager->titleId('administrator'), true); + + $this->assertEquals(1, $this->manager->count()); + } + + public function testRemove() + { + $this->manager->addPath('/administrator/moderator', ['Admin', 'Modo']); + + $this->manager->remove($this->manager->titleId('administrator')); + + $this->assertEquals(2, $this->manager->count()); + $this->assertEquals('moderator', $this->manager->children(1)[0]['Title']); + $this->assertEquals('Modo', $this->manager->children(1)[0]['Description']); + } + + public function testHasPermission() + { + $this->assertTrue($this->manager->hasPermission(1, 1)); + } + + public function testHasNoPermission() + { + $this->assertFalse($this->manager->hasPermission(1, 2)); + } + + public function testPermissions() + { + $permissions = $this->manager->permissions(1); + + $this->assertCount(1, $permissions); + } + + public function testPermissionsWithRoleTitle() + { + $permissions = $this->manager->permissions('root'); + + $this->assertCount(1, $permissions); + } + + public function testCompletePermissions() + { + $permissions = $this->manager->permissions(1, false); + + $this->assertCount(1, $permissions); + $this->assertEquals('root', $permissions[0]['Title']); + } + + public function testUnassign() + { + $this->assertTrue($this->manager->unassign(1, 1)); + } + + public function testUnassignWithTitle() + { + $this->assertTrue($this->manager->unassign('root', 'root')); + } + + public function testUnassignWithPath() + { + $this->assertTrue($this->manager->unassign('/', '/')); + } + + public function testUnassignUsers() + { + $this->assertEquals(1, $this->manager->unassignPermissions(1)); + } + + public function testUnassignPermissions() + { + $this->assertEquals(1, $this->manager->unassignUsers(1)); + } + + public function testParentNode() + { + $this->manager->addPath('/admin'); + + $this->assertEquals('root', $this->manager->parentNode($this->manager->titleId('admin'))['Title']); + } + + public function configurationProvider() + { + return [ + [ + [ + "adapter" => "pdo_mysql", + "host" => "localhost", + "user" => "root", + "pass" => "vagrant", + "dbname" => "kilix_rbac_test", + "table_prefix" => "kilix_rbac_" + ] + ] + ]; + } +} \ No newline at end of file diff --git a/PhpRbac/Tests/Manager/UserManagerTest.php b/PhpRbac/Tests/Manager/UserManagerTest.php new file mode 100644 index 0000000..5b36010 --- /dev/null +++ b/PhpRbac/Tests/Manager/UserManagerTest.php @@ -0,0 +1,86 @@ +configurationProvider()[0][0]); + Jf::loadConnection(); + + $rbac->reset(true); + + $this->manager = new UserManager(); + } + + public function testHasRole() + { + $this->assertTrue($this->manager->hasRole(1, 1)); + } + + public function testHasRoleWithRolePath() + { + $this->assertTrue($this->manager->hasRole('/', 1)); + } + + public function testHasRoleWithRoleTitle() + { + $this->assertTrue($this->manager->hasRole('root', 1)); + } + + public function testAssign() + { + $this->assertTrue($this->manager->assign(1, 2)); + } + + public function testUnassign() + { + $this->assertTrue($this->manager->unassign(1, 1)); + } + + public function testUnassignWithRolePath() + { + $this->assertTrue($this->manager->unassign('/', 1)); + } + + public function testUnassignWithRoleTitle() + { + $this->assertTrue($this->manager->unassign('root', 1)); + } + + public function testAllRoles() + { + $this->assertCount(1, $this->manager->allRoles(1)); + } + + public function testRoleCount() + { + $this->assertequals(1, $this->manager->roleCount(1)); + } + + public function configurationProvider() + { + return [ + [ + [ + "adapter" => "pdo_mysql", + "host" => "localhost", + "user" => "root", + "pass" => "vagrant", + "dbname" => "kilix_rbac_test", + "table_prefix" => "kilix_rbac_" + ] + ] + ]; + } +} \ No newline at end of file diff --git a/PhpRbac/Tests/RbacTest.php b/PhpRbac/Tests/RbacTest.php new file mode 100644 index 0000000..695d7f0 --- /dev/null +++ b/PhpRbac/Tests/RbacTest.php @@ -0,0 +1,63 @@ +rbac = new Rbac(); + + Jf::loadConfig($this->configurationProvider()[0][0]); + Jf::loadConnection(); + + $this->rbac->reset(true); + } + + public function testAssign() + { + $this->rbac->Roles->addPath('/role_01/role_02'); + $this->rbac->Permissions->addPath('/permission_01/permission_02'); + + $this->assertTrue($this->rbac->assign('role_01', 'permission_02')); + } + + public function testCheck() + { + $this->assertTrue($this->rbac->check(1, 1)); + } + + public function testEnforce() + { + $this->rbac->Permissions->add('read-article', 'Lire un article'); + + $this->assertTrue($this->rbac->enforce('read-article', 1)); + } + + public function testTablePrefix() + { + $this->assertInternalType('string', $this->rbac->tablePrefix()); + } + + public function configurationProvider() + { + return [ + [ + [ + "adapter" => "pdo_mysql", + "host" => "localhost", + "user" => "root", + "pass" => "vagrant", + "dbname" => "kilix_rbac_test", + "table_prefix" => "kilix_rbac_" + ] + ] + ]; + } +} \ No newline at end of file From 3871167bfd261b7a6979ff8f681afa20a59724d5 Mon Sep 17 00:00:00 2001 From: Axel Venet Date: Thu, 22 Jan 2015 13:49:00 +0100 Subject: [PATCH 31/57] Delete old database configuration --- PhpRbac/Tests/database/database.config | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 PhpRbac/Tests/database/database.config diff --git a/PhpRbac/Tests/database/database.config b/PhpRbac/Tests/database/database.config deleted file mode 100644 index e217c17..0000000 --- a/PhpRbac/Tests/database/database.config +++ /dev/null @@ -1,26 +0,0 @@ - Date: Thu, 22 Jan 2015 13:52:28 +0100 Subject: [PATCH 32/57] Remove old tests files and rename phpunit configuration file --- ...xpected_add_path_permissions_hierarchy.xml | 19 ------- ...path_permissions_hierarchy_description.xml | 19 ------- ...pected_add_path_permissions_sequential.xml | 7 --- ...ath_permissions_sequential_description.xml | 7 --- .../expected_add_path_permissions_single.xml | 7 --- ...dd_path_permissions_single_description.xml | 7 --- .../expected_add_path_roles_hierarchy.xml | 19 ------- ...d_add_path_roles_hierarchy_description.xml | 19 ------- .../expected_add_path_roles_sequential.xml | 7 --- ..._add_path_roles_sequential_description.xml | 7 --- .../base/expected_add_path_roles_single.xml | 7 --- ...cted_add_path_roles_single_description.xml | 7 --- .../expected_add_permissions_hierarchy.xml | 12 ----- .../expected_add_permissions_sequential.xml | 7 --- .../base/expected_add_roles_hierarchy.xml | 12 ----- .../base/expected_add_roles_sequential.xml | 7 --- .../base/expected_assign_permissions.xml | 9 ---- .../datasets/base/expected_assign_roles.xml | 9 ---- .../base/expected_edit_permissions_all.xml | 4 -- .../expected_edit_permissions_description.xml | 4 -- .../base/expected_edit_permissions_title.xml | 4 -- .../datasets/base/expected_edit_roles_all.xml | 4 -- .../base/expected_edit_roles_description.xml | 4 -- .../base/expected_edit_roles_title.xml | 4 -- ...expected_reset_assignments_permissions.xml | 4 -- .../base/expected_reset_assignments_roles.xml | 4 -- .../base/expected_reset_permissions.xml | 4 -- .../datasets/base/expected_reset_roles.xml | 4 -- .../base/expected_unassign_permissions.xml | 4 -- .../datasets/base/expected_unassign_roles.xml | 4 -- PhpRbac/Tests/datasets/database-seed.xml | 51 ------------------- .../datasets/manager/expected_assign_id.xml | 9 ---- .../datasets/manager/expected_assign_path.xml | 13 ----- .../manager/expected_assign_title.xml | 9 ---- .../Tests/datasets/manager/expected_reset.xml | 7 --- .../permissions/expected_remove_recursive.xml | 9 ---- .../permissions/expected_remove_single.xml | 4 -- .../expected_remove_single_role.xml | 7 --- .../permissions/expected_unassign_roles.xml | 4 -- .../roles/expected_remove_recursive.xml | 7 --- .../datasets/roles/expected_remove_single.xml | 4 -- .../expected_remove_single_permission.xml | 8 --- .../roles/expected_unassign_permissions.xml | 4 -- .../roles/expected_unassign_users.xml | 6 --- .../datasets/users/expected_assign_no_id.xml | 5 -- .../users/expected_assign_with_id.xml | 5 -- .../users/expected_assign_with_path.xml | 5 -- .../users/expected_reset_assignments.xml | 4 -- .../datasets/users/expected_unassign.xml | 6 --- PhpRbac/Tests/mysql_tests.bat | 3 -- PhpRbac/Tests/mysql_tests.sh | 4 -- PhpRbac/Tests/phpunit.bat | 3 -- .../Tests/{phpunit_mysql.xml => phpunit.xml} | 3 -- PhpRbac/Tests/phpunit_sqlite.xml | 15 ------ PhpRbac/Tests/sqlite_tests.bat | 3 -- PhpRbac/Tests/sqlite_tests.sh | 4 -- 56 files changed, 438 deletions(-) delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_permissions_single.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_permissions_single_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_roles_single.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_path_roles_single_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_permissions_hierarchy.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_permissions_sequential.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_roles_hierarchy.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_add_roles_sequential.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_assign_permissions.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_assign_roles.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_edit_permissions_all.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_edit_permissions_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_edit_permissions_title.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_edit_roles_all.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_edit_roles_description.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_edit_roles_title.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_reset_assignments_permissions.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_reset_assignments_roles.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_reset_permissions.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_reset_roles.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_unassign_permissions.xml delete mode 100644 PhpRbac/Tests/datasets/base/expected_unassign_roles.xml delete mode 100644 PhpRbac/Tests/datasets/database-seed.xml delete mode 100644 PhpRbac/Tests/datasets/manager/expected_assign_id.xml delete mode 100644 PhpRbac/Tests/datasets/manager/expected_assign_path.xml delete mode 100644 PhpRbac/Tests/datasets/manager/expected_assign_title.xml delete mode 100644 PhpRbac/Tests/datasets/manager/expected_reset.xml delete mode 100644 PhpRbac/Tests/datasets/permissions/expected_remove_recursive.xml delete mode 100644 PhpRbac/Tests/datasets/permissions/expected_remove_single.xml delete mode 100644 PhpRbac/Tests/datasets/permissions/expected_remove_single_role.xml delete mode 100644 PhpRbac/Tests/datasets/permissions/expected_unassign_roles.xml delete mode 100644 PhpRbac/Tests/datasets/roles/expected_remove_recursive.xml delete mode 100644 PhpRbac/Tests/datasets/roles/expected_remove_single.xml delete mode 100644 PhpRbac/Tests/datasets/roles/expected_remove_single_permission.xml delete mode 100644 PhpRbac/Tests/datasets/roles/expected_unassign_permissions.xml delete mode 100644 PhpRbac/Tests/datasets/roles/expected_unassign_users.xml delete mode 100644 PhpRbac/Tests/datasets/users/expected_assign_no_id.xml delete mode 100644 PhpRbac/Tests/datasets/users/expected_assign_with_id.xml delete mode 100644 PhpRbac/Tests/datasets/users/expected_assign_with_path.xml delete mode 100644 PhpRbac/Tests/datasets/users/expected_reset_assignments.xml delete mode 100644 PhpRbac/Tests/datasets/users/expected_unassign.xml delete mode 100644 PhpRbac/Tests/mysql_tests.bat delete mode 100644 PhpRbac/Tests/mysql_tests.sh delete mode 100644 PhpRbac/Tests/phpunit.bat rename PhpRbac/Tests/{phpunit_mysql.xml => phpunit.xml} (73%) delete mode 100644 PhpRbac/Tests/phpunit_sqlite.xml delete mode 100644 PhpRbac/Tests/sqlite_tests.bat delete mode 100644 PhpRbac/Tests/sqlite_tests.sh diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy.xml deleted file mode 100644 index 06111b6..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy_description.xml deleted file mode 100644 index e1cb9ed..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_hierarchy_description.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential.xml deleted file mode 100644 index 6e8a20e..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential_description.xml deleted file mode 100644 index 471acf2..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_sequential_description.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single.xml deleted file mode 100644 index 6e8a20e..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single_description.xml deleted file mode 100644 index 471acf2..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_permissions_single_description.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy.xml deleted file mode 100644 index d48b105..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy_description.xml deleted file mode 100644 index cb9db55..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_roles_hierarchy_description.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential.xml deleted file mode 100644 index dae48fc..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential_description.xml deleted file mode 100644 index 1cf1f17..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_roles_sequential_description.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_roles_single.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_single.xml deleted file mode 100644 index dae48fc..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_roles_single.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_path_roles_single_description.xml b/PhpRbac/Tests/datasets/base/expected_add_path_roles_single_description.xml deleted file mode 100644 index 1cf1f17..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_path_roles_single_description.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_permissions_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_permissions_hierarchy.xml deleted file mode 100644 index 23d4fd5..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_permissions_hierarchy.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_permissions_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_permissions_sequential.xml deleted file mode 100644 index cf1e7fd..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_permissions_sequential.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_roles_hierarchy.xml b/PhpRbac/Tests/datasets/base/expected_add_roles_hierarchy.xml deleted file mode 100644 index 31af121..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_roles_hierarchy.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_add_roles_sequential.xml b/PhpRbac/Tests/datasets/base/expected_add_roles_sequential.xml deleted file mode 100644 index 79f96fa..0000000 --- a/PhpRbac/Tests/datasets/base/expected_add_roles_sequential.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_assign_permissions.xml b/PhpRbac/Tests/datasets/base/expected_assign_permissions.xml deleted file mode 100644 index df48feb..0000000 --- a/PhpRbac/Tests/datasets/base/expected_assign_permissions.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_assign_roles.xml b/PhpRbac/Tests/datasets/base/expected_assign_roles.xml deleted file mode 100644 index df48feb..0000000 --- a/PhpRbac/Tests/datasets/base/expected_assign_roles.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_edit_permissions_all.xml b/PhpRbac/Tests/datasets/base/expected_edit_permissions_all.xml deleted file mode 100644 index c0fd9bc..0000000 --- a/PhpRbac/Tests/datasets/base/expected_edit_permissions_all.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_edit_permissions_description.xml b/PhpRbac/Tests/datasets/base/expected_edit_permissions_description.xml deleted file mode 100644 index 372e98e..0000000 --- a/PhpRbac/Tests/datasets/base/expected_edit_permissions_description.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_edit_permissions_title.xml b/PhpRbac/Tests/datasets/base/expected_edit_permissions_title.xml deleted file mode 100644 index 0d2341c..0000000 --- a/PhpRbac/Tests/datasets/base/expected_edit_permissions_title.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_edit_roles_all.xml b/PhpRbac/Tests/datasets/base/expected_edit_roles_all.xml deleted file mode 100644 index 49ef5a4..0000000 --- a/PhpRbac/Tests/datasets/base/expected_edit_roles_all.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_edit_roles_description.xml b/PhpRbac/Tests/datasets/base/expected_edit_roles_description.xml deleted file mode 100644 index 09ce9d9..0000000 --- a/PhpRbac/Tests/datasets/base/expected_edit_roles_description.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_edit_roles_title.xml b/PhpRbac/Tests/datasets/base/expected_edit_roles_title.xml deleted file mode 100644 index 1474c9d..0000000 --- a/PhpRbac/Tests/datasets/base/expected_edit_roles_title.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_reset_assignments_permissions.xml b/PhpRbac/Tests/datasets/base/expected_reset_assignments_permissions.xml deleted file mode 100644 index 24683d1..0000000 --- a/PhpRbac/Tests/datasets/base/expected_reset_assignments_permissions.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_reset_assignments_roles.xml b/PhpRbac/Tests/datasets/base/expected_reset_assignments_roles.xml deleted file mode 100644 index 24683d1..0000000 --- a/PhpRbac/Tests/datasets/base/expected_reset_assignments_roles.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_reset_permissions.xml b/PhpRbac/Tests/datasets/base/expected_reset_permissions.xml deleted file mode 100644 index af97c59..0000000 --- a/PhpRbac/Tests/datasets/base/expected_reset_permissions.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_reset_roles.xml b/PhpRbac/Tests/datasets/base/expected_reset_roles.xml deleted file mode 100644 index f1a0adf..0000000 --- a/PhpRbac/Tests/datasets/base/expected_reset_roles.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_unassign_permissions.xml b/PhpRbac/Tests/datasets/base/expected_unassign_permissions.xml deleted file mode 100644 index 24683d1..0000000 --- a/PhpRbac/Tests/datasets/base/expected_unassign_permissions.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/base/expected_unassign_roles.xml b/PhpRbac/Tests/datasets/base/expected_unassign_roles.xml deleted file mode 100644 index 24683d1..0000000 --- a/PhpRbac/Tests/datasets/base/expected_unassign_roles.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/database-seed.xml b/PhpRbac/Tests/datasets/database-seed.xml deleted file mode 100644 index 2778743..0000000 --- a/PhpRbac/Tests/datasets/database-seed.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - ID - Lft - Rght - Title - Description - - 1 - 0 - 1 - root - root - -
- - RoleID - PermissionID - AssignmentDate - - 1 - 1 - 1376789692 - -
- - ID - Lft - Rght - Title - Description - - 1 - 0 - 1 - root - root - -
- - UserID - RoleID - AssignmentDate - - 1 - 1 - 1376789694 - -
-
\ No newline at end of file diff --git a/PhpRbac/Tests/datasets/manager/expected_assign_id.xml b/PhpRbac/Tests/datasets/manager/expected_assign_id.xml deleted file mode 100644 index df48feb..0000000 --- a/PhpRbac/Tests/datasets/manager/expected_assign_id.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/manager/expected_assign_path.xml b/PhpRbac/Tests/datasets/manager/expected_assign_path.xml deleted file mode 100644 index ed2a2d1..0000000 --- a/PhpRbac/Tests/datasets/manager/expected_assign_path.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/manager/expected_assign_title.xml b/PhpRbac/Tests/datasets/manager/expected_assign_title.xml deleted file mode 100644 index df48feb..0000000 --- a/PhpRbac/Tests/datasets/manager/expected_assign_title.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/manager/expected_reset.xml b/PhpRbac/Tests/datasets/manager/expected_reset.xml deleted file mode 100644 index 14e046e..0000000 --- a/PhpRbac/Tests/datasets/manager/expected_reset.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/permissions/expected_remove_recursive.xml b/PhpRbac/Tests/datasets/permissions/expected_remove_recursive.xml deleted file mode 100644 index 47cb9ce..0000000 --- a/PhpRbac/Tests/datasets/permissions/expected_remove_recursive.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/permissions/expected_remove_single.xml b/PhpRbac/Tests/datasets/permissions/expected_remove_single.xml deleted file mode 100644 index af97c59..0000000 --- a/PhpRbac/Tests/datasets/permissions/expected_remove_single.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/permissions/expected_remove_single_role.xml b/PhpRbac/Tests/datasets/permissions/expected_remove_single_role.xml deleted file mode 100644 index e5c0e46..0000000 --- a/PhpRbac/Tests/datasets/permissions/expected_remove_single_role.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/permissions/expected_unassign_roles.xml b/PhpRbac/Tests/datasets/permissions/expected_unassign_roles.xml deleted file mode 100644 index 24683d1..0000000 --- a/PhpRbac/Tests/datasets/permissions/expected_unassign_roles.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/roles/expected_remove_recursive.xml b/PhpRbac/Tests/datasets/roles/expected_remove_recursive.xml deleted file mode 100644 index 93f4472..0000000 --- a/PhpRbac/Tests/datasets/roles/expected_remove_recursive.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/roles/expected_remove_single.xml b/PhpRbac/Tests/datasets/roles/expected_remove_single.xml deleted file mode 100644 index f1a0adf..0000000 --- a/PhpRbac/Tests/datasets/roles/expected_remove_single.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/roles/expected_remove_single_permission.xml b/PhpRbac/Tests/datasets/roles/expected_remove_single_permission.xml deleted file mode 100644 index cacc8ea..0000000 --- a/PhpRbac/Tests/datasets/roles/expected_remove_single_permission.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/roles/expected_unassign_permissions.xml b/PhpRbac/Tests/datasets/roles/expected_unassign_permissions.xml deleted file mode 100644 index 24683d1..0000000 --- a/PhpRbac/Tests/datasets/roles/expected_unassign_permissions.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/roles/expected_unassign_users.xml b/PhpRbac/Tests/datasets/roles/expected_unassign_users.xml deleted file mode 100644 index 6004b2b..0000000 --- a/PhpRbac/Tests/datasets/roles/expected_unassign_users.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/users/expected_assign_no_id.xml b/PhpRbac/Tests/datasets/users/expected_assign_no_id.xml deleted file mode 100644 index bccaa4f..0000000 --- a/PhpRbac/Tests/datasets/users/expected_assign_no_id.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/users/expected_assign_with_id.xml b/PhpRbac/Tests/datasets/users/expected_assign_with_id.xml deleted file mode 100644 index 70d3348..0000000 --- a/PhpRbac/Tests/datasets/users/expected_assign_with_id.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/users/expected_assign_with_path.xml b/PhpRbac/Tests/datasets/users/expected_assign_with_path.xml deleted file mode 100644 index 91c1418..0000000 --- a/PhpRbac/Tests/datasets/users/expected_assign_with_path.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/users/expected_reset_assignments.xml b/PhpRbac/Tests/datasets/users/expected_reset_assignments.xml deleted file mode 100644 index 933faaf..0000000 --- a/PhpRbac/Tests/datasets/users/expected_reset_assignments.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/datasets/users/expected_unassign.xml b/PhpRbac/Tests/datasets/users/expected_unassign.xml deleted file mode 100644 index 6004b2b..0000000 --- a/PhpRbac/Tests/datasets/users/expected_unassign.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/PhpRbac/Tests/mysql_tests.bat b/PhpRbac/Tests/mysql_tests.bat deleted file mode 100644 index e05e09f..0000000 --- a/PhpRbac/Tests/mysql_tests.bat +++ /dev/null @@ -1,3 +0,0 @@ -@ECHO OFF -php "%~dp0phpunit.phar" -c phpunit_mysql.xml %* -PAUSE \ No newline at end of file diff --git a/PhpRbac/Tests/mysql_tests.sh b/PhpRbac/Tests/mysql_tests.sh deleted file mode 100644 index 197bc99..0000000 --- a/PhpRbac/Tests/mysql_tests.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -php phpunit.phar -c phpunit_mysql.xml "$@" -read -p "Press [Enter] key to continue..." \ No newline at end of file diff --git a/PhpRbac/Tests/phpunit.bat b/PhpRbac/Tests/phpunit.bat deleted file mode 100644 index 957bcdf..0000000 --- a/PhpRbac/Tests/phpunit.bat +++ /dev/null @@ -1,3 +0,0 @@ -@ECHO OFF -php "%~dp0phpunit.phar" %* -PAUSE \ No newline at end of file diff --git a/PhpRbac/Tests/phpunit_mysql.xml b/PhpRbac/Tests/phpunit.xml similarity index 73% rename from PhpRbac/Tests/phpunit_mysql.xml rename to PhpRbac/Tests/phpunit.xml index 946a890..a5b3190 100644 --- a/PhpRbac/Tests/phpunit_mysql.xml +++ b/PhpRbac/Tests/phpunit.xml @@ -4,7 +4,4 @@ . - - -
diff --git a/PhpRbac/Tests/phpunit_sqlite.xml b/PhpRbac/Tests/phpunit_sqlite.xml deleted file mode 100644 index b7e52b8..0000000 --- a/PhpRbac/Tests/phpunit_sqlite.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - . - - - - - - - - - - - diff --git a/PhpRbac/Tests/sqlite_tests.bat b/PhpRbac/Tests/sqlite_tests.bat deleted file mode 100644 index 5a264d2..0000000 --- a/PhpRbac/Tests/sqlite_tests.bat +++ /dev/null @@ -1,3 +0,0 @@ -@ECHO OFF -php "%~dp0phpunit.phar" -c phpunit_sqlite.xml %* -PAUSE \ No newline at end of file diff --git a/PhpRbac/Tests/sqlite_tests.sh b/PhpRbac/Tests/sqlite_tests.sh deleted file mode 100644 index 18562dc..0000000 --- a/PhpRbac/Tests/sqlite_tests.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash - -php phpunit.phar -c phpunit_sqlite.xml "$@" -read -p "Press [Enter] key to continue..." \ No newline at end of file From be00699442407d5d041018cfefa509ed84fc0fe0 Mon Sep 17 00:00:00 2001 From: Charles Sanquer Date: Thu, 22 Jan 2015 15:14:59 +0100 Subject: [PATCH 33/57] improve phpunit config --- .gitignore | 5 +- .../Installer/MysqliInstallerTest.php | 13 +- .../Installer/PdoMysqlInstallerTest.php | 13 +- .../Installer/PdoSqliteInstallerTest.php | 18 +- PhpRbac/Tests/Database/JfTest.php | 12 +- .../Tests/Manager/PermissionManagerTest.php | 23 +- PhpRbac/Tests/Manager/RbacManagerTest.php | 29 +- PhpRbac/Tests/Manager/RoleManagerTest.php | 23 +- PhpRbac/Tests/Manager/UserManagerTest.php | 21 +- PhpRbac/Tests/RbacTest.php | 22 +- PhpRbac/Tests/RbacTestCase.php | 38 + PhpRbac/Tests/phpunit.phar | 69930 ---------------- PhpRbac/Tests/phpunit.xml | 7 - composer.json | 3 + phpunit.xml.dist | 53 + 15 files changed, 138 insertions(+), 70072 deletions(-) create mode 100644 PhpRbac/Tests/RbacTestCase.php delete mode 100644 PhpRbac/Tests/phpunit.phar delete mode 100644 PhpRbac/Tests/phpunit.xml create mode 100644 phpunit.xml.dist diff --git a/.gitignore b/.gitignore index 0dd953e..1b85d46 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,7 @@ *Doxygen* *phpdoc* /nbproject/ -/vendor/ \ No newline at end of file +/vendor/ +/build +phpunit.xml +composer.lock diff --git a/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php b/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php index e7b08aa..c902592 100644 --- a/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php +++ b/PhpRbac/Tests/Database/Installer/MysqliInstallerTest.php @@ -5,8 +5,9 @@ use PhpRbac\Database\Installer\MysqliInstaller; use PhpRbac\Database\Jf; +use PhpRbac\Tests\RbacTestCase; -class MysqliInstallerTest extends \PHPUnit_Framework_TestCase +class MysqliInstallerTest extends RbacTestCase { public function setUp() { @@ -30,18 +31,12 @@ public function test($config) $this->assertTrue($installationSuccess); } - + public function configurationProvider() { return [ [ - [ - 'host' => 'localhost', - 'user' => 'root', - 'pass' => 'vagrant', - 'dbname' => 'kilix_rbac_test', - 'table_prefix' => 'kilix_rbac_' - ] + static::getSQLConfig('mysql'), ] ]; } diff --git a/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php b/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php index 60f80d3..0937a99 100644 --- a/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php +++ b/PhpRbac/Tests/Database/Installer/PdoMysqlInstallerTest.php @@ -5,8 +5,9 @@ use PhpRbac\Database\Installer\PdoMysqlInstaller; use PhpRbac\Database\Jf; +use PhpRbac\Tests\RbacTestCase; -class PdoMysqlInstallerTest extends \PHPUnit_Framework_TestCase +class PdoMysqlInstallerTest extends RbacTestCase { public function setUp() { @@ -30,18 +31,12 @@ public function test($config) $this->assertTrue($installationSuccess); } - + public function configurationProvider() { return [ [ - [ - 'host' => 'localhost', - 'user' => 'root', - 'pass' => 'vagrant', - 'dbname' => 'kilix_rbac_test', - 'table_prefix' => 'kilix_rbac_' - ] + static::getSQLConfig('pdo_mysql'), ] ]; } diff --git a/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php b/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php index d32f439..ee6d991 100644 --- a/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php +++ b/PhpRbac/Tests/Database/Installer/PdoSqliteInstallerTest.php @@ -5,13 +5,19 @@ use PhpRbac\Database\Installer\PdoSqliteInstaller; use PhpRbac\Database\Jf; +use PhpRbac\Tests\RbacTestCase; -class PdoSqliteInstallerTest extends \PHPUnit_Framework_TestCase +class PdoSqliteInstallerTest extends RbacTestCase { public function setUp() { + $config = static::getSQLConfig('pdo_sqlite'); + Jf::$Db->query('DROP DATABASE kilix_rbac_test'); - unlink('kilix_rbac_test'); + if ($config['dbname'] != ':memory:') { + unlink($config['dbname']); + } + } /** @@ -46,13 +52,7 @@ public function configurationProvider() { return [ [ - [ - 'host' => 'localhost', - 'user' => 'root', - 'pass' => 'vagrant', - 'dbname' => 'kilix_rbac_test', - 'table_prefix' => 'kilix_rbac_' - ] + static::getSQLConfig('pdo_sqlite'), ] ]; } diff --git a/PhpRbac/Tests/Database/JfTest.php b/PhpRbac/Tests/Database/JfTest.php index 6231e87..7202f81 100644 --- a/PhpRbac/Tests/Database/JfTest.php +++ b/PhpRbac/Tests/Database/JfTest.php @@ -5,8 +5,9 @@ use PhpRbac\Database\Jf; use PhpRbac\Rbac; +use PhpRbac\Tests\RbacTestCase; -class JfTest extends \PHPUnit_Framework_TestCase +class JfTest extends RbacTestCase { public static function setUpBeforeClass() { @@ -121,14 +122,7 @@ public static function configProvider() { return [ [ - [ - 'adapter' => 'fakeAdapter', - 'host' => 'localhost', - 'user' => 'root', - 'pass' => 'vagrant', - 'dbname'=> 'kilix_rbac_test', - 'table_prefix' => 'kilix_rbac_' - ] + static::getSQLConfig('fakeAdapter'), ] ]; } diff --git a/PhpRbac/Tests/Manager/PermissionManagerTest.php b/PhpRbac/Tests/Manager/PermissionManagerTest.php index 5cf88fd..cf7bd1c 100644 --- a/PhpRbac/Tests/Manager/PermissionManagerTest.php +++ b/PhpRbac/Tests/Manager/PermissionManagerTest.php @@ -5,8 +5,9 @@ use PhpRbac\Manager\PermissionManager; use PhpRbac\Rbac; use PhpRbac\Database\Jf; +use PhpRbac\Tests\RbacTestCase; -class PermissionManagerTest extends \PHPUnit_Framework_TestCase +class PermissionManagerTest extends RbacTestCase { /** @var PermissionManager **/ private $manager; @@ -14,8 +15,8 @@ class PermissionManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { $rbac = new Rbac(); - - Jf::loadConfig($this->configurationProvider()[0][0]); + + Jf::loadConfig(static::getSQLConfig('pdo_mysql')); Jf::loadConnection(); $rbac->reset(true); @@ -107,20 +108,4 @@ public function testEdit() $this->assertEquals('file-log', $this->manager->descendants(1)['file-log']['Title']); } - - public function configurationProvider() - { - return [ - [ - [ - "adapter" => "pdo_mysql", - "host" => "localhost", - "user" => "root", - "pass" => "vagrant", - "dbname" => "kilix_rbac_test", - "table_prefix" => "kilix_rbac_" - ] - ] - ]; - } } \ No newline at end of file diff --git a/PhpRbac/Tests/Manager/RbacManagerTest.php b/PhpRbac/Tests/Manager/RbacManagerTest.php index d9e0a66..1df0b3a 100644 --- a/PhpRbac/Tests/Manager/RbacManagerTest.php +++ b/PhpRbac/Tests/Manager/RbacManagerTest.php @@ -4,12 +4,11 @@ use PhpRbac\Manager\RbacManager; use PhpRbac\Rbac; - use PhpRbac\Exception\RbacUserNotProvidedException; - use PhpRbac\Database\Jf; +use PhpRbac\Tests\RbacTestCase; -class RbacManagerTest extends \PHPUnit_Framework_TestCase +class RbacManagerTest extends RbacTestCase { /** @var RbacManager **/ private $manager; @@ -17,8 +16,8 @@ class RbacManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { $rbac = new Rbac(); - - Jf::loadConfig($this->configurationProvider()[0][0]); + + Jf::loadConfig(static::getSQLConfig('pdo_mysql')); Jf::loadConnection(); $rbac->reset(true); @@ -49,7 +48,7 @@ public function testCheckWithPermissionTitle() } /** - * @expectedException PhpRbac\Exception\RbacUserNotProvidedException + * @expectedException \PhpRbac\Exception\RbacUserNotProvidedException */ public function testInvalidCheck() { @@ -62,7 +61,7 @@ public function testEnforceWithExactData() } /** - * @expectedException PhpRbac\Exception\RbacUserNotProvidedException + * @expectedException \PhpRbac\Exception\RbacUserNotProvidedException */ public function testInvalidEnforce() { @@ -85,20 +84,4 @@ public function testInvalidReset() { $this->manager->reset(); } - - public function configurationProvider() - { - return [ - [ - [ - "adapter" => "pdo_mysql", - "host" => "localhost", - "user" => "root", - "pass" => "vagrant", - "dbname" => "kilix_rbac_test", - "table_prefix" => "kilix_rbac_" - ] - ] - ]; - } } \ No newline at end of file diff --git a/PhpRbac/Tests/Manager/RoleManagerTest.php b/PhpRbac/Tests/Manager/RoleManagerTest.php index 9091d8e..f3cf087 100644 --- a/PhpRbac/Tests/Manager/RoleManagerTest.php +++ b/PhpRbac/Tests/Manager/RoleManagerTest.php @@ -5,8 +5,9 @@ use PhpRbac\Manager\RoleManager; use PhpRbac\Rbac; use PhpRbac\Database\Jf; +use PhpRbac\Tests\RbacTestCase; -class RoleManagerTest extends \PHPUnit_Framework_TestCase +class RoleManagerTest extends RbacTestCase { /** @var RoleManager **/ private $manager; @@ -14,8 +15,8 @@ class RoleManagerTest extends \PHPUnit_Framework_TestCase public function setUp() { $rbac = new Rbac(); - - Jf::loadConfig($this->configurationProvider()[0][0]); + + Jf::loadConfig(static::getSQLConfig('pdo_mysql')); Jf::loadConnection(); $rbac->reset(true); @@ -106,20 +107,4 @@ public function testParentNode() $this->assertEquals('root', $this->manager->parentNode($this->manager->titleId('admin'))['Title']); } - - public function configurationProvider() - { - return [ - [ - [ - "adapter" => "pdo_mysql", - "host" => "localhost", - "user" => "root", - "pass" => "vagrant", - "dbname" => "kilix_rbac_test", - "table_prefix" => "kilix_rbac_" - ] - ] - ]; - } } \ No newline at end of file diff --git a/PhpRbac/Tests/Manager/UserManagerTest.php b/PhpRbac/Tests/Manager/UserManagerTest.php index 5b36010..6d9b2e7 100644 --- a/PhpRbac/Tests/Manager/UserManagerTest.php +++ b/PhpRbac/Tests/Manager/UserManagerTest.php @@ -5,8 +5,9 @@ use PhpRbac\Manager\UserManager; use PhpRbac\Rbac; use PhpRbac\Database\Jf; +use PhpRbac\Tests\RbacTestCase; -class UserManagerTest extends \PHPUnit_Framework_TestCase +class UserManagerTest extends RbacTestCase { /** @var RoleManager **/ private $manager; @@ -15,7 +16,7 @@ public function setUp() { $rbac = new Rbac(); - Jf::loadConfig($this->configurationProvider()[0][0]); + Jf::loadConfig(static::getSQLConfig('pdo_mysql')); Jf::loadConnection(); $rbac->reset(true); @@ -67,20 +68,4 @@ public function testRoleCount() { $this->assertequals(1, $this->manager->roleCount(1)); } - - public function configurationProvider() - { - return [ - [ - [ - "adapter" => "pdo_mysql", - "host" => "localhost", - "user" => "root", - "pass" => "vagrant", - "dbname" => "kilix_rbac_test", - "table_prefix" => "kilix_rbac_" - ] - ] - ]; - } } \ No newline at end of file diff --git a/PhpRbac/Tests/RbacTest.php b/PhpRbac/Tests/RbacTest.php index 695d7f0..760f0f5 100644 --- a/PhpRbac/Tests/RbacTest.php +++ b/PhpRbac/Tests/RbacTest.php @@ -5,7 +5,7 @@ use PhpRbac\Rbac; use PhpRbac\Database\Jf; -class RbacTest extends \PHPUnit_Framework_TestCase +class RbacTest extends RbacTestCase { /** @var Rbac **/ private $rbac; @@ -13,8 +13,8 @@ class RbacTest extends \PHPUnit_Framework_TestCase public function setUp() { $this->rbac = new Rbac(); - - Jf::loadConfig($this->configurationProvider()[0][0]); + + Jf::loadConfig(static::getSQLConfig('pdo_mysql')); Jf::loadConnection(); $this->rbac->reset(true); @@ -44,20 +44,4 @@ public function testTablePrefix() { $this->assertInternalType('string', $this->rbac->tablePrefix()); } - - public function configurationProvider() - { - return [ - [ - [ - "adapter" => "pdo_mysql", - "host" => "localhost", - "user" => "root", - "pass" => "vagrant", - "dbname" => "kilix_rbac_test", - "table_prefix" => "kilix_rbac_" - ] - ] - ]; - } } \ No newline at end of file diff --git a/PhpRbac/Tests/RbacTestCase.php b/PhpRbac/Tests/RbacTestCase.php new file mode 100644 index 0000000..f054bdb --- /dev/null +++ b/PhpRbac/Tests/RbacTestCase.php @@ -0,0 +1,38 @@ + $adapter, + "host" => $GLOBALS['SQLITE_DB_HOST'], + "user" => $GLOBALS['SQLITE_DB_USER'], + "pass" => $GLOBALS['SQLITE_DB_PASSWD'], + "dbname" => $GLOBALS['SQLITE_DB_DBNAME'], + ]; + break; + case 'pdo_mysql': + case 'mysql': + default: + $config = [ + "adapter" => $adapter, + "host" => $GLOBALS['MYSQL_DB_HOST'], + "user" => $GLOBALS['MYSQL_DB_USER'], + "pass" => $GLOBALS['MYSQL_DB_PASSWD'], + "dbname" => $GLOBALS['MYSQL_DB_DBNAME'], + ]; + } + + $config['table_prefix'] = $GLOBALS['DB_TABLE_PREFIX']; + + return $config; + } +} diff --git a/PhpRbac/Tests/phpunit.phar b/PhpRbac/Tests/phpunit.phar deleted file mode 100644 index 53f53f5..0000000 --- a/PhpRbac/Tests/phpunit.phar +++ /dev/null @@ -1,69930 +0,0 @@ -#!/usr/bin/env php - '/DbUnit-1.2.3/Samples/BankAccountDB/BankAccount.php', - 'bankaccountdbtest' => '/DbUnit-1.2.3/Samples/BankAccountDB/BankAccountDBTest.php', - 'bankaccountdbtestmysql' => '/DbUnit-1.2.3/Samples/BankAccountDB/BankAccountDBTestMySQL.php', - 'bankaccountexception' => '/DbUnit-1.2.3/Samples/BankAccountDB/BankAccount.php', - 'file_iterator' => '/File_Iterator-1.3.3/File/Iterator.php', - 'file_iterator_facade' => '/File_Iterator-1.3.3/File/Iterator/Facade.php', - 'file_iterator_factory' => '/File_Iterator-1.3.3/File/Iterator/Factory.php', - 'php_codecoverage' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage.php', - 'php_codecoverage_driver' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Driver.php', - 'php_codecoverage_driver_xdebug' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Driver/Xdebug.php', - 'php_codecoverage_exception' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Exception.php', - 'php_codecoverage_filter' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Filter.php', - 'php_codecoverage_report_clover' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Clover.php', - 'php_codecoverage_report_factory' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Factory.php', - 'php_codecoverage_report_html' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML.php', - 'php_codecoverage_report_html_renderer' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer.php', - 'php_codecoverage_report_html_renderer_dashboard' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Dashboard.php', - 'php_codecoverage_report_html_renderer_directory' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Directory.php', - 'php_codecoverage_report_html_renderer_file' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/File.php', - 'php_codecoverage_report_node' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node.php', - 'php_codecoverage_report_node_directory' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node/Directory.php', - 'php_codecoverage_report_node_file' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node/File.php', - 'php_codecoverage_report_node_iterator' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node/Iterator.php', - 'php_codecoverage_report_php' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/PHP.php', - 'php_codecoverage_report_text' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Text.php', - 'php_codecoverage_util' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Util.php', - 'php_codecoverage_util_invalidargumenthelper' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Util/InvalidArgumentHelper.php', - 'php_codecoverage_version' => '/PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Version.php', - 'php_invoker' => '/PHP_Invoker-1.1.2/PHP/Invoker.php', - 'php_invoker_timeoutexception' => '/PHP_Invoker-1.1.2/PHP/Invoker/TimeoutException.php', - 'php_timer' => '/PHP_Timer-1.0.5/PHP/Timer.php', - 'php_token' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_abstract' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_ampersand' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_and_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_array' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_array_cast' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_as' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_at' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_backtick' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_bad_character' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_bool_cast' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_boolean_and' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_boolean_or' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_break' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_callable' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_caret' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_case' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_catch' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_character' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_class' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_class_c' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_clone' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_close_bracket' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_close_curly' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_close_square' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_close_tag' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_colon' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_comma' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_comment' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_concat_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_const' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_constant_encapsed_string' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_continue' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_curly_open' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_dec' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_declare' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_default' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_dir' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_div' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_div_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_dnumber' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_do' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_doc_comment' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_dollar' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_dollar_open_curly_braces' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_dot' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_double_arrow' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_double_cast' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_double_colon' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_double_quotes' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_echo' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_else' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_elseif' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_empty' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_encapsed_and_whitespace' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_end_heredoc' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_enddeclare' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_endfor' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_endforeach' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_endif' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_endswitch' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_endwhile' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_eval' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_exclamation_mark' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_exit' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_extends' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_file' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_final' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_finally' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_for' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_foreach' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_func_c' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_function' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_global' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_goto' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_gt' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_halt_compiler' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_if' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_implements' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_inc' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_include' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_include_once' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_includes' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_inline_html' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_instanceof' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_insteadof' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_int_cast' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_interface' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_is_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_is_greater_or_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_is_identical' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_is_not_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_is_not_identical' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_is_smaller_or_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_isset' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_line' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_list' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_lnumber' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_logical_and' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_logical_or' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_logical_xor' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_lt' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_method_c' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_minus' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_minus_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_mod_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_mul_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_mult' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_namespace' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_new' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_ns_c' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_ns_separator' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_num_string' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_object_cast' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_object_operator' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_open_bracket' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_open_curly' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_open_square' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_open_tag' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_open_tag_with_echo' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_or_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_paamayim_nekudotayim' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_percent' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_pipe' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_plus' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_plus_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_print' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_private' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_protected' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_public' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_question_mark' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_require' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_require_once' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_return' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_semicolon' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_sl' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_sl_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_sr' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_sr_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_start_heredoc' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_static' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_stream' => '/PHP_TokenStream-1.1.8/PHP/Token/Stream.php', - 'php_token_stream_cachingfactory' => '/PHP_TokenStream-1.1.8/PHP/Token/Stream/CachingFactory.php', - 'php_token_string' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_string_cast' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_string_varname' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_switch' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_throw' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_tilde' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_trait' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_trait_c' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_try' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_unset' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_unset_cast' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_use' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_var' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_variable' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_while' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_whitespace' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_xor_equal' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_token_yield' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_tokenwithscope' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'php_tokenwithscopeandvisibility' => '/PHP_TokenStream-1.1.8/PHP/Token.php', - 'phpunit_extensions_database_abstracttester' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/AbstractTester.php', - 'phpunit_extensions_database_constraint_datasetisequal' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.php', - 'phpunit_extensions_database_constraint_tableisequal' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Constraint/TableIsEqual.php', - 'phpunit_extensions_database_constraint_tablerowcount' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Constraint/TableRowCount.php', - 'phpunit_extensions_database_dataset_abstractdataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php', - 'phpunit_extensions_database_dataset_abstracttable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractTable.php', - 'phpunit_extensions_database_dataset_abstracttablemetadata' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.php', - 'phpunit_extensions_database_dataset_abstractxmldataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.php', - 'phpunit_extensions_database_dataset_compositedataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/CompositeDataSet.php', - 'phpunit_extensions_database_dataset_csvdataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/CsvDataSet.php', - 'phpunit_extensions_database_dataset_datasetfilter' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DataSetFilter.php', - 'phpunit_extensions_database_dataset_defaultdataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php', - 'phpunit_extensions_database_dataset_defaulttable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultTable.php', - 'phpunit_extensions_database_dataset_defaulttableiterator' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.php', - 'phpunit_extensions_database_dataset_defaulttablemetadata' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php', - 'phpunit_extensions_database_dataset_flatxmldataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.php', - 'phpunit_extensions_database_dataset_idataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/IDataSet.php', - 'phpunit_extensions_database_dataset_ipersistable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/IPersistable.php', - 'phpunit_extensions_database_dataset_ispec' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ISpec.php', - 'phpunit_extensions_database_dataset_itable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ITable.php', - 'phpunit_extensions_database_dataset_itableiterator' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ITableIterator.php', - 'phpunit_extensions_database_dataset_itablemetadata' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ITableMetaData.php', - 'phpunit_extensions_database_dataset_mysqlxmldataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/MysqlXmlDataSet.php', - 'phpunit_extensions_database_dataset_persistors_abstract' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Abstract.php', - 'phpunit_extensions_database_dataset_persistors_factory' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Factory.php', - 'phpunit_extensions_database_dataset_persistors_flatxml' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/FlatXml.php', - 'phpunit_extensions_database_dataset_persistors_mysqlxml' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/MysqlXml.php', - 'phpunit_extensions_database_dataset_persistors_xml' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Xml.php', - 'phpunit_extensions_database_dataset_persistors_yaml' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Yaml.php', - 'phpunit_extensions_database_dataset_querydataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/QueryDataSet.php', - 'phpunit_extensions_database_dataset_querytable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/QueryTable.php', - 'phpunit_extensions_database_dataset_replacementdataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ReplacementDataSet.php', - 'phpunit_extensions_database_dataset_replacementtable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ReplacementTable.php', - 'phpunit_extensions_database_dataset_replacementtableiterator' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ReplacementTableIterator.php', - 'phpunit_extensions_database_dataset_specs_csv' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Csv.php', - 'phpunit_extensions_database_dataset_specs_dbquery' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/DbQuery.php', - 'phpunit_extensions_database_dataset_specs_dbtable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/DbTable.php', - 'phpunit_extensions_database_dataset_specs_factory' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Factory.php', - 'phpunit_extensions_database_dataset_specs_flatxml' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/FlatXml.php', - 'phpunit_extensions_database_dataset_specs_ifactory' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/IFactory.php', - 'phpunit_extensions_database_dataset_specs_xml' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Xml.php', - 'phpunit_extensions_database_dataset_specs_yaml' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Yaml.php', - 'phpunit_extensions_database_dataset_tablefilter' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/TableFilter.php', - 'phpunit_extensions_database_dataset_tablemetadatafilter' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/TableMetaDataFilter.php', - 'phpunit_extensions_database_dataset_xmldataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/XmlDataSet.php', - 'phpunit_extensions_database_dataset_yamldataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/YamlDataSet.php', - 'phpunit_extensions_database_db_dataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/DataSet.php', - 'phpunit_extensions_database_db_defaultdatabaseconnection' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.php', - 'phpunit_extensions_database_db_filtereddataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/FilteredDataSet.php', - 'phpunit_extensions_database_db_idatabaseconnection' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/IDatabaseConnection.php', - 'phpunit_extensions_database_db_imetadata' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/IMetaData.php', - 'phpunit_extensions_database_db_metadata' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData.php', - 'phpunit_extensions_database_db_metadata_informationschema' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/InformationSchema.php', - 'phpunit_extensions_database_db_metadata_mysql' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/MySQL.php', - 'phpunit_extensions_database_db_metadata_oci' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/Oci.php', - 'phpunit_extensions_database_db_metadata_pgsql' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/PgSQL.php', - 'phpunit_extensions_database_db_metadata_sqlite' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/Sqlite.php', - 'phpunit_extensions_database_db_metadata_sqlsrv' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/SqlSrv.php', - 'phpunit_extensions_database_db_resultsettable' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/ResultSetTable.php', - 'phpunit_extensions_database_db_table' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/Table.php', - 'phpunit_extensions_database_db_tableiterator' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/TableIterator.php', - 'phpunit_extensions_database_db_tablemetadata' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/TableMetaData.php', - 'phpunit_extensions_database_defaulttester' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/DefaultTester.php', - 'phpunit_extensions_database_exception' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Exception.php', - 'phpunit_extensions_database_idatabaselistconsumer' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/IDatabaseListConsumer.php', - 'phpunit_extensions_database_itester' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/ITester.php', - 'phpunit_extensions_database_operation_composite' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Composite.php', - 'phpunit_extensions_database_operation_delete' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Delete.php', - 'phpunit_extensions_database_operation_deleteall' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/DeleteAll.php', - 'phpunit_extensions_database_operation_exception' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Exception.php', - 'phpunit_extensions_database_operation_factory' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Factory.php', - 'phpunit_extensions_database_operation_idatabaseoperation' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/IDatabaseOperation.php', - 'phpunit_extensions_database_operation_insert' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Insert.php', - 'phpunit_extensions_database_operation_null' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Null.php', - 'phpunit_extensions_database_operation_replace' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Replace.php', - 'phpunit_extensions_database_operation_rowbased' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/RowBased.php', - 'phpunit_extensions_database_operation_truncate' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Truncate.php', - 'phpunit_extensions_database_operation_update' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Update.php', - 'phpunit_extensions_database_testcase' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/TestCase.php', - 'phpunit_extensions_database_ui_command' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Command.php', - 'phpunit_extensions_database_ui_context' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Context.php', - 'phpunit_extensions_database_ui_imedium' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IMedium.php', - 'phpunit_extensions_database_ui_imediumprinter' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IMediumPrinter.php', - 'phpunit_extensions_database_ui_imode' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IMode.php', - 'phpunit_extensions_database_ui_imodefactory' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IModeFactory.php', - 'phpunit_extensions_database_ui_invalidmodeexception' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/InvalidModeException.php', - 'phpunit_extensions_database_ui_mediums_text' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Mediums/Text.php', - 'phpunit_extensions_database_ui_modefactory' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/ModeFactory.php', - 'phpunit_extensions_database_ui_modes_exportdataset' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Modes/ExportDataSet.php', - 'phpunit_extensions_database_ui_modes_exportdataset_arguments' => '/DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Modes/ExportDataSet/Arguments.php', - 'phpunit_extensions_grouptestsuite' => '/PHPUnit/Extensions/GroupTestSuite.php', - 'phpunit_extensions_phpttestcase' => '/PHPUnit/Extensions/PhptTestCase.php', - 'phpunit_extensions_phpttestcase_logger' => '/PHPUnit/Extensions/PhptTestCase/Logger.php', - 'phpunit_extensions_phpttestsuite' => '/PHPUnit/Extensions/PhptTestSuite.php', - 'phpunit_extensions_repeatedtest' => '/PHPUnit/Extensions/RepeatedTest.php', - 'phpunit_extensions_selenium2testcase' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase.php', - 'phpunit_extensions_selenium2testcase_command' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Command.php', - 'phpunit_extensions_selenium2testcase_commandsholder' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/CommandsHolder.php', - 'phpunit_extensions_selenium2testcase_driver' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Driver.php', - 'phpunit_extensions_selenium2testcase_element' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Element.php', - 'phpunit_extensions_selenium2testcase_element_accessor' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Element/Accessor.php', - 'phpunit_extensions_selenium2testcase_element_select' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Element/Select.php', - 'phpunit_extensions_selenium2testcase_elementcommand_attribute' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Attribute.php', - 'phpunit_extensions_selenium2testcase_elementcommand_click' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Click.php', - 'phpunit_extensions_selenium2testcase_elementcommand_css' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Css.php', - 'phpunit_extensions_selenium2testcase_elementcommand_equals' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Equals.php', - 'phpunit_extensions_selenium2testcase_elementcommand_genericaccessor' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/GenericAccessor.php', - 'phpunit_extensions_selenium2testcase_elementcommand_genericpost' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/GenericPost.php', - 'phpunit_extensions_selenium2testcase_elementcommand_value' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Value.php', - 'phpunit_extensions_selenium2testcase_elementcriteria' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCriteria.php', - 'phpunit_extensions_selenium2testcase_exception' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Exception.php', - 'phpunit_extensions_selenium2testcase_keys' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Keys.php', - 'phpunit_extensions_selenium2testcase_keysholder' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/KeysHolder.php', - 'phpunit_extensions_selenium2testcase_noseleniumexception' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/NoSeleniumException.php', - 'phpunit_extensions_selenium2testcase_response' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Response.php', - 'phpunit_extensions_selenium2testcase_screenshotlistener' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php', - 'phpunit_extensions_selenium2testcase_session' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session.php', - 'phpunit_extensions_selenium2testcase_session_cookie' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Cookie.php', - 'phpunit_extensions_selenium2testcase_session_cookie_builder' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Cookie/Builder.php', - 'phpunit_extensions_selenium2testcase_session_storage' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Storage.php', - 'phpunit_extensions_selenium2testcase_session_timeouts' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Timeouts.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_acceptalert' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/AcceptAlert.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_alerttext' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/AlertText.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_click' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Click.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_dismissalert' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/DismissAlert.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_frame' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Frame.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_genericaccessor' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/GenericAccessor.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_genericattribute' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/GenericAttribute.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_keys' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Keys.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_location' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Location.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_moveto' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/MoveTo.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_orientation' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Orientation.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_url' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Url.php', - 'phpunit_extensions_selenium2testcase_sessioncommand_window' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Window.php', - 'phpunit_extensions_selenium2testcase_sessionstrategy' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionStrategy.php', - 'phpunit_extensions_selenium2testcase_sessionstrategy_isolated' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionStrategy/Isolated.php', - 'phpunit_extensions_selenium2testcase_sessionstrategy_shared' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionStrategy/Shared.php', - 'phpunit_extensions_selenium2testcase_statecommand' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/StateCommand.php', - 'phpunit_extensions_selenium2testcase_url' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/URL.php', - 'phpunit_extensions_selenium2testcase_waituntil' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/WaitUntil.php', - 'phpunit_extensions_selenium2testcase_webdriverexception' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/WebDriverException.php', - 'phpunit_extensions_selenium2testcase_window' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Window.php', - 'phpunit_extensions_seleniumbrowsersuite' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumBrowserSuite.php', - 'phpunit_extensions_seleniumcommon_remotecoverage' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumCommon/RemoteCoverage.php', - 'phpunit_extensions_seleniumtestcase' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumTestCase.php', - 'phpunit_extensions_seleniumtestcase_driver' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumTestCase/Driver.php', - 'phpunit_extensions_seleniumtestsuite' => '/PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumTestSuite.php', - 'phpunit_extensions_testdecorator' => '/PHPUnit/Extensions/TestDecorator.php', - 'phpunit_extensions_ticketlistener' => '/PHPUnit/Extensions/TicketListener.php', - 'phpunit_framework_assert' => '/PHPUnit/Framework/Assert.php', - 'phpunit_framework_assertionfailederror' => '/PHPUnit/Framework/AssertionFailedError.php', - 'phpunit_framework_comparator' => '/PHPUnit/Framework/Comparator.php', - 'phpunit_framework_comparator_array' => '/PHPUnit/Framework/Comparator/Array.php', - 'phpunit_framework_comparator_domdocument' => '/PHPUnit/Framework/Comparator/DOMDocument.php', - 'phpunit_framework_comparator_double' => '/PHPUnit/Framework/Comparator/Double.php', - 'phpunit_framework_comparator_exception' => '/PHPUnit/Framework/Comparator/Exception.php', - 'phpunit_framework_comparator_mockobject' => '/PHPUnit/Framework/Comparator/MockObject.php', - 'phpunit_framework_comparator_numeric' => '/PHPUnit/Framework/Comparator/Numeric.php', - 'phpunit_framework_comparator_object' => '/PHPUnit/Framework/Comparator/Object.php', - 'phpunit_framework_comparator_resource' => '/PHPUnit/Framework/Comparator/Resource.php', - 'phpunit_framework_comparator_scalar' => '/PHPUnit/Framework/Comparator/Scalar.php', - 'phpunit_framework_comparator_splobjectstorage' => '/PHPUnit/Framework/Comparator/SplObjectStorage.php', - 'phpunit_framework_comparator_type' => '/PHPUnit/Framework/Comparator/Type.php', - 'phpunit_framework_comparatorfactory' => '/PHPUnit/Framework/ComparatorFactory.php', - 'phpunit_framework_comparisonfailure' => '/PHPUnit/Framework/ComparisonFailure.php', - 'phpunit_framework_constraint' => '/PHPUnit/Framework/Constraint.php', - 'phpunit_framework_constraint_and' => '/PHPUnit/Framework/Constraint/And.php', - 'phpunit_framework_constraint_arrayhaskey' => '/PHPUnit/Framework/Constraint/ArrayHasKey.php', - 'phpunit_framework_constraint_attribute' => '/PHPUnit/Framework/Constraint/Attribute.php', - 'phpunit_framework_constraint_callback' => '/PHPUnit/Framework/Constraint/Callback.php', - 'phpunit_framework_constraint_classhasattribute' => '/PHPUnit/Framework/Constraint/ClassHasAttribute.php', - 'phpunit_framework_constraint_classhasstaticattribute' => '/PHPUnit/Framework/Constraint/ClassHasStaticAttribute.php', - 'phpunit_framework_constraint_composite' => '/PHPUnit/Framework/Constraint/Composite.php', - 'phpunit_framework_constraint_count' => '/PHPUnit/Framework/Constraint/Count.php', - 'phpunit_framework_constraint_exception' => '/PHPUnit/Framework/Constraint/Exception.php', - 'phpunit_framework_constraint_exceptioncode' => '/PHPUnit/Framework/Constraint/ExceptionCode.php', - 'phpunit_framework_constraint_exceptionmessage' => '/PHPUnit/Framework/Constraint/ExceptionMessage.php', - 'phpunit_framework_constraint_fileexists' => '/PHPUnit/Framework/Constraint/FileExists.php', - 'phpunit_framework_constraint_greaterthan' => '/PHPUnit/Framework/Constraint/GreaterThan.php', - 'phpunit_framework_constraint_isanything' => '/PHPUnit/Framework/Constraint/IsAnything.php', - 'phpunit_framework_constraint_isempty' => '/PHPUnit/Framework/Constraint/IsEmpty.php', - 'phpunit_framework_constraint_isequal' => '/PHPUnit/Framework/Constraint/IsEqual.php', - 'phpunit_framework_constraint_isfalse' => '/PHPUnit/Framework/Constraint/IsFalse.php', - 'phpunit_framework_constraint_isidentical' => '/PHPUnit/Framework/Constraint/IsIdentical.php', - 'phpunit_framework_constraint_isinstanceof' => '/PHPUnit/Framework/Constraint/IsInstanceOf.php', - 'phpunit_framework_constraint_isjson' => '/PHPUnit/Framework/Constraint/IsJson.php', - 'phpunit_framework_constraint_isnull' => '/PHPUnit/Framework/Constraint/IsNull.php', - 'phpunit_framework_constraint_istrue' => '/PHPUnit/Framework/Constraint/IsTrue.php', - 'phpunit_framework_constraint_istype' => '/PHPUnit/Framework/Constraint/IsType.php', - 'phpunit_framework_constraint_jsonmatches' => '/PHPUnit/Framework/Constraint/JsonMatches.php', - 'phpunit_framework_constraint_jsonmatches_errormessageprovider' => '/PHPUnit/Framework/Constraint/JsonMatches/ErrorMessageProvider.php', - 'phpunit_framework_constraint_lessthan' => '/PHPUnit/Framework/Constraint/LessThan.php', - 'phpunit_framework_constraint_not' => '/PHPUnit/Framework/Constraint/Not.php', - 'phpunit_framework_constraint_objecthasattribute' => '/PHPUnit/Framework/Constraint/ObjectHasAttribute.php', - 'phpunit_framework_constraint_or' => '/PHPUnit/Framework/Constraint/Or.php', - 'phpunit_framework_constraint_pcrematch' => '/PHPUnit/Framework/Constraint/PCREMatch.php', - 'phpunit_framework_constraint_samesize' => '/PHPUnit/Framework/Constraint/SameSize.php', - 'phpunit_framework_constraint_stringcontains' => '/PHPUnit/Framework/Constraint/StringContains.php', - 'phpunit_framework_constraint_stringendswith' => '/PHPUnit/Framework/Constraint/StringEndsWith.php', - 'phpunit_framework_constraint_stringmatches' => '/PHPUnit/Framework/Constraint/StringMatches.php', - 'phpunit_framework_constraint_stringstartswith' => '/PHPUnit/Framework/Constraint/StringStartsWith.php', - 'phpunit_framework_constraint_traversablecontains' => '/PHPUnit/Framework/Constraint/TraversableContains.php', - 'phpunit_framework_constraint_traversablecontainsonly' => '/PHPUnit/Framework/Constraint/TraversableContainsOnly.php', - 'phpunit_framework_constraint_xor' => '/PHPUnit/Framework/Constraint/Xor.php', - 'phpunit_framework_error' => '/PHPUnit/Framework/Error.php', - 'phpunit_framework_error_deprecated' => '/PHPUnit/Framework/Error/Deprecated.php', - 'phpunit_framework_error_notice' => '/PHPUnit/Framework/Error/Notice.php', - 'phpunit_framework_error_warning' => '/PHPUnit/Framework/Error/Warning.php', - 'phpunit_framework_exception' => '/PHPUnit/Framework/Exception.php', - 'phpunit_framework_expectationfailedexception' => '/PHPUnit/Framework/ExpectationFailedException.php', - 'phpunit_framework_incompletetest' => '/PHPUnit/Framework/IncompleteTest.php', - 'phpunit_framework_incompletetesterror' => '/PHPUnit/Framework/IncompleteTestError.php', - 'phpunit_framework_mockobject_builder_identity' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Identity.php', - 'phpunit_framework_mockobject_builder_invocationmocker' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/InvocationMocker.php', - 'phpunit_framework_mockobject_builder_match' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Match.php', - 'phpunit_framework_mockobject_builder_methodnamematch' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php', - 'phpunit_framework_mockobject_builder_namespace' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Namespace.php', - 'phpunit_framework_mockobject_builder_parametersmatch' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/ParametersMatch.php', - 'phpunit_framework_mockobject_builder_stub' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Stub.php', - 'phpunit_framework_mockobject_generator' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator.php', - 'phpunit_framework_mockobject_invocation' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invocation.php', - 'phpunit_framework_mockobject_invocation_object' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invocation/Object.php', - 'phpunit_framework_mockobject_invocation_static' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invocation/Static.php', - 'phpunit_framework_mockobject_invocationmocker' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/InvocationMocker.php', - 'phpunit_framework_mockobject_invokable' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invokable.php', - 'phpunit_framework_mockobject_matcher' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher.php', - 'phpunit_framework_mockobject_matcher_anyinvokedcount' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.php', - 'phpunit_framework_mockobject_matcher_anyparameters' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/AnyParameters.php', - 'phpunit_framework_mockobject_matcher_invocation' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/Invocation.php', - 'phpunit_framework_mockobject_matcher_invokedatindex' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php', - 'phpunit_framework_mockobject_matcher_invokedatleastonce' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php', - 'phpunit_framework_mockobject_matcher_invokedcount' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedCount.php', - 'phpunit_framework_mockobject_matcher_invokedrecorder' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.php', - 'phpunit_framework_mockobject_matcher_methodname' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/MethodName.php', - 'phpunit_framework_mockobject_matcher_parameters' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/Parameters.php', - 'phpunit_framework_mockobject_matcher_statelessinvocation' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php', - 'phpunit_framework_mockobject_mockbuilder' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/MockBuilder.php', - 'phpunit_framework_mockobject_mockobject' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/MockObject.php', - 'phpunit_framework_mockobject_stub' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub.php', - 'phpunit_framework_mockobject_stub_consecutivecalls' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php', - 'phpunit_framework_mockobject_stub_exception' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/Exception.php', - 'phpunit_framework_mockobject_stub_matchercollection' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/MatcherCollection.php', - 'phpunit_framework_mockobject_stub_return' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/Return.php', - 'phpunit_framework_mockobject_stub_returnargument' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnArgument.php', - 'phpunit_framework_mockobject_stub_returncallback' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnCallback.php', - 'phpunit_framework_mockobject_stub_returnself' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnSelf.php', - 'phpunit_framework_mockobject_stub_returnvaluemap' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnValueMap.php', - 'phpunit_framework_mockobject_verifiable' => '/PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Verifiable.php', - 'phpunit_framework_outputerror' => '/PHPUnit/Framework/OutputError.php', - 'phpunit_framework_selfdescribing' => '/PHPUnit/Framework/SelfDescribing.php', - 'phpunit_framework_skippedtest' => '/PHPUnit/Framework/SkippedTest.php', - 'phpunit_framework_skippedtesterror' => '/PHPUnit/Framework/SkippedTestError.php', - 'phpunit_framework_skippedtestsuiteerror' => '/PHPUnit/Framework/SkippedTestSuiteError.php', - 'phpunit_framework_syntheticerror' => '/PHPUnit/Framework/SyntheticError.php', - 'phpunit_framework_test' => '/PHPUnit/Framework/Test.php', - 'phpunit_framework_testcase' => '/PHPUnit/Framework/TestCase.php', - 'phpunit_framework_testfailure' => '/PHPUnit/Framework/TestFailure.php', - 'phpunit_framework_testlistener' => '/PHPUnit/Framework/TestListener.php', - 'phpunit_framework_testresult' => '/PHPUnit/Framework/TestResult.php', - 'phpunit_framework_testsuite' => '/PHPUnit/Framework/TestSuite.php', - 'phpunit_framework_testsuite_dataprovider' => '/PHPUnit/Framework/TestSuite/DataProvider.php', - 'phpunit_framework_warning' => '/PHPUnit/Framework/Warning.php', - 'phpunit_runner_basetestrunner' => '/PHPUnit/Runner/BaseTestRunner.php', - 'phpunit_runner_standardtestsuiteloader' => '/PHPUnit/Runner/StandardTestSuiteLoader.php', - 'phpunit_runner_testsuiteloader' => '/PHPUnit/Runner/TestSuiteLoader.php', - 'phpunit_runner_version' => '/PHPUnit/Runner/Version.php', - 'phpunit_textui_command' => '/PHPUnit/TextUI/Command.php', - 'phpunit_textui_resultprinter' => '/PHPUnit/TextUI/ResultPrinter.php', - 'phpunit_textui_testrunner' => '/PHPUnit/TextUI/TestRunner.php', - 'phpunit_util_class' => '/PHPUnit/Util/Class.php', - 'phpunit_util_configuration' => '/PHPUnit/Util/Configuration.php', - 'phpunit_util_deprecatedfeature' => '/PHPUnit/Util/DeprecatedFeature.php', - 'phpunit_util_deprecatedfeature_logger' => '/PHPUnit/Util/DeprecatedFeature/Logger.php', - 'phpunit_util_diff' => '/PHPUnit/Util/Diff.php', - 'phpunit_util_errorhandler' => '/PHPUnit/Util/ErrorHandler.php', - 'phpunit_util_fileloader' => '/PHPUnit/Util/Fileloader.php', - 'phpunit_util_filesystem' => '/PHPUnit/Util/Filesystem.php', - 'phpunit_util_filter' => '/PHPUnit/Util/Filter.php', - 'phpunit_util_getopt' => '/PHPUnit/Util/Getopt.php', - 'phpunit_util_globalstate' => '/PHPUnit/Util/GlobalState.php', - 'phpunit_util_invalidargumenthelper' => '/PHPUnit/Util/InvalidArgumentHelper.php', - 'phpunit_util_log_json' => '/PHPUnit/Util/Log/JSON.php', - 'phpunit_util_log_junit' => '/PHPUnit/Util/Log/JUnit.php', - 'phpunit_util_log_tap' => '/PHPUnit/Util/Log/TAP.php', - 'phpunit_util_php' => '/PHPUnit/Util/PHP.php', - 'phpunit_util_php_default' => '/PHPUnit/Util/PHP/Default.php', - 'phpunit_util_php_windows' => '/PHPUnit/Util/PHP/Windows.php', - 'phpunit_util_printer' => '/PHPUnit/Util/Printer.php', - 'phpunit_util_string' => '/PHPUnit/Util/String.php', - 'phpunit_util_test' => '/PHPUnit/Util/Test.php', - 'phpunit_util_testdox_nameprettifier' => '/PHPUnit/Util/TestDox/NamePrettifier.php', - 'phpunit_util_testdox_resultprinter' => '/PHPUnit/Util/TestDox/ResultPrinter.php', - 'phpunit_util_testdox_resultprinter_html' => '/PHPUnit/Util/TestDox/ResultPrinter/HTML.php', - 'phpunit_util_testdox_resultprinter_text' => '/PHPUnit/Util/TestDox/ResultPrinter/Text.php', - 'phpunit_util_testsuiteiterator' => '/PHPUnit/Util/TestSuiteIterator.php', - 'phpunit_util_type' => '/PHPUnit/Util/Type.php', - 'phpunit_util_xml' => '/PHPUnit/Util/XML.php', - 'symfony\\component\\yaml\\dumper' => '/Yaml-2.2.0/Symfony/Component/Yaml/Dumper.php', - 'symfony\\component\\yaml\\escaper' => '/Yaml-2.2.0/Symfony/Component/Yaml/Escaper.php', - 'symfony\\component\\yaml\\exception\\dumpexception' => '/Yaml-2.2.0/Symfony/Component/Yaml/Exception/DumpException.php', - 'symfony\\component\\yaml\\exception\\exceptioninterface' => '/Yaml-2.2.0/Symfony/Component/Yaml/Exception/ExceptionInterface.php', - 'symfony\\component\\yaml\\exception\\parseexception' => '/Yaml-2.2.0/Symfony/Component/Yaml/Exception/ParseException.php', - 'symfony\\component\\yaml\\exception\\runtimeexception' => '/Yaml-2.2.0/Symfony/Component/Yaml/Exception/RuntimeException.php', - 'symfony\\component\\yaml\\inline' => '/Yaml-2.2.0/Symfony/Component/Yaml/Inline.php', - 'symfony\\component\\yaml\\parser' => '/Yaml-2.2.0/Symfony/Component/Yaml/Parser.php', - 'symfony\\component\\yaml\\tests\\a' => '/Yaml-2.2.0/Symfony/Component/Yaml/Tests/DumperTest.php', - 'symfony\\component\\yaml\\tests\\b' => '/Yaml-2.2.0/Symfony/Component/Yaml/Tests/ParserTest.php', - 'symfony\\component\\yaml\\tests\\dumpertest' => '/Yaml-2.2.0/Symfony/Component/Yaml/Tests/DumperTest.php', - 'symfony\\component\\yaml\\tests\\inlinetest' => '/Yaml-2.2.0/Symfony/Component/Yaml/Tests/InlineTest.php', - 'symfony\\component\\yaml\\tests\\parsertest' => '/Yaml-2.2.0/Symfony/Component/Yaml/Tests/ParserTest.php', - 'symfony\\component\\yaml\\tests\\yamltest' => '/Yaml-2.2.0/Symfony/Component/Yaml/Tests/YamlTest.php', - 'symfony\\component\\yaml\\unescaper' => '/Yaml-2.2.0/Symfony/Component/Yaml/Unescaper.php', - 'symfony\\component\\yaml\\yaml' => '/Yaml-2.2.0/Symfony/Component/Yaml/Yaml.php', - 'text_template' => '/Text_Template-1.1.4/Text/Template.php' - ); - } - - $class = strtolower($class); - - if (isset($classes[$class])) { - require 'phar://phpunit-3.7.24.phar' . $classes[$class]; - } - } -); - -Phar::mapPhar('phpunit-3.7.24.phar'); - -if ($GLOBALS['_SERVER']['SCRIPT_NAME'] != '-') { - PHPUnit_TextUI_Command::main(); -} - -__HALT_COMPILER(); ?> -™­phpunit-3.7.24.pharFile_Iterator-1.3.3/LICENSE /“R  þæ¶&File_Iterator-1.3.3/ChangeLog.markdownT/“RTÇŽÌX¶#File_Iterator-1.3.3/README.markdownF/“RF_h'¶%File_Iterator-1.3.3/File/Iterator.phpk/“RkÂM¶,File_Iterator-1.3.3/File/Iterator/Facade.php­/“R­žmɶ-File_Iterator-1.3.3/File/Iterator/Factory.phpC/“RCÏ=—ˆ¶*PHP_TokenStream-1.1.8/PHP/Token/Stream.php“=/“R“=©éJv¶9PHP_TokenStream-1.1.8/PHP/Token/Stream/CachingFactory.phpì /“Rì ÄÔ¯¶#PHP_TokenStream-1.1.8/PHP/Token.phpL[/“RL[Öâ¶PHP_TokenStream-1.1.8/LICENSE/“RÅQ)[¶(PHP_TokenStream-1.1.8/ChangeLog.markdown¢/“R¢ÈžÁ¶%PHP_TokenStream-1.1.8/README.markdowne/“ReXžsF¶ PHPUnit_MockObject-1.2.3/LICENSE/“RBÒ¶CPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invokable.php= /“R= °‹²¶SPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/wsdl_class.tpl.distµ/“RµŽ§¶WPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/unmocked_clone.tpl.distŸ/“RŸ8W}ض]PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/mocked_object_method.tpl.dist„/“R„ãbVæ¶TPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/wsdl_method.tpl.dist</“R<¾Ði‰¶]PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/mocked_static_method.tpl.dist‰/“R‰>¦K¶UPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/mocked_class.tpl.dist‚/“R‚Àb)¶UPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/mocked_clone.tpl.dist„/“R„œaT¶TPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator/trait_class.tpl.dist-/“R-˜1°,¶CPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Generator.php%i/“R%ipúp)¶LPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/MethodName.phpJ/“RJÔk¶TPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedAtLeastOnce.php7 /“R7 ‡äßQ¶QPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedRecorder.phpÓ/“RÓŠ?ïd¶OPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/AnyParameters.php® /“R® g‚Œ¾¶NPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedCount.phpz/“Rz³_F¶QPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/AnyInvokedCount.phpI /“RI ™çDH¶LPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/Parameters.php£/“R£¸¦¶LPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/Invocation.php/“Réan¶UPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/StatelessInvocation.php/“RtšÅ¶PPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher/InvokedAtIndex.php}/“R}£Ó骶EPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/MockBuilder.php‡/“R‡ q¶APHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Matcher.php´&/“R´&$q¶JPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/InvocationMocker.php/“Rfû¬¶KPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invocation/Static.phpF/“RF (ü™¶KPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invocation/Object.php - /“R - ­Ò¥‹¶EPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/Return.phpÇ /“RÇ #£àʶPPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/MatcherCollection.phpj /“Rj ÍôÙ_¶MPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnArgument.phpm /“Rm #D j¶IPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnSelf.php˜ /“R˜ pžWʶHPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/Exception.phpb /“Rb +«`¶OPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ConsecutiveCalls.php /“R ì®G—¶MPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnCallback.phpû /“Rû ’+­¶MPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub/ReturnValueMap.phpê /“Rê `ËY¸¶DPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Verifiable.php /“R |¶DPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Invocation.phpö /“Rö ²7ù°¶>PHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Stub.php] /“R] ¹…íǶQPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/ParametersMatch.phpi/“Ri’9¶GPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Match.phpx /“Rx h“þ¶RPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/InvocationMocker.phpÄ/“RÄ–*¬b¶KPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Namespace.phpŽ /“RŽ ÃG“¶QPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/MethodNameMatch.php /“R ·6»¶JPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Identity.phpý /“Rý ÊÚh_¶FPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/Builder/Stub.phpË /“RË 0üĶDPHPUnit_MockObject-1.2.3/PHPUnit/Framework/MockObject/MockObject.php¡/“R¡ǧü4¶+PHPUnit_MockObject-1.2.3/ChangeLog.markdownã/“RãU¬z¶PHPUnit_Selenium-1.3.1/LICENSE/“Rvç Þ¶?PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumTestSuite.phpD/“RDrF™¶?PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase.phpéA/“RéA­LT϶EPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumTestCase/Driver.phpR«/“RR«År°¶BPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumBrowserSuite.phpæ/“Ræ¤È3”¶>PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumTestCase.php¢–/“R¢–B Ãó¶RPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Css.php] /“R] _ç4@¶^PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/GenericAccessor.php] -/“R] -Édް¶UPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Equals.phpT /“RT ³g—›¶ZPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/GenericPost.phpK -/“RK -²û¬š¶TPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Value.phpƒ -/“Rƒ -¤º¶XPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Attribute.phph /“Rh (‡¿$¶TPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCommand/Click.php -/“R -´à&¶JPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/KeysHolder.php/“R)˪p¶PPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Element/Accessor.php¶/“R¶›!.¡¶NPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Element/Select.php0/“R0þO®¨¶GPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Command.php@ /“R@ [·ÞL¶IPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Exception.php× /“R× 2 -´c¶FPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Driver.php"/“R":0Üx¶LPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/StateCommand.phpk -/“Rk -›O©¶HPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Response.phpF /“RF ü y̶SPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/NoSeleniumException.php¹ /“R¹ -d}L¶RPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/WebDriverException.phpZ /“RZ -Àd°¶GPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session.php2,/“R2,ªI¶XPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionStrategy/Isolated.php† /“R† 6™¥‡¶VPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionStrategy/Shared.php</“R<NÕR¶FPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Window.phpC /“RC óê+¶CPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/URL.php/“RRrê¶DPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Keys.php=/“R=ž¢¶OPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Storage.php, /“R, é®Þ¶NPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Cookie.phpñ/“Rñ<9.D¶VPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Cookie/Builder.php/“RY¦n…¶PPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Session/Timeouts.phpM/“RMñ`â¶OPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionStrategy.php• /“R• R$³r¶OPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ElementCriteria.phpB /“RB xÄA\¶WPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Location.php¿ /“R¿ Èâ>•¶[PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/DismissAlert.php* -/“R* -漩/¶TPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Frame.phpª /“Rª ¶´Û¶^PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/GenericAccessor.phpH -/“RH -2ï µ¶RPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Url.php /“R ;¦JÛ¶XPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/AlertText.php7 /“R7 Hÿxs¶UPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Window.phpÐ -/“RÐ -Kaö¶SPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Keys.php/“R³ßF¶UPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/MoveTo.php„ /“R„ z–]¶_PHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/GenericAttribute.php“ -/“R“ -ì”â¶ZPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/AcceptAlert.php% -/“R% -OÎâ¶ZPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Orientation.phpÎ /“RÎ `Ö¸¶TPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/SessionCommand/Click.php¯ /“R¯ àɿ߶RPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/ScreenshotListener.php{/“R{6;ÁE¶GPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/Element.php½/“R½fFÄ:¶NPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/CommandsHolder.php¿/“R¿õ"Õ¶IPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/Selenium2TestCase/WaitUntil.phpx/“Rx §|†¶DPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumCommon/prepend.phpê -/“Rê -ª%Ù±¶KPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumCommon/RemoteCoverage.php>/“R>*dBʶMPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumCommon/phpunit_coverage.php¥ /“R¥ ow™¶CPHPUnit_Selenium-1.3.1/PHPUnit/Extensions/SeleniumCommon/append.php /“R ›·ú÷¶)PHPUnit_Selenium-1.3.1/ChangeLog.markdown/“Rª*Ån¶DbUnit-1.2.3/dbunit.batn/“Rnq{Oª¶DbUnit-1.2.3/LICENSE/“RÓ î ¶IDbUnit-1.2.3/PHPUnit/Extensions/Database/DB/DefaultDatabaseConnection.phpý/“Rý0ë¶5DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/Table.php /“R (ZjK¶9DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/IMetaData.php*/“R*æX¶=DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/TableIterator.php~/“R~Hê"ñ¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/DB/IDatabaseConnection.phpˆ/“Rˆ^p²¶7DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/DataSet.phpÑ/“RÑ?>–õ¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/FilteredDataSet.phpA /“RA Ê‚‚:¶JDbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/InformationSchema.phpÃ/“RÃdGT6¶<DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/Oci.phpJ/“RJ®×[¶>DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/PgSQL.phpv/“Rvyr¡-¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/Sqlite.php/“R³Û†&¶>DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/MySQL.phpÊ/“RÊ÷§­Æ¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData/SqlSrv.php™/“R™‡b“2¶=DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/TableMetaData.php /“R ÞYó%¶>DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/ResultSetTable.phpÝ /“RÝ žÎô -¶8DbUnit-1.2.3/PHPUnit/Extensions/Database/DB/MetaData.php±/“R±³„þʶ5DbUnit-1.2.3/PHPUnit/Extensions/Database/TestCase.php%/“R%ë×Ü=¶7DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Command.phpF /“RF ËìÌW¶7DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IMedium.phpM /“RM b£»Å¶MDbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Modes/ExportDataSet/Arguments.php/“R#_Ñü¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Modes/ExportDataSet.phpï/“Rï|àÍ ¶;DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/ModeFactory.php/“R?Š_"¶<DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Mediums/Text.php•/“R•|ªJÁ¶7DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/Context.php /“R Ñ«’¶DDbUnit-1.2.3/PHPUnit/Extensions/Database/UI/InvalidModeException.phpÀ /“RÀ LFi¶5DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IMode.php± -/“R± -¿W;¶>DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IMediumPrinter.php£ -/“R£ -{4J˶<DbUnit-1.2.3/PHPUnit/Extensions/Database/UI/IModeFactory.phpè -/“Rè -cg]9¶@DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Exception.php¾/“R¾ò¾h¶=DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Delete.php÷ /“R÷ …›¦~¶=DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Insert.phpÍ/“RÍÌ~Ìù¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/RowBased.php6/“R6~ -JN¶@DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/DeleteAll.php– /“R– n{¶=DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Update.php›/“R›ã3f€¶;DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Null.phpˆ -/“Rˆ -Õ˜MX¶IDbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/IDatabaseOperation.phpÇ /“RÇ >k´¶@DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Composite.phpƒ/“RƒöJ¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Truncate.php² /“R² ¦kJ­¶>DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Replace.phpQ/“RQÎçȶ>DbUnit-1.2.3/PHPUnit/Extensions/Database/Operation/Factory.php¬/“R¬šÝÙ¶6DbUnit-1.2.3/PHPUnit/Extensions/Database/Exception.phpþ /“Rþ àY?¤¶DDbUnit-1.2.3/PHPUnit/Extensions/Database/Constraint/TableIsEqual.phpX/“RX}¼¶FDbUnit-1.2.3/PHPUnit/Extensions/Database/Constraint/DataSetIsEqual.phpf/“RfáÁTu¶EDbUnit-1.2.3/PHPUnit/Extensions/Database/Constraint/TableRowCount.phpW /“RW wV±¶BDbUnit-1.2.3/PHPUnit/Extensions/Database/IDatabaseListConsumer.php5 -/“R5 -ê—§c¶ADbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/QueryDataSet.phpc/“Rc{É.G¶DDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/MysqlXmlDataSet.php#/“R#Ó^N¦¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/QueryTable.phpô/“Rô¾žÑG¶:DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ISpec.php} -/“R} -šííû¶HDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/TableMetaDataFilter.php/“RîkOͶGDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractXmlDataSet.phpÇ/“RÇ]Õ喝;DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ITable.php /“R }¬"¶ADbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultTable.phpx/“RxU—9œ¶MDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ReplacementTableIterator.php„/“R„V(ß ¶GDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ReplacementDataSet.phpT/“RT»øÅʶ=DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/IDataSet.phpÄ /“RÄ V€?¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultDataSet.php‹ /“R‹ óª¶EDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ReplacementTable.php/“R%Íï®¶BDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractTable.phpÊ/“RÊ4RçO¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ITableIterator.phpþ -/“Rþ -²’¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/CsvDataSet.phpÌ/“RÌc4]¶IDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultTableMetaData.php– /“R– î8`¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Yaml.php§ /“R§ ˆ"Šî¶>DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Xml.php¡ /“R¡ H%z}¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/IFactory.phpE -/“RE -Pº—¶>DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Csv.phpU/“RUhçB›¶BDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/DbTable.phpx/“Rx>ÜëжBDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/DbQuery.phpÓ/“RÓ4¶BDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/FlatXml.php» /“R» hë*¶BDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Specs/Factory.php³ /“R³ PúÙ»¶IDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DefaultTableIterator.phpŠ/“RŠù< ¶BDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/DataSetFilter.php -/“R -•”¸7¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/ITableMetaData.php, /“R, Înùû¶DDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractDataSet.php/“R¿ÙK¶?DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/XmlDataSet.php¸/“R¸þl •¶DDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Yaml.phpá/“Rárñ¤¹¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Xml.php -/“R -_ð¶HDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/MysqlXml.php¸/“R¸V÷?I¶HDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Abstract.phpç/“Rç;ÓŽ@¶GDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/FlatXml.php^/“R^m ×ã¶GDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/Persistors/Factory.phpÄ /“RÄ käV@¶ADbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/IPersistable.phpˆ -/“Rˆ -R®¼Î¶CDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/FlatXmlDataSet.phpJ/“RJÉ٠ζEDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/CompositeDataSet.php;/“R;|Qñù¶@DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/YamlDataSet.php÷/“R÷úc¶JDbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/AbstractTableMetaData.phpÜ/“Rܳ'nn¶@DbUnit-1.2.3/PHPUnit/Extensions/Database/DataSet/TableFilter.php°/“R°PÈ'¶;DbUnit-1.2.3/PHPUnit/Extensions/Database/AbstractTester.php/“R Ußé¶:DbUnit-1.2.3/PHPUnit/Extensions/Database/DefaultTester.php£ /“R£ ¹B»¶4DbUnit-1.2.3/PHPUnit/Extensions/Database/ITester.phpž/“RžÝ¿$¶DbUnit-1.2.3/ChangeLog.markdown /“R /¤]W¶DbUnit-1.2.3/dbunit.phpu/“Rudizt¶=DbUnit-1.2.3/Samples/BankAccountDB/BankAccountDBTestMySQL.phpò/“RòsãDÛ¶LDbUnit-1.2.3/Samples/BankAccountDB/_files/bank-account-after-new-account.xmlQ/“RQüÂ)¶IDbUnit-1.2.3/Samples/BankAccountDB/_files/bank-account-after-deposits.xml/“RCP$ƶLDbUnit-1.2.3/Samples/BankAccountDB/_files/bank-account-after-withdrawals.xml -/“R -':ݶ?DbUnit-1.2.3/Samples/BankAccountDB/_files/bank-account-seed.xml /“R ›Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/sfObjects.yml/“Rè<öGYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsNullsAndEmpties.yml«/“R«×>;¥¶<Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/sfTests.yml÷/“R÷U“¶>Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/sfCompact.ymlU /“RU Ó¯¶BYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsErrorTests.ymlq/“Rqtõür¶FYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/escapedCharacters.ymlõ/“Rõá*£Â¶MYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsSpecificationExamples.yml0¢/“R0¢,x`k¶BYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsBasicTests.ymlô/“RôçõXœ¶GYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsFlowCollections.ymlX/“RXZ{kì¶?Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/embededPhp.yml/“RZÀܶ?Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/sfComments.yml/“R@ÖÛï¶EYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsTypeTransfers.ymlä/“Rä€T -¯¶DYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsBlockMapping.yml—/“R—Œ¼õ¶CYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsAnchorAlias.yml[/“R[á5ÒR¶?Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/sfMergeKey.ymlJ/“RJ;:šQ¶IYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsDocumentSeparator.ymlú/“Rú%MC¶=Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/sfQuotes.ymlå/“Råˆì„¶:Yaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/index.yml8/“R8£ôܶEYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/YtsFoldedScalars.ymlz/“Rzګغ¶JYaml-2.2.0/Symfony/Component/Yaml/Tests/Fixtures/unindentedCollections.yml-/“R-Çè¶/Yaml-2.2.0/Symfony/Component/Yaml/composer.jsonÓ/“RÓæùßF¶,Yaml-2.2.0/Symfony/Component/Yaml/.gitignore#/“R#Ü0å¶)Yaml-2.2.0/Symfony/Component/Yaml/LICENSE)/“R)NmòQ¶,Yaml-2.2.0/Symfony/Component/Yaml/Dumper.php” /“R” 8¹n¶0Yaml-2.2.0/Symfony/Component/Yaml/autoloader.phpú/“RúçU2¾¶2Yaml-2.2.0/Symfony/Component/Yaml/phpunit.xml.dist3/“R3ø>[¶>Yaml-2.2.0/Symfony/Component/Yaml/Exception/ParseException.php9 /“R9 ^Ÿ[¶BYaml-2.2.0/Symfony/Component/Yaml/Exception/ExceptionInterface.phpÆ/“RÆî+­l¶@Yaml-2.2.0/Symfony/Component/Yaml/Exception/RuntimeException.phpð/“RðÏ|-¶=Yaml-2.2.0/Symfony/Component/Yaml/Exception/DumpException.phpÒ/“RÒؙ՚¶,Yaml-2.2.0/Symfony/Component/Yaml/Parser.phpX/“RXÞHñ?¶/Yaml-2.2.0/Symfony/Component/Yaml/Unescaper.php™/“R™аÂn¶+Yaml-2.2.0/Symfony/Component/Yaml/README.mda/“RaŸ•#X¶,Yaml-2.2.0/Symfony/Component/Yaml/Inline.php¨>/“R¨>ßhàâ¶-Yaml-2.2.0/Symfony/Component/Yaml/Escaper.phpi /“Ri á¼¶.Yaml-2.2.0/Symfony/Component/Yaml/CHANGELOG.md²/“R²XÁl¶!PHPUnit/Framework/TestFailure.phpŸ/“RŸy…x˶'PHPUnit/Framework/ComparatorFactory.phpI/“RIèØZ\¶+PHPUnit/Framework/SkippedTestSuiteError.php: -/“R: -õ±c¶PHPUnit/Framework/Assert.phpJe/“RJe$—z¶PHPUnit/Framework/TestCase.php·Ò/“R·Ò*õͶ&PHPUnit/Framework/Assert/Functions.php ú/“R úÆ­ì8¶)PHPUnit/Framework/Assert/Functions.php.inå/“Rådx˜û¶)PHPUnit/Framework/IncompleteTestError.php9 -/“R9 -—do¶!PHPUnit/Framework/OutputError.php -/“R -ŠCÐg¶PHPUnit/Framework/Exception.php¬ /“R¬ ¿/`?¶PHPUnit/Framework/Warning.php5/“R5ež¶'PHPUnit/Framework/ComparisonFailure.php­/“R­ëÄM¶&PHPUnit/Framework/SkippedTestError.php/ -/“R/ -aà,*¶3PHPUnit/Framework/Constraint/ObjectHasAttribute.phpL /“RL »;2¶*PHPUnit/Framework/Constraint/PCREMatch.phpJ/“RJeâm¶.PHPUnit/Framework/Constraint/ExceptionCode.phpy/“Ry)V»¶-PHPUnit/Framework/Constraint/IsInstanceOf.phpã/“Rãc§¨ý¶)PHPUnit/Framework/Constraint/SameSize.php /“R !n+‘¶(PHPUnit/Framework/Constraint/IsEqual.php–/“R–çZȶ'PHPUnit/Framework/Constraint/IsNull.php /“R 8®î$¶'PHPUnit/Framework/Constraint/IsJson.phpÂ/“RÂxVZP¶'PHPUnit/Framework/Constraint/IsTrue.php /“R ,+ÜͶ,PHPUnit/Framework/Constraint/ArrayHasKey.php™/“R™'ÑFÙ¶,PHPUnit/Framework/Constraint/IsIdentical.phpI/“RIÝ¢é¶*PHPUnit/Framework/Constraint/Exception.phpD/“RD-xDɶ$PHPUnit/Framework/Constraint/And.phpÎ/“RÎQ¨ï€¶8PHPUnit/Framework/Constraint/TraversableContainsOnly.phpI/“RIê L½¶)PHPUnit/Framework/Constraint/Callback.php{/“R{‚Q™c¶$PHPUnit/Framework/Constraint/Not.phpc/“Rc`ü:¶2PHPUnit/Framework/Constraint/ClassHasAttribute.phpC/“RC­¤ô“¶APHPUnit/Framework/Constraint/JsonMatches/ErrorMessageProvider.php›/“R›nY¤¶,PHPUnit/Framework/Constraint/GreaterThan.phpY /“RY c׆¶+PHPUnit/Framework/Constraint/IsAnything.php /“R ZèµM¶/PHPUnit/Framework/Constraint/StringContains.phpÂ/“RÂõÂdj¶4PHPUnit/Framework/Constraint/TraversableContains.php/“R­µ÷¶)PHPUnit/Framework/Constraint/LessThan.phpP /“RP >”–µ¶.PHPUnit/Framework/Constraint/StringMatches.php;/“R;$–n:¶*PHPUnit/Framework/Constraint/Composite.php/“RG$a|¶1PHPUnit/Framework/Constraint/ExceptionMessage.php[/“R[h¢9¶+PHPUnit/Framework/Constraint/FileExists.phpY/“RYCÅ”©¶*PHPUnit/Framework/Constraint/Attribute.php/“RÞ ¶#PHPUnit/Framework/Constraint/Or.php/“R¸Å+¶/PHPUnit/Framework/Constraint/StringEndsWith.phpg /“Rg qR ¥¶8PHPUnit/Framework/Constraint/ClassHasStaticAttribute.php)/“R)Òîi¶(PHPUnit/Framework/Constraint/IsFalse.php$ /“R$ c{ðR¶1PHPUnit/Framework/Constraint/StringStartsWith.phpV /“RV u/<¿¶,PHPUnit/Framework/Constraint/JsonMatches.php/“Rùª$¸¶(PHPUnit/Framework/Constraint/IsEmpty.phpj/“RjØ·Eò¶&PHPUnit/Framework/Constraint/Count.phpþ/“Rþï‡È)¶$PHPUnit/Framework/Constraint/Xor.phpy/“Ry%(í¶'PHPUnit/Framework/Constraint/IsType.phpÏ/“RÏÈZ-Ÿ¶ PHPUnit/Framework/Constraint.php‹/“R‹¶PHP_Timer-1.0.5/README.md9/“R9¿Å¶,PHP_CodeCoverage-1.2.12/PHP/CodeCoverage.php*Y/“R*Y0:*U¶GPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Util/InvalidArgumentHelper.phpW /“RW “Y½)¶:PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Driver/Xdebug.php¿ /“R¿ ¦ei¶1PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Util.phpË'/“RË'jý¼š¶6PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Exception.phpú /“Rú -u:¶3PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Driver.php¸ -/“R¸ -n …¶3PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Filter.phpí'/“Rí'[‘µí¶4PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Version.php< /“R< ¨ÏY¶8PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node.php*%/“R*%’B©ó¶=PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node/File.phpR/“RR\-¡Ç¶APHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node/Iterator.php/“Ru¾¶BPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Node/Directory.php#0/“R#03µ¶APHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer.phpˆ#/“Rˆ#^Qš¶FPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/File.phpQT/“RQT¯€0Ͷ]PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/coverage_bar.html.distŽ/“RŽ­¾¶cPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/img/glyphicons-halflings.pngÿ1/“Rÿ1ëV(F¶iPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/img/glyphicons-halflings-white.pngI"/“RI"¤‹€C¶ZPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/file_item.html.dist;/“R;rS¶ZPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/directory.html.dist˜/“R˜Àp¬W¶\PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/css/bootstrap.min.css’“/“R’“®ñak¶gPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/css/bootstrap-responsive.min.css©@/“R©@¢±÷T¶TPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/css/style.cssq/“Rq -¹*µ¶_PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/directory_item.html.dist /“R -“,—¶\PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/method_item.html.distX/“RX%ŽJ¶UPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/file.html.dist/“R´`Öâ¶ZPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/js/bootstrap.min.jsl{/“Rl{áôš¶VPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/js/html5shiv.jsH /“RH «Õß¶WPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/js/highcharts.jsåä/“Råä~K&¶WPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/js/jquery.min.jsÕi/“RÕi´v„¶ZPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Template/dashboard.html.dist /“R €·H¶KPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Directory.phpŽ/“RŽ[ »J¶KPHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML/Renderer/Dashboard.php¥/“R¥/MKU¶8PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/HTML.php/“RÀáz¥¶7PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/PHP.php{ /“R{ ð=Œ¶8PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Text.php6+/“R6+ 8R¶:PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Clover.phpÍ2/“RÍ2)†Ö¶;PHP_CodeCoverage-1.2.12/PHP/CodeCoverage/Report/Factory.php2/“R2Õö[î¶PHP_CodeCoverage-1.2.12/LICENSE/“R–õw!¶%Text_Template-1.1.4/Text/Template.phpµ/“RµW¹–y¶Text_Template-1.1.4/LICENSE/“RŒÐrȶ&Text_Template-1.1.4/ChangeLog.markdownŒ/“RŒœø‡÷¶#Text_Template-1.1.4/README.markdownF/“RF™Q¶File_Iterator - -Copyright (c) 2009-2012, Sebastian Bergmann . -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - * Neither the name of Sebastian Bergmann nor the names of his - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -File_Iterator 1.3 -================= - -This is the list of changes for the File_Iterator 1.3 release series. - -File_Iterator 1.3.3 -------------------- - -* No changes. - -File_Iterator 1.3.2 -------------------- - -* No changes. - -File_Iterator 1.3.1 -------------------- - -* Fixed infinite loop in `File_Iterator_Facade::getCommonPath()` for empty directories. - -File_Iterator 1.3.0 -------------------- - -* Added `File_Iterator_Facade` for the most common use case. -* Moved `File_Iterator_Factory::getFilesAsArray()` to `File_Iterator_Facade::getFilesAsArray()`. -* `File_Iterator_Factory` is no longer static. -File_Iterator -============= - -Installation ------------- - -File_Iterator should be installed using the [PEAR Installer](http://pear.php.net/). This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0. - -The PEAR channel (`pear.phpunit.de`) that is used to distribute File_Iterator needs to be registered with the local PEAR environment: - - sb@ubuntu ~ % pear channel-discover pear.phpunit.de - Adding Channel "pear.phpunit.de" succeeded - Discovery of channel "pear.phpunit.de" succeeded - -This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel: - - sb@vmware ~ % pear install phpunit/File_Iterator - downloading File_Iterator-1.1.1.tgz ... - Starting to download File_Iterator-1.1.1.tgz (3,173 bytes) - ....done: 3,173 bytes - install ok: channel://pear.phpunit.de/File_Iterator-1.1.1 - -After the installation you can find the File_Iterator source files inside your local PEAR directory; the path is usually `/usr/lib/php/File`. -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package File - * @author Sebastian Bergmann - * @copyright 2009-2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @since File available since Release 1.0.0 - */ - -/** - * FilterIterator implementation that filters files based on prefix(es) and/or - * suffix(es). Hidden files and files from hidden directories are also filtered. - * - * @author Sebastian Bergmann - * @copyright 2009-2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.3 - * @link http://github.com/sebastianbergmann/php-file-iterator/tree - * @since Class available since Release 1.0.0 - */ -class File_Iterator extends FilterIterator -{ - const PREFIX = 0; - const SUFFIX = 1; - - /** - * @var array - */ - protected $suffixes = array(); - - /** - * @var array - */ - protected $prefixes = array(); - - /** - * @var array - */ - protected $exclude = array(); - - /** - * @var string - */ - protected $basepath; - - /** - * @param Iterator $iterator - * @param array $suffixes - * @param array $prefixes - * @param array $exclude - * @param string $basepath - */ - public function __construct(Iterator $iterator, array $suffixes = array(), array $prefixes = array(), array $exclude = array(), $basepath = NULL) - { - $exclude = array_filter(array_map('realpath', $exclude)); - - if ($basepath !== NULL) { - $basepath = realpath($basepath); - } - - if ($basepath === FALSE) { - $basepath = NULL; - } else { - foreach ($exclude as &$_exclude) { - $_exclude = str_replace($basepath, '', $_exclude); - } - } - - $this->prefixes = $prefixes; - $this->suffixes = $suffixes; - $this->exclude = $exclude; - $this->basepath = $basepath; - - parent::__construct($iterator); - } - - /** - * @return boolean - */ - public function accept() - { - $current = $this->getInnerIterator()->current(); - $filename = $current->getFilename(); - $realpath = $current->getRealPath(); - - if ($this->basepath !== NULL) { - $realpath = str_replace($this->basepath, '', $realpath); - } - - // Filter files in hidden directories. - if (preg_match('=/\.[^/]*/=', $realpath)) { - return FALSE; - } - - return $this->acceptPath($realpath) && - $this->acceptPrefix($filename) && - $this->acceptSuffix($filename); - } - - /** - * @param string $path - * @return boolean - * @since Method available since Release 1.1.0 - */ - protected function acceptPath($path) - { - foreach ($this->exclude as $exclude) { - if (strpos($path, $exclude) === 0) { - return FALSE; - } - } - - return TRUE; - } - - /** - * @param string $filename - * @return boolean - * @since Method available since Release 1.1.0 - */ - protected function acceptPrefix($filename) - { - return $this->acceptSubString($filename, $this->prefixes, self::PREFIX); - } - - /** - * @param string $filename - * @return boolean - * @since Method available since Release 1.1.0 - */ - protected function acceptSuffix($filename) - { - return $this->acceptSubString($filename, $this->suffixes, self::SUFFIX); - } - - /** - * @param string $filename - * @param array $subString - * @param integer $type - * @return boolean - * @since Method available since Release 1.1.0 - */ - protected function acceptSubString($filename, array $subStrings, $type) - { - if (empty($subStrings)) { - return TRUE; - } - - $matched = FALSE; - - foreach ($subStrings as $string) { - if (($type == self::PREFIX && strpos($filename, $string) === 0) || - ($type == self::SUFFIX && - substr($filename, -1 * strlen($string)) == $string)) { - $matched = TRUE; - break; - } - } - - return $matched; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package File - * @author Sebastian Bergmann - * @copyright 2009-2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @since File available since Release 1.3.0 - */ - -/** - * Façade implementation that uses File_Iterator_Factory to create a - * File_Iterator that operates on an AppendIterator that contains an - * RecursiveDirectoryIterator for each given path. The list of unique - * files is returned as an array. - * - * @author Sebastian Bergmann - * @copyright 2009-2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.3 - * @link http://github.com/sebastianbergmann/php-file-iterator/tree - * @since Class available since Release 1.3.0 - */ -class File_Iterator_Facade -{ - /** - * @param array|string $paths - * @param array|string $suffixes - * @param array|string $prefixes - * @param array $exclude - * @param boolean $commonPath - * @return array - */ - public function getFilesAsArray($paths, $suffixes = '', $prefixes = '', array $exclude = array(), $commonPath = FALSE) - { - if (is_string($paths)) { - $paths = array($paths); - } - - $factory = new File_Iterator_Factory; - $iterator = $factory->getFileIterator( - $paths, $suffixes, $prefixes, $exclude - ); - - $files = array(); - - foreach ($iterator as $file) { - $file = $file->getRealPath(); - - if ($file) { - $files[] = $file; - } - } - - foreach ($paths as $path) { - if (is_file($path)) { - $files[] = realpath($path); - } - } - - $files = array_unique($files); - sort($files); - - if ($commonPath) { - return array( - 'commonPath' => $this->getCommonPath($files), - 'files' => $files - ); - } else { - return $files; - } - } - - /** - * Returns the common path of a set of files. - * - * @param array $files - * @return string - */ - protected function getCommonPath(array $files) - { - $count = count($files); - - if ($count == 0) { - return ''; - } - - if ($count == 1) { - return dirname($files[0]) . DIRECTORY_SEPARATOR; - } - - $_files = array(); - - foreach ($files as $file) { - $_files[] = $_fileParts = explode(DIRECTORY_SEPARATOR, $file); - - if (empty($_fileParts[0])) { - $_fileParts[0] = DIRECTORY_SEPARATOR; - } - } - - $common = ''; - $done = FALSE; - $j = 0; - $count--; - - while (!$done) { - for ($i = 0; $i < $count; $i++) { - if ($_files[$i][$j] != $_files[$i+1][$j]) { - $done = TRUE; - break; - } - } - - if (!$done) { - $common .= $_files[0][$j]; - - if ($j > 0) { - $common .= DIRECTORY_SEPARATOR; - } - } - - $j++; - } - - return DIRECTORY_SEPARATOR . $common; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package File - * @author Sebastian Bergmann - * @copyright 2009-2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @since File available since Release 1.1.0 - */ - -/** - * Factory Method implementation that creates a File_Iterator that operates on - * an AppendIterator that contains an RecursiveDirectoryIterator for each given - * path. - * - * @author Sebastian Bergmann - * @copyright 2009-2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.3 - * @link http://github.com/sebastianbergmann/php-file-iterator/tree - * @since Class available since Release 1.1.0 - */ -class File_Iterator_Factory -{ - /** - * @param array|string $paths - * @param array|string $suffixes - * @param array|string $prefixes - * @param array $exclude - * @return AppendIterator - */ - public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = array()) - { - if (is_string($paths)) { - $paths = array($paths); - } - - $_paths = array(); - - foreach ($paths as $path) { - if ($locals = glob($path, GLOB_ONLYDIR)) { - $_paths = array_merge($_paths, $locals); - } else { - $_paths[] = $path; - } - } - - $paths = $_paths; - unset($_paths); - - if (is_string($prefixes)) { - if ($prefixes != '') { - $prefixes = array($prefixes); - } else { - $prefixes = array(); - } - } - - if (is_string($suffixes)) { - if ($suffixes != '') { - $suffixes = array($suffixes); - } else { - $suffixes = array(); - } - } - - $iterator = new AppendIterator; - - foreach ($paths as $path) { - if (is_dir($path)) { - $iterator->append( - new File_Iterator( - new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($path) - ), - $suffixes, - $prefixes, - $exclude, - $path - ) - ); - } - } - - return $iterator; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHP_TokenStream - * @author Sebastian Bergmann - * @copyright 2009-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @since File available since Release 1.0.0 - */ - -/** - * A stream of PHP tokens. - * - * @author Sebastian Bergmann - * @copyright 2009-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.1.8 - * @link http://github.com/sebastianbergmann/php-token-stream/tree - * @since Class available since Release 1.0.0 - */ -class PHP_Token_Stream implements ArrayAccess, Countable, SeekableIterator -{ - /** - * @var array - */ - protected static $customTokens = array( - '(' => 'PHP_Token_OPEN_BRACKET', - ')' => 'PHP_Token_CLOSE_BRACKET', - '[' => 'PHP_Token_OPEN_SQUARE', - ']' => 'PHP_Token_CLOSE_SQUARE', - '{' => 'PHP_Token_OPEN_CURLY', - '}' => 'PHP_Token_CLOSE_CURLY', - ';' => 'PHP_Token_SEMICOLON', - '.' => 'PHP_Token_DOT', - ',' => 'PHP_Token_COMMA', - '=' => 'PHP_Token_EQUAL', - '<' => 'PHP_Token_LT', - '>' => 'PHP_Token_GT', - '+' => 'PHP_Token_PLUS', - '-' => 'PHP_Token_MINUS', - '*' => 'PHP_Token_MULT', - '/' => 'PHP_Token_DIV', - '?' => 'PHP_Token_QUESTION_MARK', - '!' => 'PHP_Token_EXCLAMATION_MARK', - ':' => 'PHP_Token_COLON', - '"' => 'PHP_Token_DOUBLE_QUOTES', - '@' => 'PHP_Token_AT', - '&' => 'PHP_Token_AMPERSAND', - '%' => 'PHP_Token_PERCENT', - '|' => 'PHP_Token_PIPE', - '$' => 'PHP_Token_DOLLAR', - '^' => 'PHP_Token_CARET', - '~' => 'PHP_Token_TILDE', - '`' => 'PHP_Token_BACKTICK' - ); - - /** - * @var string - */ - protected $filename; - - /** - * @var array - */ - protected $tokens = array(); - - /** - * @var integer - */ - protected $position = 0; - - /** - * @var array - */ - protected $linesOfCode = array('loc' => 0, 'cloc' => 0, 'ncloc' => 0); - - /** - * @var array - */ - protected $classes; - - /** - * @var array - */ - protected $functions; - - /** - * @var array - */ - protected $includes; - - /** - * @var array - */ - protected $interfaces; - - /** - * @var array - */ - protected $traits; - - /** - * Constructor. - * - * @param string $sourceCode - */ - public function __construct($sourceCode) - { - if (is_file($sourceCode)) { - $this->filename = $sourceCode; - $sourceCode = file_get_contents($sourceCode); - } - - $this->scan($sourceCode); - } - - /** - * Destructor. - */ - public function __destruct() - { - $this->tokens = array(); - } - - /** - * @return string - */ - public function __toString() - { - $buffer = ''; - - foreach ($this as $token) { - $buffer .= $token; - } - - return $buffer; - } - - /** - * @return string - * @since Method available since Release 1.1.0 - */ - public function getFilename() - { - return $this->filename; - } - - /** - * Scans the source for sequences of characters and converts them into a - * stream of tokens. - * - * @param string $sourceCode - */ - protected function scan($sourceCode) - { - $line = 1; - $tokens = token_get_all($sourceCode); - $numTokens = count($tokens); - - for ($i = 0; $i < $numTokens; ++$i) { - $token = $tokens[$i]; - unset($tokens[$i]); - - if (is_array($token)) { - $text = $token[1]; - $tokenClass = 'PHP_Token_' . substr(token_name($token[0]), 2); - } else { - $text = $token; - $tokenClass = self::$customTokens[$token]; - } - - $this->tokens[] = new $tokenClass($text, $line, $this, $i); - $lines = substr_count($text, "\n"); - $line += $lines; - - if ($tokenClass == 'PHP_Token_HALT_COMPILER') { - break; - } - - else if ($tokenClass == 'PHP_Token_COMMENT' || - $tokenClass == 'PHP_Token_DOC_COMMENT') { - $this->linesOfCode['cloc'] += $lines + 1; - } - } - - $this->linesOfCode['loc'] = substr_count($sourceCode, "\n"); - $this->linesOfCode['ncloc'] = $this->linesOfCode['loc'] - - $this->linesOfCode['cloc']; - } - - /** - * @return integer - */ - public function count() - { - return count($this->tokens); - } - - /** - * @return PHP_Token[] - */ - public function tokens() - { - return $this->tokens; - } - - /** - * @return array - */ - public function getClasses() - { - if ($this->classes !== NULL) { - return $this->classes; - } - - $this->parse(); - - return $this->classes; - } - - /** - * @return array - */ - public function getFunctions() - { - if ($this->functions !== NULL) { - return $this->functions; - } - - $this->parse(); - - return $this->functions; - } - - /** - * @return array - */ - public function getInterfaces() - { - if ($this->interfaces !== NULL) { - return $this->interfaces; - } - - $this->parse(); - - return $this->interfaces; - } - - /** - * @return array - * @since Method available since Release 1.1.0 - */ - public function getTraits() - { - if ($this->traits !== NULL) { - return $this->traits; - } - - $this->parse(); - - return $this->traits; - } - - /** - * Gets the names of all files that have been included - * using include(), include_once(), require() or require_once(). - * - * Parameter $categorize set to TRUE causing this function to return a - * multi-dimensional array with categories in the keys of the first dimension - * and constants and their values in the second dimension. - * - * Parameter $category allow to filter following specific inclusion type - * - * @param bool $categorize OPTIONAL - * @param string $category OPTIONAL Either 'require_once', 'require', - * 'include_once', 'include'. - * @return array - * @since Method available since Release 1.1.0 - */ - public function getIncludes($categorize = FALSE, $category = NULL) - { - if ($this->includes === NULL) { - $this->includes = array( - 'require_once' => array(), - 'require' => array(), - 'include_once' => array(), - 'include' => array() - ); - - foreach ($this->tokens as $token) { - switch (get_class($token)) { - case 'PHP_Token_REQUIRE_ONCE': - case 'PHP_Token_REQUIRE': - case 'PHP_Token_INCLUDE_ONCE': - case 'PHP_Token_INCLUDE': { - $this->includes[$token->getType()][] = $token->getName(); - } - break; - } - } - } - - if (isset($this->includes[$category])) { - $includes = $this->includes[$category]; - } - - else if ($categorize === FALSE) { - $includes = array_merge( - $this->includes['require_once'], - $this->includes['require'], - $this->includes['include_once'], - $this->includes['include'] - ); - } else { - $includes = $this->includes; - } - - return $includes; - } - - protected function parse() - { - $this->interfaces = array(); - $this->classes = array(); - $this->traits = array(); - $this->functions = array(); - $class = FALSE; - $classEndLine = FALSE; - $trait = FALSE; - $traitEndLine = FALSE; - $interface = FALSE; - $interfaceEndLine = FALSE; - - foreach ($this->tokens as $token) { - switch (get_class($token)) { - case 'PHP_Token_HALT_COMPILER': { - return; - } - break; - - case 'PHP_Token_INTERFACE': { - $interface = $token->getName(); - $interfaceEndLine = $token->getEndLine(); - - $this->interfaces[$interface] = array( - 'methods' => array(), - 'parent' => $token->getParent(), - 'keywords' => $token->getKeywords(), - 'docblock' => $token->getDocblock(), - 'startLine' => $token->getLine(), - 'endLine' => $interfaceEndLine, - 'package' => $token->getPackage(), - 'file' => $this->filename - ); - } - break; - - case 'PHP_Token_CLASS': - case 'PHP_Token_TRAIT': { - $tmp = array( - 'methods' => array(), - 'parent' => $token->getParent(), - 'interfaces'=> $token->getInterfaces(), - 'keywords' => $token->getKeywords(), - 'docblock' => $token->getDocblock(), - 'startLine' => $token->getLine(), - 'endLine' => $token->getEndLine(), - 'package' => $token->getPackage(), - 'file' => $this->filename - ); - - if ($token instanceof PHP_Token_CLASS) { - $class = $token->getName(); - $classEndLine = $token->getEndLine(); - $this->classes[$class] = $tmp; - } else { - $trait = $token->getName(); - $traitEndLine = $token->getEndLine(); - $this->traits[$trait] = $tmp; - } - } - break; - - case 'PHP_Token_FUNCTION': { - $name = $token->getName(); - $tmp = array( - 'docblock' => $token->getDocblock(), - 'keywords' => $token->getKeywords(), - 'visibility'=> $token->getVisibility(), - 'signature' => $token->getSignature(), - 'startLine' => $token->getLine(), - 'endLine' => $token->getEndLine(), - 'ccn' => $token->getCCN(), - 'file' => $this->filename - ); - - if ($class === FALSE && - $trait === FALSE && - $interface === FALSE) { - $this->functions[$name] = $tmp; - } - - else if ($class !== FALSE) { - $this->classes[$class]['methods'][$name] = $tmp; - } - - else if ($trait !== FALSE) { - $this->traits[$trait]['methods'][$name] = $tmp; - } - - else { - $this->interfaces[$interface]['methods'][$name] = $tmp; - } - } - break; - - case 'PHP_Token_CLOSE_CURLY': { - if ($classEndLine !== FALSE && - $classEndLine == $token->getLine()) { - $class = FALSE; - $classEndLine = FALSE; - } - - else if ($traitEndLine !== FALSE && - $traitEndLine == $token->getLine()) { - $trait = FALSE; - $traitEndLine = FALSE; - } - - else if ($interfaceEndLine !== FALSE && - $interfaceEndLine == $token->getLine()) { - $interface = FALSE; - $interfaceEndLine = FALSE; - } - } - break; - } - } - } - - /** - * @return array - */ - public function getLinesOfCode() - { - return $this->linesOfCode; - } - - /** - */ - public function rewind() - { - $this->position = 0; - } - - /** - * @return boolean - */ - public function valid() - { - return isset($this->tokens[$this->position]); - } - - /** - * @return integer - */ - public function key() - { - return $this->position; - } - - /** - * @return PHP_Token - */ - public function current() - { - return $this->tokens[$this->position]; - } - - /** - */ - public function next() - { - $this->position++; - } - - /** - * @param mixed $offset - */ - public function offsetExists($offset) - { - return isset($this->tokens[$offset]); - } - - /** - * @param mixed $offset - * @return mixed - */ - public function offsetGet($offset) - { - return $this->tokens[$offset]; - } - - /** - * @param mixed $offset - * @param mixed $value - */ - public function offsetSet($offset, $value) - { - $this->tokens[$offset] = $value; - } - - /** - * @param mixed $offset - */ - public function offsetUnset($offset) - { - unset($this->tokens[$offset]); - } - - /** - * Seek to an absolute position. - * - * @param integer $position - * @throws OutOfBoundsException - */ - public function seek($position) - { - $this->position = $position; - - if (!$this->valid()) { - throw new OutOfBoundsException('Invalid seek position'); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHP_TokenStream - * @author Sebastian Bergmann - * @copyright 2009-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @since File available since Release 1.0.0 - */ - -/** - * A caching factory for token stream objects. - * - * @author Sebastian Bergmann - * @copyright 2009-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.1.8 - * @link http://github.com/sebastianbergmann/php-token-stream/tree - * @since Class available since Release 1.0.0 - */ -class PHP_Token_Stream_CachingFactory -{ - /** - * @var array - */ - protected static $cache = array(); - - /** - * @param string $filename - * @return PHP_Token_Stream - */ - public static function get($filename) - { - if (!isset(self::$cache[$filename])) { - self::$cache[$filename] = new PHP_Token_Stream($filename); - } - - return self::$cache[$filename]; - } - - /** - * @param string $filename - */ - public static function clear($filename = NULL) - { - if (is_string($filename)) { - unset(self::$cache[$filename]); - } else { - self::$cache = array(); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHP_TokenStream - * @author Sebastian Bergmann - * @copyright 2009-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @since File available since Release 1.0.0 - */ - -/** - * A PHP token. - * - * @author Sebastian Bergmann - * @copyright 2009-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.1.8 - * @link http://github.com/sebastianbergmann/php-token-stream/tree - * @since Class available since Release 1.0.0 - */ -abstract class PHP_Token -{ - /** - * @var string - */ - protected $text; - - /** - * @var integer - */ - protected $line; - - /** - * @var PHP_Token_Stream - */ - protected $tokenStream; - - /** - * @var integer - */ - protected $id; - - /** - * Constructor. - * - * @param string $text - * @param integer $line - * @param PHP_Token_Stream $tokenStream - * @param integer $id - */ - public function __construct($text, $line, PHP_Token_Stream $tokenStream, $id) - { - $this->text = $text; - $this->line = $line; - $this->tokenStream = $tokenStream; - $this->id = $id; - } - - /** - * @return string - */ - public function __toString() - { - return $this->text; - } - - /** - * @return integer - */ - public function getLine() - { - return $this->line; - } -} - -abstract class PHP_TokenWithScope extends PHP_Token -{ - protected $endTokenId; - - /** - * Get the docblock for this token - * - * This method will fetch the docblock belonging to the current token. The - * docblock must be placed on the line directly above the token to be - * recognized. - * - * @return string|null Returns the docblock as a string if found - */ - public function getDocblock() - { - $tokens = $this->tokenStream->tokens(); - $currentLineNumber = $tokens[$this->id]->getLine(); - $prevLineNumber = $currentLineNumber - 1; - - for ($i = $this->id - 1; $i; $i--) { - if (!isset($tokens[$i])) { - return; - } - - if ($tokens[$i] instanceof PHP_Token_FUNCTION || - $tokens[$i] instanceof PHP_Token_CLASS || - $tokens[$i] instanceof PHP_Token_TRAIT) { - // Some other trait, class or function, no docblock can be - // used for the current token - break; - } - - $line = $tokens[$i]->getLine(); - - if ($line == $currentLineNumber || - ($line == $prevLineNumber && - $tokens[$i] instanceof PHP_Token_WHITESPACE)) { - continue; - } - - if ($line < $currentLineNumber && - !$tokens[$i] instanceof PHP_Token_DOC_COMMENT) { - break; - } - - return (string)$tokens[$i]; - } - } - - public function getEndTokenId() - { - $block = 0; - $i = $this->id; - $tokens = $this->tokenStream->tokens(); - - while ($this->endTokenId === NULL && isset($tokens[$i])) { - if ($tokens[$i] instanceof PHP_Token_OPEN_CURLY || - $tokens[$i] instanceof PHP_Token_CURLY_OPEN) { - $block++; - } - - else if ($tokens[$i] instanceof PHP_Token_CLOSE_CURLY) { - $block--; - - if ($block === 0) { - $this->endTokenId = $i; - } - } - - else if (($this instanceof PHP_Token_FUNCTION || - $this instanceof PHP_Token_NAMESPACE) && - $tokens[$i] instanceof PHP_Token_SEMICOLON) { - if ($block === 0) { - $this->endTokenId = $i; - } - } - - $i++; - } - - if ($this->endTokenId === NULL) { - $this->endTokenId = $this->id; - } - - return $this->endTokenId; - } - - public function getEndLine() - { - return $this->tokenStream[$this->getEndTokenId()]->getLine(); - } - -} - -abstract class PHP_TokenWithScopeAndVisibility extends PHP_TokenWithScope { - - public function getVisibility() - { - $tokens = $this->tokenStream->tokens(); - - for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { - if (isset($tokens[$i]) && - ($tokens[$i] instanceof PHP_Token_PRIVATE || - $tokens[$i] instanceof PHP_Token_PROTECTED || - $tokens[$i] instanceof PHP_Token_PUBLIC)) { - return strtolower( - str_replace('PHP_Token_', '', get_class($tokens[$i])) - ); - } - if (isset($tokens[$i]) && - !($tokens[$i] instanceof PHP_Token_STATIC || - $tokens[$i] instanceof PHP_Token_FINAL || - $tokens[$i] instanceof PHP_Token_ABSTRACT)) { - // no keywords; stop visibility search - break; - } - } - } - - public function getKeywords() - { - $keywords = array(); - $tokens = $this->tokenStream->tokens(); - - for ($i = $this->id - 2; $i > $this->id - 7; $i -= 2) { - if (isset($tokens[$i]) && - ($tokens[$i] instanceof PHP_Token_PRIVATE || - $tokens[$i] instanceof PHP_Token_PROTECTED || - $tokens[$i] instanceof PHP_Token_PUBLIC)) { - continue; - } - - if (isset($tokens[$i]) && - ($tokens[$i] instanceof PHP_Token_STATIC || - $tokens[$i] instanceof PHP_Token_FINAL || - $tokens[$i] instanceof PHP_Token_ABSTRACT)) { - $keywords[] = strtolower( - str_replace('PHP_Token_', '', get_class($tokens[$i])) - ); - } - } - - return implode(',', $keywords); - } - -} - -abstract class PHP_Token_Includes extends PHP_Token -{ - protected $name; - protected $type; - - public function getName() - { - if ($this->name !== NULL) { - return $this->name; - } - - $tokens = $this->tokenStream->tokens(); - - if ($tokens[$this->id+2] instanceof PHP_Token_CONSTANT_ENCAPSED_STRING) { - $this->name = trim($tokens[$this->id+2], "'\""); - $this->type = strtolower( - str_replace('PHP_Token_', '', get_class($tokens[$this->id])) - ); - } - - return $this->name; - } - - public function getType() - { - $this->getName(); - return $this->type; - } -} - -class PHP_Token_REQUIRE_ONCE extends PHP_Token_Includes {} -class PHP_Token_REQUIRE extends PHP_Token_Includes {} -class PHP_Token_EVAL extends PHP_Token {} -class PHP_Token_INCLUDE_ONCE extends PHP_Token_Includes {} -class PHP_Token_INCLUDE extends PHP_Token_Includes {} -class PHP_Token_LOGICAL_OR extends PHP_Token {} -class PHP_Token_LOGICAL_XOR extends PHP_Token {} -class PHP_Token_LOGICAL_AND extends PHP_Token {} -class PHP_Token_PRINT extends PHP_Token {} -class PHP_Token_SR_EQUAL extends PHP_Token {} -class PHP_Token_SL_EQUAL extends PHP_Token {} -class PHP_Token_XOR_EQUAL extends PHP_Token {} -class PHP_Token_OR_EQUAL extends PHP_Token {} -class PHP_Token_AND_EQUAL extends PHP_Token {} -class PHP_Token_MOD_EQUAL extends PHP_Token {} -class PHP_Token_CONCAT_EQUAL extends PHP_Token {} -class PHP_Token_DIV_EQUAL extends PHP_Token {} -class PHP_Token_MUL_EQUAL extends PHP_Token {} -class PHP_Token_MINUS_EQUAL extends PHP_Token {} -class PHP_Token_PLUS_EQUAL extends PHP_Token {} -class PHP_Token_BOOLEAN_OR extends PHP_Token {} -class PHP_Token_BOOLEAN_AND extends PHP_Token {} -class PHP_Token_IS_NOT_IDENTICAL extends PHP_Token {} -class PHP_Token_IS_IDENTICAL extends PHP_Token {} -class PHP_Token_IS_NOT_EQUAL extends PHP_Token {} -class PHP_Token_IS_EQUAL extends PHP_Token {} -class PHP_Token_IS_GREATER_OR_EQUAL extends PHP_Token {} -class PHP_Token_IS_SMALLER_OR_EQUAL extends PHP_Token {} -class PHP_Token_SR extends PHP_Token {} -class PHP_Token_SL extends PHP_Token {} -class PHP_Token_INSTANCEOF extends PHP_Token {} -class PHP_Token_UNSET_CAST extends PHP_Token {} -class PHP_Token_BOOL_CAST extends PHP_Token {} -class PHP_Token_OBJECT_CAST extends PHP_Token {} -class PHP_Token_ARRAY_CAST extends PHP_Token {} -class PHP_Token_STRING_CAST extends PHP_Token {} -class PHP_Token_DOUBLE_CAST extends PHP_Token {} -class PHP_Token_INT_CAST extends PHP_Token {} -class PHP_Token_DEC extends PHP_Token {} -class PHP_Token_INC extends PHP_Token {} -class PHP_Token_CLONE extends PHP_Token {} -class PHP_Token_NEW extends PHP_Token {} -class PHP_Token_EXIT extends PHP_Token {} -class PHP_Token_IF extends PHP_Token {} -class PHP_Token_ELSEIF extends PHP_Token {} -class PHP_Token_ELSE extends PHP_Token {} -class PHP_Token_ENDIF extends PHP_Token {} -class PHP_Token_LNUMBER extends PHP_Token {} -class PHP_Token_DNUMBER extends PHP_Token {} -class PHP_Token_STRING extends PHP_Token {} -class PHP_Token_STRING_VARNAME extends PHP_Token {} -class PHP_Token_VARIABLE extends PHP_Token {} -class PHP_Token_NUM_STRING extends PHP_Token {} -class PHP_Token_INLINE_HTML extends PHP_Token {} -class PHP_Token_CHARACTER extends PHP_Token {} -class PHP_Token_BAD_CHARACTER extends PHP_Token {} -class PHP_Token_ENCAPSED_AND_WHITESPACE extends PHP_Token {} -class PHP_Token_CONSTANT_ENCAPSED_STRING extends PHP_Token {} -class PHP_Token_ECHO extends PHP_Token {} -class PHP_Token_DO extends PHP_Token {} -class PHP_Token_WHILE extends PHP_Token {} -class PHP_Token_ENDWHILE extends PHP_Token {} -class PHP_Token_FOR extends PHP_Token {} -class PHP_Token_ENDFOR extends PHP_Token {} -class PHP_Token_FOREACH extends PHP_Token {} -class PHP_Token_ENDFOREACH extends PHP_Token {} -class PHP_Token_DECLARE extends PHP_Token {} -class PHP_Token_ENDDECLARE extends PHP_Token {} -class PHP_Token_AS extends PHP_Token {} -class PHP_Token_SWITCH extends PHP_Token {} -class PHP_Token_ENDSWITCH extends PHP_Token {} -class PHP_Token_CASE extends PHP_Token {} -class PHP_Token_DEFAULT extends PHP_Token {} -class PHP_Token_BREAK extends PHP_Token {} -class PHP_Token_CONTINUE extends PHP_Token {} -class PHP_Token_GOTO extends PHP_Token {} -class PHP_Token_CALLABLE extends PHP_Token {} -class PHP_Token_INSTEADOF extends PHP_Token {} - -class PHP_Token_FUNCTION extends PHP_TokenWithScopeAndVisibility -{ - protected $arguments; - protected $ccn; - protected $name; - protected $signature; - - public function getArguments() - { - if ($this->arguments !== NULL) { - return $this->arguments; - } - - $this->arguments = array(); - $i = $this->id + 2; - $tokens = $this->tokenStream->tokens(); - $typeHint = NULL; - - while (!$tokens[$i] instanceof PHP_Token_CLOSE_BRACKET) { - if ($tokens[$i] instanceof PHP_Token_STRING) { - $typeHint = (string)$tokens[$i]; - } - - else if ($tokens[$i] instanceof PHP_Token_VARIABLE) { - $this->arguments[(string)$tokens[$i]] = $typeHint; - $typeHint = NULL; - } - - $i++; - } - - return $this->arguments; - } - - public function getName() - { - if ($this->name !== NULL) { - return $this->name; - } - - $tokens = $this->tokenStream->tokens(); - - for ($i = $this->id + 1; $i < count($tokens); $i++) { - if ($tokens[$i] instanceof PHP_Token_STRING) { - $this->name = (string)$tokens[$i]; - break; - } - - else if ($tokens[$i] instanceof PHP_Token_AMPERSAND && - $tokens[$i+1] instanceof PHP_Token_STRING) { - $this->name = (string)$tokens[$i+1]; - break; - } - - else if ($tokens[$i] instanceof PHP_Token_OPEN_BRACKET) { - $this->name = 'anonymous function'; - break; - } - } - - if ($this->name != 'anonymous function') { - for ($i = $this->id; $i; --$i) { - if ($tokens[$i] instanceof PHP_Token_NAMESPACE) { - $this->name = $tokens[$i]->getName() . '\\' . $this->name; - break; - } - - if ($tokens[$i] instanceof PHP_Token_INTERFACE) { - break; - } - } - } - - return $this->name; - } - - public function getCCN() - { - if ($this->ccn !== NULL) { - return $this->ccn; - } - - $this->ccn = 1; - $end = $this->getEndTokenId(); - $tokens = $this->tokenStream->tokens(); - - for ($i = $this->id; $i <= $end; $i++) { - switch (get_class($tokens[$i])) { - case 'PHP_Token_IF': - case 'PHP_Token_ELSEIF': - case 'PHP_Token_FOR': - case 'PHP_Token_FOREACH': - case 'PHP_Token_WHILE': - case 'PHP_Token_CASE': - case 'PHP_Token_CATCH': - case 'PHP_Token_BOOLEAN_AND': - case 'PHP_Token_LOGICAL_AND': - case 'PHP_Token_BOOLEAN_OR': - case 'PHP_Token_LOGICAL_OR': - case 'PHP_Token_QUESTION_MARK': { - $this->ccn++; - } - break; - } - } - - return $this->ccn; - } - - public function getSignature() - { - if ($this->signature !== NULL) { - return $this->signature; - } - - if ($this->getName() == 'anonymous function') { - $this->signature = 'anonymous function'; - $i = $this->id + 1; - } else { - $this->signature = ''; - $i = $this->id + 2; - } - - $tokens = $this->tokenStream->tokens(); - - while (isset($tokens[$i]) && - !$tokens[$i] instanceof PHP_Token_OPEN_CURLY && - !$tokens[$i] instanceof PHP_Token_SEMICOLON) { - $this->signature .= $tokens[$i++]; - } - - $this->signature = trim($this->signature); - - return $this->signature; - } -} - -class PHP_Token_CONST extends PHP_Token {} -class PHP_Token_RETURN extends PHP_Token {} -class PHP_Token_YIELD extends PHP_Token {} -class PHP_Token_TRY extends PHP_Token {} -class PHP_Token_CATCH extends PHP_Token {} -class PHP_Token_FINALLY extends PHP_Token {} -class PHP_Token_THROW extends PHP_Token {} -class PHP_Token_USE extends PHP_Token {} -class PHP_Token_GLOBAL extends PHP_Token {} -class PHP_Token_PUBLIC extends PHP_Token {} -class PHP_Token_PROTECTED extends PHP_Token {} -class PHP_Token_PRIVATE extends PHP_Token {} -class PHP_Token_FINAL extends PHP_Token {} -class PHP_Token_ABSTRACT extends PHP_Token {} -class PHP_Token_STATIC extends PHP_Token {} -class PHP_Token_VAR extends PHP_Token {} -class PHP_Token_UNSET extends PHP_Token {} -class PHP_Token_ISSET extends PHP_Token {} -class PHP_Token_EMPTY extends PHP_Token {} -class PHP_Token_HALT_COMPILER extends PHP_Token {} - -class PHP_Token_INTERFACE extends PHP_TokenWithScopeAndVisibility -{ - protected $interfaces; - - public function getName() - { - return (string)$this->tokenStream[$this->id + 2]; - } - - public function hasParent() - { - return $this->tokenStream[$this->id + 4] instanceof PHP_Token_EXTENDS; - } - - public function getPackage() - { - $className = $this->getName(); - $docComment = $this->getDocblock(); - - $result = array( - 'namespace' => '', - 'fullPackage' => '', - 'category' => '', - 'package' => '', - 'subpackage' => '' - ); - - for ($i = $this->id; $i; --$i) { - if ($this->tokenStream[$i] instanceof PHP_Token_NAMESPACE) { - $result['namespace'] = $this->tokenStream[$i]->getName(); - break; - } - } - - if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) { - $result['category'] = $matches[1]; - } - - if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) { - $result['package'] = $matches[1]; - $result['fullPackage'] = $matches[1]; - } - - if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) { - $result['subpackage'] = $matches[1]; - $result['fullPackage'] .= '.' . $matches[1]; - } - - if (empty($result['fullPackage'])) { - $result['fullPackage'] = $this->arrayToName( - explode('_', str_replace('\\', '_', $className)), '.' - ); - } - - return $result; - } - - protected function arrayToName(array $parts, $join = '\\') - { - $result = ''; - - if (count($parts) > 1) { - array_pop($parts); - - $result = join($join, $parts); - } - - return $result; - } - - public function getParent() - { - if (!$this->hasParent()) { - return FALSE; - } - - $i = $this->id + 6; - $tokens = $this->tokenStream->tokens(); - $className = (string)$tokens[$i]; - - while (isset($tokens[$i+1]) && - !$tokens[$i+1] instanceof PHP_Token_WHITESPACE) { - $className .= (string)$tokens[++$i]; - } - - return $className; - } - - public function hasInterfaces() - { - return (isset($this->tokenStream[$this->id + 4]) && - $this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) || - (isset($this->tokenStream[$this->id + 8]) && - $this->tokenStream[$this->id + 8] instanceof PHP_Token_IMPLEMENTS); - } - - public function getInterfaces() - { - if ($this->interfaces !== NULL) { - return $this->interfaces; - } - - if (!$this->hasInterfaces()) { - return ($this->interfaces = FALSE); - } - - if ($this->tokenStream[$this->id + 4] instanceof PHP_Token_IMPLEMENTS) { - $i = $this->id + 3; - } else { - $i = $this->id + 7; - } - - $tokens = $this->tokenStream->tokens(); - - while (!$tokens[$i+1] instanceof PHP_Token_OPEN_CURLY) { - $i++; - - if ($tokens[$i] instanceof PHP_Token_STRING) { - $this->interfaces[] = (string)$tokens[$i]; - } - } - - return $this->interfaces; - } -} - -class PHP_Token_CLASS extends PHP_Token_INTERFACE {} -class PHP_Token_TRAIT extends PHP_Token_INTERFACE {} -class PHP_Token_EXTENDS extends PHP_Token {} -class PHP_Token_IMPLEMENTS extends PHP_Token {} -class PHP_Token_OBJECT_OPERATOR extends PHP_Token {} -class PHP_Token_DOUBLE_ARROW extends PHP_Token {} -class PHP_Token_LIST extends PHP_Token {} -class PHP_Token_ARRAY extends PHP_Token {} -class PHP_Token_CLASS_C extends PHP_Token {} -class PHP_Token_TRAIT_C extends PHP_Token {} -class PHP_Token_METHOD_C extends PHP_Token {} -class PHP_Token_FUNC_C extends PHP_Token {} -class PHP_Token_LINE extends PHP_Token {} -class PHP_Token_FILE extends PHP_Token {} -class PHP_Token_COMMENT extends PHP_Token {} -class PHP_Token_DOC_COMMENT extends PHP_Token {} -class PHP_Token_OPEN_TAG extends PHP_Token {} -class PHP_Token_OPEN_TAG_WITH_ECHO extends PHP_Token {} -class PHP_Token_CLOSE_TAG extends PHP_Token {} -class PHP_Token_WHITESPACE extends PHP_Token {} -class PHP_Token_START_HEREDOC extends PHP_Token {} -class PHP_Token_END_HEREDOC extends PHP_Token {} -class PHP_Token_DOLLAR_OPEN_CURLY_BRACES extends PHP_Token {} -class PHP_Token_CURLY_OPEN extends PHP_Token {} -class PHP_Token_PAAMAYIM_NEKUDOTAYIM extends PHP_Token {} - -class PHP_Token_NAMESPACE extends PHP_TokenWithScope -{ - public function getName() - { - $tokens = $this->tokenStream->tokens(); - $namespace = (string)$tokens[$this->id+2]; - - for ($i = $this->id + 3; ; $i += 2) { - if (isset($tokens[$i]) && - $tokens[$i] instanceof PHP_Token_NS_SEPARATOR) { - $namespace .= '\\' . $tokens[$i+1]; - } else { - break; - } - } - - return $namespace; - } -} - -class PHP_Token_NS_C extends PHP_Token {} -class PHP_Token_DIR extends PHP_Token {} -class PHP_Token_NS_SEPARATOR extends PHP_Token {} -class PHP_Token_DOUBLE_COLON extends PHP_Token {} -class PHP_Token_OPEN_BRACKET extends PHP_Token {} -class PHP_Token_CLOSE_BRACKET extends PHP_Token {} -class PHP_Token_OPEN_SQUARE extends PHP_Token {} -class PHP_Token_CLOSE_SQUARE extends PHP_Token {} -class PHP_Token_OPEN_CURLY extends PHP_Token {} -class PHP_Token_CLOSE_CURLY extends PHP_Token {} -class PHP_Token_SEMICOLON extends PHP_Token {} -class PHP_Token_DOT extends PHP_Token {} -class PHP_Token_COMMA extends PHP_Token {} -class PHP_Token_EQUAL extends PHP_Token {} -class PHP_Token_LT extends PHP_Token {} -class PHP_Token_GT extends PHP_Token {} -class PHP_Token_PLUS extends PHP_Token {} -class PHP_Token_MINUS extends PHP_Token {} -class PHP_Token_MULT extends PHP_Token {} -class PHP_Token_DIV extends PHP_Token {} -class PHP_Token_QUESTION_MARK extends PHP_Token {} -class PHP_Token_EXCLAMATION_MARK extends PHP_Token {} -class PHP_Token_COLON extends PHP_Token {} -class PHP_Token_DOUBLE_QUOTES extends PHP_Token {} -class PHP_Token_AT extends PHP_Token {} -class PHP_Token_AMPERSAND extends PHP_Token {} -class PHP_Token_PERCENT extends PHP_Token {} -class PHP_Token_PIPE extends PHP_Token {} -class PHP_Token_DOLLAR extends PHP_Token {} -class PHP_Token_CARET extends PHP_Token {} -class PHP_Token_TILDE extends PHP_Token {} -class PHP_Token_BACKTICK extends PHP_Token {} -PHP_TokenStream - -Copyright (c) 2009-2013, Sebastian Bergmann . -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - * Neither the name of Sebastian Bergmann nor the names of his - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -PHP_TokenStream 1.1 -=================== - -This is the list of changes for the PHP_TokenStream 1.1 release series. - -PHP_TokenStream 1.1.7 ---------------------- - -* Fixed parsing of function signatures. - -PHP_TokenStream 1.1.6 ---------------------- - -* Fixed handling of closures. -* Fixed parsing of function signatures. - -PHP_TokenStream 1.1.5 ---------------------- - -* No changes. - -PHP_TokenStream 1.1.4 ---------------------- - -* No changes. - -PHP_TokenStream 1.1.3 ---------------------- - -* Added class for the `T_TRAIT_C` token that was added in PHP 5.4. - -PHP_TokenStream 1.1.2 ---------------------- - -* Added classes for the `T_CALLABLE` and `T_INSTEADOF` tokens that were added in PHP 5.4. -* Added support for namespaced functions. - -PHP_TokenStream 1.1.1 ---------------------- - -* Fixed issue #19: Notice in `PHP_Token_INTERFACE::hasInterfaces()`. - -PHP_TokenStream 1.1.0 ---------------------- - -* Moved `phptok` tool to separate package. -PHP_TokenStream -=============== - -Installation ------------- - -PHP_TokenStream should be installed using the [PEAR Installer](http://pear.php.net/). This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0. - -The PEAR channel (`pear.phpunit.de`) that is used to distribute PHP_TokenStream needs to be registered with the local PEAR environment: - - sb@ubuntu ~ % pear channel-discover pear.phpunit.de - Adding Channel "pear.phpunit.de" succeeded - Discovery of channel "pear.phpunit.de" succeeded - -This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel: - - sb@ubuntu tokenstream % pear install phpunit/PHP_TokenStream-beta - downloading PHP_TokenStream-0.9.1.tgz ... - Starting to download PHP_TokenStream-0.9.1.tgz (5,113 bytes) - ...done: 5,113 bytes - install ok: channel://pear.phpunit.de/PHP_TokenStream-0.9.1 - -After the installation you can find the PHP_TokenStream source files inside your local PEAR directory; the path is usually `/usr/lib/php/PHP`. -PHPUnit_MockObject - -Copyright (c) 2002-2013, Sebastian Bergmann . -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - * Neither the name of Sebastian Bergmann nor the names of his - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Interface for classes which can be invoked. - * - * The invocation will be taken from a mock object and passed to an object - * of this class. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Invokable extends PHPUnit_Framework_MockObject_Verifiable -{ - /** - * Invokes the invocation object $invocation so that it can be checked for - * expectations or matched against stubs. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * The invocation object passed from mock object. - * @return object - */ - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation); - - /** - * Checks if the invocation matches. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * The invocation object passed from mock object. - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation); -} -{namespace} - -class {class_name} extends \SOAPClient -{ - public function __construct($wsdl, array $options) - { - parent::__construct('{wsdl}', $options); - } -{methods}} - public function __clone() - { - $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); - parent::__clone(); - } - - {modifier} function {reference}{method_name}({arguments_decl}) - { - $arguments = array({arguments_call}); - $count = func_num_args(); - - if ($count > {arguments_count}) { - $_arguments = func_get_args(); - - for ($i = {arguments_count}; $i < $count; $i++) { - $arguments[] = $_arguments[$i]; - } - } - - $result = $this->__phpunit_getInvocationMocker()->invoke( - new PHPUnit_Framework_MockObject_Invocation_Object( - '{class_name}', '{method_name}', $arguments, $this, {clone_arguments} - ) - ); - - return $result; - } - - public function {method_name}({arguments}) - { - } - - {modifier} static function {reference}{method_name}({arguments_decl}) - { - $arguments = array({arguments_call}); - $count = func_num_args(); - - if ($count > {arguments_count}) { - $_arguments = func_get_args(); - - for ($i = {arguments_count}; $i < $count; $i++) { - $arguments[] = $_arguments[$i]; - } - } - - $result = self::__phpunit_getStaticInvocationMocker()->invoke( - new PHPUnit_Framework_MockObject_Invocation_Static( - '{class_name}', '{method_name}', $arguments, {clone_arguments} - ) - ); - - return $result; - } -{prologue}{class_declaration} -{ - private static $__phpunit_staticInvocationMocker; - private $__phpunit_invocationMocker; - -{clone}{mocked_methods} - public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) - { - return $this->__phpunit_getInvocationMocker()->expects($matcher); - } - - public static function staticExpects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) - { - return self::__phpunit_getStaticInvocationMocker()->expects($matcher); - } - - public function __phpunit_getInvocationMocker() - { - if ($this->__phpunit_invocationMocker === NULL) { - $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; - } - - return $this->__phpunit_invocationMocker; - } - - public static function __phpunit_getStaticInvocationMocker() - { - if (self::$__phpunit_staticInvocationMocker === NULL) { - self::$__phpunit_staticInvocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker; - } - - return self::$__phpunit_staticInvocationMocker; - } - - public function __phpunit_hasMatchers() - { - return self::__phpunit_getStaticInvocationMocker()->hasMatchers() || - $this->__phpunit_getInvocationMocker()->hasMatchers(); - } - - public function __phpunit_verify() - { - self::__phpunit_getStaticInvocationMocker()->verify(); - $this->__phpunit_getInvocationMocker()->verify(); - } - - public function __phpunit_cleanup() - { - self::$__phpunit_staticInvocationMocker = NULL; - $this->__phpunit_invocationMocker = NULL; - } -}{epilogue} - public function __clone() - { - $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); - } -class {class_name} -{ - use {trait_name}; -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Mock Object Code Generator - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Generator -{ - /** - * @var array - */ - protected static $cache = array(); - - /** - * @var array - */ - protected static $blacklistedMethodNames = array( - '__clone' => TRUE, - 'abstract' => TRUE, - 'and' => TRUE, - 'array' => TRUE, - 'as' => TRUE, - 'break' => TRUE, - 'case' => TRUE, - 'catch' => TRUE, - 'class' => TRUE, - 'clone' => TRUE, - 'const' => TRUE, - 'continue' => TRUE, - 'declare' => TRUE, - 'default' => TRUE, - 'die' => TRUE, - 'do' => TRUE, - 'echo' => TRUE, - 'else' => TRUE, - 'elseif' => TRUE, - 'empty' => TRUE, - 'enddeclare' => TRUE, - 'endfor' => TRUE, - 'endforeach' => TRUE, - 'endif' => TRUE, - 'endswitch' => TRUE, - 'endwhile' => TRUE, - 'eval' => TRUE, - 'exit' => TRUE, - 'expects' => TRUE, - 'extends' => TRUE, - 'final' => TRUE, - 'for' => TRUE, - 'foreach' => TRUE, - 'function' => TRUE, - 'global' => TRUE, - 'goto' => TRUE, - 'if' => TRUE, - 'implements' => TRUE, - 'include' => TRUE, - 'include_once' => TRUE, - 'instanceof' => TRUE, - 'interface' => TRUE, - 'isset' => TRUE, - 'list' => TRUE, - 'namespace' => TRUE, - 'new' => TRUE, - 'or' => TRUE, - 'print' => TRUE, - 'private' => TRUE, - 'protected' => TRUE, - 'public' => TRUE, - 'require' => TRUE, - 'require_once' => TRUE, - 'return' => TRUE, - 'static' => TRUE, - 'staticExpects' => TRUE, - 'switch' => TRUE, - 'throw' => TRUE, - 'try' => TRUE, - 'unset' => TRUE, - 'use' => TRUE, - 'var' => TRUE, - 'while' => TRUE, - 'xor' => TRUE - ); - - /** - * @var boolean - */ - protected static $soapLoaded = NULL; - - /** - * Returns a mock object for the specified class. - * - * @param string $originalClassName - * @param array $methods - * @param array $arguments - * @param string $mockClassName - * @param boolean $callOriginalConstructor - * @param boolean $callOriginalClone - * @param boolean $callAutoload - * @param boolean $cloneArguments - * @return object - * @throws InvalidArgumentException - * @since Method available since Release 1.0.0 - */ - public static function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = TRUE) - { - if (!is_string($originalClassName)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - if (!is_string($mockClassName)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(4, 'string'); - } - - if (!is_array($methods) && !is_null($methods)) { - throw new InvalidArgumentException; - } - - if (NULL !== $methods) { - foreach ($methods as $method) { - if (!preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*~', $method)) { - throw new PHPUnit_Framework_Exception( - sprintf( - 'Cannot stub or mock method with invalid name "%s"', - $method - ) - ); - } - } - if ($methods != array_unique($methods)) { - throw new PHPUnit_Framework_Exception( - sprintf( - 'Cannot stub or mock using a method list that contains duplicates: "%s"', - implode(', ', $methods) - ) - ); - } - } - - if ($mockClassName != '' && class_exists($mockClassName, FALSE)) { - $reflect = new ReflectionClass($mockClassName); - if (!$reflect->implementsInterface("PHPUnit_Framework_MockObject_MockObject")) { - throw new PHPUnit_Framework_Exception( - sprintf( - 'Class "%s" already exists.', - $mockClassName - ) - ); - } - } - - $mock = self::generate( - $originalClassName, - $methods, - $mockClassName, - $callOriginalClone, - $callAutoload, - $cloneArguments - ); - - return self::getObject( - $mock['code'], - $mock['mockClassName'], - $originalClassName, - $callOriginalConstructor, - $callAutoload, - $arguments - ); - } - - /** - * @param string $code - * @param string $className - * @param string $originalClassName - * @param string $callOriginalConstructor - * @param string $callAutoload - * @param array $arguments - * @return object - */ - protected static function getObject($code, $className, $originalClassName = '', $callOriginalConstructor = FALSE, $callAutoload = FALSE, array $arguments = array()) - { - if (!class_exists($className, FALSE)) { - eval($code); - } - - if ($callOriginalConstructor && - !interface_exists($originalClassName, $callAutoload)) { - if (count($arguments) == 0) { - $object = new $className; - } else { - $class = new ReflectionClass($className); - $object = $class->newInstanceArgs($arguments); - } - } else { - // Use a trick to create a new object of a class - // without invoking its constructor. - $object = unserialize( - sprintf('O:%d:"%s":0:{}', strlen($className), $className) - ); - } - - return $object; - } - - /** - * Returns a mock object for the specified abstract class with all abstract - * methods of the class mocked. Concrete methods to mock can be specified with - * the last parameter - * - * @param string $originalClassName - * @param array $arguments - * @param string $mockClassName - * @param boolean $callOriginalConstructor - * @param boolean $callOriginalClone - * @param boolean $callAutoload - * @param array $mockedMethods - * @param boolean $cloneArguments - * @return object - * @since Method available since Release 1.0.0 - * @throws InvalidArgumentException - */ - public static function getMockForAbstractClass($originalClassName, array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE, $mockedMethods = array(), $cloneArguments = TRUE) - { - if (!is_string($originalClassName)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - if (!is_string($mockClassName)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(3, 'string'); - } - - if (class_exists($originalClassName, $callAutoload) || - interface_exists($originalClassName, $callAutoload)) { - $methods = array(); - $reflector = new ReflectionClass($originalClassName); - - foreach ($reflector->getMethods() as $method) { - if ($method->isAbstract() || in_array($method->getName(), $mockedMethods)) { - $methods[] = $method->getName(); - } - } - - if (empty($methods)) { - $methods = NULL; - } - - return self::getMock( - $originalClassName, - $methods, - $arguments, - $mockClassName, - $callOriginalConstructor, - $callOriginalClone, - $callAutoload, - $cloneArguments - ); - } else { - throw new PHPUnit_Framework_Exception( - sprintf( - 'Class "%s" does not exist.', - $originalClassName - ) - ); - } - } - - /** - * Returns an object for the specified trait. - * - * @param string $traitName - * @param array $arguments - * @param string $traitClassName - * @param boolean $callOriginalConstructor - * @param boolean $callOriginalClone - * @param boolean $callAutoload - * @return object - * @since Method available since Release 1.1.0 - * @throws InvalidArgumentException - */ - public static function getObjectForTrait($traitName, array $arguments = array(), $traitClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE) - { - if (!is_string($traitName)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - if (!is_string($traitClassName)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(3, 'string'); - } - - if (!trait_exists($traitName, $callAutoload)) { - throw new PHPUnit_Framework_Exception( - sprintf( - 'Trait "%s" does not exist.', - $traitName - ) - ); - } - - $className = self::generateClassName( - $traitName, $traitClassName, 'Trait_' - ); - - $templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . - DIRECTORY_SEPARATOR; - $classTemplate = new Text_Template( - $templateDir . 'trait_class.tpl' - ); - - $classTemplate->setVar( - array( - 'class_name' => $className['className'], - 'trait_name' => $traitName - ) - ); - - return self::getObject( - $classTemplate->render(), - $className['className'] - ); - } - - /** - * @param string $originalClassName - * @param array $methods - * @param string $mockClassName - * @param boolean $callOriginalClone - * @param boolean $callAutoload - * @param boolean $cloneArguments - * @return array - */ - public static function generate($originalClassName, array $methods = NULL, $mockClassName = '', $callOriginalClone = TRUE, $callAutoload = TRUE, $cloneArguments = TRUE) - { - if ($mockClassName == '') { - $key = md5( - $originalClassName . - serialize($methods) . - serialize($callOriginalClone) . - serialize($cloneArguments) - ); - - if (isset(self::$cache[$key])) { - return self::$cache[$key]; - } - } - - $mock = self::generateMock( - $originalClassName, - $methods, - $mockClassName, - $callOriginalClone, - $callAutoload, - $cloneArguments - ); - - if (isset($key)) { - self::$cache[$key] = $mock; - } - - return $mock; - } - - /** - * @param string $wsdlFile - * @param string $originalClassName - * @param array $methods - * @param array $options - * @return array - */ - public static function generateClassFromWsdl($wsdlFile, $originalClassName, array $methods = array(), array $options = array()) - { - if (self::$soapLoaded === NULL) { - self::$soapLoaded = extension_loaded('soap'); - } - - if (self::$soapLoaded) { - $client = new SOAPClient($wsdlFile, $options); - $_methods = array_unique($client->__getFunctions()); - unset($client); - - $templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . - 'Generator' . DIRECTORY_SEPARATOR; - $methodTemplate = new Text_Template( - $templateDir . 'wsdl_method.tpl' - ); - $methodsBuffer = ''; - - foreach ($_methods as $method) { - $nameStart = strpos($method, ' ') + 1; - $nameEnd = strpos($method, '('); - $name = substr($method, $nameStart, $nameEnd - $nameStart); - - if (empty($methods) || in_array($name, $methods)) { - $args = explode( - ',', - substr( - $method, - $nameEnd + 1, - strpos($method, ')') - $nameEnd - 1 - ) - ); - $numArgs = count($args); - - for ($i = 0; $i < $numArgs; $i++) { - $args[$i] = substr($args[$i], strpos($args[$i], '$')); - } - - $methodTemplate->setVar( - array( - 'method_name' => $name, - 'arguments' => join(', ', $args) - ) - ); - - $methodsBuffer .= $methodTemplate->render(); - } - } - - $optionsBuffer = 'array('; - foreach ($options as $key => $value) { - $optionsBuffer .= $key . ' => ' . $value; - } - - $optionsBuffer .= ')'; - - $classTemplate = new Text_Template( - $templateDir . 'wsdl_class.tpl' - ); - - $namespace = ''; - if(strpos($originalClassName, '\\') !== FALSE) { - $parts = explode('\\', $originalClassName); - $originalClassName = array_pop($parts); - $namespace = 'namespace ' . join('\\', $parts) . ';'; - } - - $classTemplate->setVar( - array( - 'namespace' => $namespace, - 'class_name' => $originalClassName, - 'wsdl' => $wsdlFile, - 'options' => $optionsBuffer, - 'methods' => $methodsBuffer - ) - ); - - return $classTemplate->render(); - } else { - throw new PHPUnit_Framework_Exception( - 'The SOAP extension is required to generate a mock object ' . - 'from WSDL.' - ); - } - } - - /** - * @param string $originalClassName - * @param array|null $methods - * @param string $mockClassName - * @param boolean $callOriginalClone - * @param boolean $callAutoload - * @param boolean $cloneArguments - * @return array - */ - protected static function generateMock($originalClassName, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments = TRUE) - { - $templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . - DIRECTORY_SEPARATOR; - $classTemplate = new Text_Template( - $templateDir . 'mocked_class.tpl' - ); - $cloneTemplate = ''; - $isClass = FALSE; - $isInterface = FALSE; - - $mockClassName = self::generateClassName( - $originalClassName, $mockClassName, 'Mock_' - ); - - if (class_exists($mockClassName['fullClassName'], $callAutoload)) { - $isClass = TRUE; - } else { - if (interface_exists($mockClassName['fullClassName'], $callAutoload)) { - $isInterface = TRUE; - } - } - - if (!class_exists($mockClassName['fullClassName'], $callAutoload) && - !interface_exists($mockClassName['fullClassName'], $callAutoload)) { - $prologue = 'class ' . $mockClassName['originalClassName'] . "\n{\n}\n\n"; - - if (!empty($mockClassName['namespaceName'])) { - $prologue = 'namespace ' . $mockClassName['namespaceName'] . - " {\n\n" . $prologue . "}\n\n" . - "namespace {\n\n"; - - $epilogue = "\n\n}"; - } - - $cloneTemplate = new Text_Template( - $templateDir . 'mocked_clone.tpl' - ); - } else { - $class = new ReflectionClass($mockClassName['fullClassName']); - - if ($class->isFinal()) { - throw new PHPUnit_Framework_Exception( - sprintf( - 'Class "%s" is declared "final" and cannot be mocked.', - $mockClassName['fullClassName'] - ) - ); - } - - if ($class->hasMethod('__clone')) { - $cloneMethod = $class->getMethod('__clone'); - - if (!$cloneMethod->isFinal()) { - if ($callOriginalClone && !$isInterface) { - $cloneTemplate = new Text_Template( - $templateDir . 'unmocked_clone.tpl' - ); - } else { - $cloneTemplate = new Text_Template( - $templateDir . 'mocked_clone.tpl' - ); - } - } - } else { - $cloneTemplate = new Text_Template( - $templateDir . 'mocked_clone.tpl' - ); - } - } - - if (is_object($cloneTemplate)) { - $cloneTemplate = $cloneTemplate->render(); - } - - if (is_array($methods) && empty($methods) && - ($isClass || $isInterface)) { - $methods = get_class_methods($mockClassName['fullClassName']); - } - - if (!is_array($methods)) { - $methods = array(); - } - - $mockedMethods = ''; - - if (isset($class)) { - foreach ($methods as $methodName) { - try { - $method = $class->getMethod($methodName); - - if (self::canMockMethod($method)) { - $mockedMethods .= self::generateMockedMethodDefinitionFromExisting( - $templateDir, $method, $cloneArguments - ); - } - } - - catch (ReflectionException $e) { - $mockedMethods .= self::generateMockedMethodDefinition( - $templateDir, $mockClassName['fullClassName'], $methodName, $cloneArguments - ); - } - } - } else { - foreach ($methods as $methodName) { - $mockedMethods .= self::generateMockedMethodDefinition( - $templateDir, $mockClassName['fullClassName'], $methodName, $cloneArguments - ); - } - } - - $classTemplate->setVar( - array( - 'prologue' => isset($prologue) ? $prologue : '', - 'epilogue' => isset($epilogue) ? $epilogue : '', - 'class_declaration' => self::generateMockClassDeclaration( - $mockClassName, $isInterface - ), - 'clone' => $cloneTemplate, - 'mock_class_name' => $mockClassName['className'], - 'mocked_methods' => $mockedMethods - ) - ); - - return array( - 'code' => $classTemplate->render(), - 'mockClassName' => $mockClassName['className'] - ); - } - - /** - * @param string $originalClassName - * @param string $className - * @param string $prefix - * @return array - */ - protected static function generateClassName($originalClassName, $className, $prefix) - { - if ($originalClassName[0] == '\\') { - $originalClassName = substr($originalClassName, 1); - } - - $classNameParts = explode('\\', $originalClassName); - - if (count($classNameParts) > 1) { - $originalClassName = array_pop($classNameParts); - $namespaceName = join('\\', $classNameParts); - $fullClassName = $namespaceName . '\\' . $originalClassName; - } else { - $namespaceName = ''; - $fullClassName = $originalClassName; - } - - if ($className == '') { - do { - $className = $prefix . $originalClassName . '_' . - substr(md5(microtime()), 0, 8); - } - while (class_exists($className, FALSE)); - } - - return array( - 'className' => $className, - 'originalClassName' => $originalClassName, - 'fullClassName' => $fullClassName, - 'namespaceName' => $namespaceName - ); - } - - /** - * @param array $mockClassName - * @param boolean $isInterface - * @return array - */ - protected static function generateMockClassDeclaration(array $mockClassName, $isInterface) - { - $buffer = 'class '; - - if ($isInterface) { - $buffer .= sprintf( - "%s implements PHPUnit_Framework_MockObject_MockObject, %s%s", - $mockClassName['className'], - !empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'] . '\\' : '', - $mockClassName['originalClassName'] - ); - } else { - $buffer .= sprintf( - "%s extends %s%s implements PHPUnit_Framework_MockObject_MockObject", - $mockClassName['className'], - !empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'] . '\\' : '', - $mockClassName['originalClassName'] - ); - } - - return $buffer; - } - - /** - * @param string $templateDir - * @param ReflectionMethod $method - * @param boolean $cloneArguments - * @return string - */ - protected static function generateMockedMethodDefinitionFromExisting($templateDir, ReflectionMethod $method, $cloneArguments = TRUE) - { - if ($method->isPrivate()) { - $modifier = 'private'; - } - - else if ($method->isProtected()) { - $modifier = 'protected'; - } - - else { - $modifier = 'public'; - } - - if ($method->isStatic()) { - $static = TRUE; - } else { - $static = FALSE; - } - - if ($method->returnsReference()) { - $reference = '&'; - } else { - $reference = ''; - } - - return self::generateMockedMethodDefinition( - $templateDir, - $method->getDeclaringClass()->getName(), - $method->getName(), - $cloneArguments, - $modifier, - PHPUnit_Util_Class::getMethodParameters($method), - PHPUnit_Util_Class::getMethodParameters($method, TRUE), - $reference, - $static - ); - } - - /** - * @param string $templateDir - * @param string $className - * @param string $methodName - * @param boolean $cloneArguments - * @param string $modifier - * @param string $arguments_decl - * @param string $arguments_call - * @param string $reference - * @param boolean $static - * @return string - */ - protected static function generateMockedMethodDefinition($templateDir, $className, $methodName, $cloneArguments = TRUE, $modifier = 'public', $arguments_decl = '', $arguments_call = '', $reference = '', $static = FALSE) - { - if ($static) { - $template = new Text_Template( - $templateDir . 'mocked_static_method.tpl' - ); - } else { - $template = new Text_Template( - $templateDir . 'mocked_object_method.tpl' - ); - } - - $template->setVar( - array( - 'arguments_decl' => $arguments_decl, - 'arguments_call' => $arguments_call, - 'arguments_count' => !empty($arguments_call) ? count(explode(',', $arguments_call)) : 0, - 'class_name' => $className, - 'method_name' => $methodName, - 'modifier' => $modifier, - 'reference' => $reference, - 'clone_arguments' => $cloneArguments ? 'TRUE' : 'FALSE' - ) - ); - - return $template->render(); - } - - /** - * @param ReflectionMethod $method - * @return boolean - */ - protected static function canMockMethod(ReflectionMethod $method) - { - if ($method->isConstructor() || $method->isFinal() || - isset(self::$blacklistedMethodNames[$method->getName()])) { - return FALSE; - } - - return TRUE; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which looks for a specific method name in the invocations. - * - * Checks the method name all incoming invocations, the name is checked against - * the defined constraint $constraint. If the constraint is met it will return - * true in matches(). - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher_MethodName extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation -{ - /** - * @var PHPUnit_Framework_Constraint - */ - protected $constraint; - - /** - * @param PHPUnit_Framework_Constraint|string - * @throws PHPUnit_Framework_Constraint - */ - public function __construct($constraint) - { - if (!$constraint instanceof PHPUnit_Framework_Constraint) { - if (!is_string($constraint)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $constraint = new PHPUnit_Framework_Constraint_IsEqual( - $constraint, 0, 10, FALSE, TRUE - ); - } - - $this->constraint = $constraint; - } - - /** - * @return string - */ - public function toString() - { - return 'method name ' . $this->constraint->toString(); - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) - { - return $this->constraint->evaluate($invocation->methodName, '', TRUE); - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which checks if a method has been invoked at least one - * time. - * - * If the number of invocations is 0 it will throw an exception in verify. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder -{ - /** - * @return string - */ - public function toString() - { - return 'invoked at least once'; - } - - /** - * Verifies that the current expectation is valid. If everything is OK the - * code should just return, if not it must throw an exception. - * - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function verify() - { - $count = $this->getInvocationCount(); - - if ($count < 1) { - throw new PHPUnit_Framework_ExpectationFailedException( - 'Expected invocation at least once but it never occured.' - ); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Records invocations and provides convenience methods for checking them later - * on. - * This abstract class can be implemented by matchers which needs to check the - * number of times an invocation has occured. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - * @abstract - */ -abstract class PHPUnit_Framework_MockObject_Matcher_InvokedRecorder implements PHPUnit_Framework_MockObject_Matcher_Invocation -{ - /** - * @var PHPUnit_Framework_MockObject_Invocation[] - */ - protected $invocations = array(); - - /** - * @return integer - */ - public function getInvocationCount() - { - return count($this->invocations); - } - - /** - * @return PHPUnit_Framework_MockObject_Invocation[] - */ - public function getInvocations() - { - return $this->invocations; - } - - /** - * @return boolean - */ - public function hasBeenInvoked() - { - return count($this->invocations) > 0; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - */ - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) - { - $this->invocations[] = $invocation; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) - { - return TRUE; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which allos any parameters to a method. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher_AnyParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation -{ - /** - * @return string - */ - public function toString() - { - return 'with any parameters'; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) - { - return TRUE; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which checks if a method has been invoked a certain amount - * of times. - * If the number of invocations exceeds the value it will immediately throw an - * exception, - * If the number is less it will later be checked in verify() and also throw an - * exception. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher_InvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder -{ - /** - * @var integer - */ - protected $expectedCount; - - /** - * @param interger $expectedCount - */ - public function __construct($expectedCount) - { - $this->expectedCount = $expectedCount; - } - - /** - * @return string - */ - public function toString() - { - return 'invoked ' . $this->expectedCount . ' time(s)'; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) - { - parent::invoked($invocation); - - $count = $this->getInvocationCount(); - - if ($count > $this->expectedCount) { - $message = $invocation->toString() . ' '; - - switch ($this->expectedCount) { - case 0: { - $message .= 'was not expected to be called.'; - } - break; - - case 1: { - $message .= 'was not expected to be called more than once.'; - } - break; - - default: { - $message .= sprintf( - 'was not expected to be called more than %d times.', - - $this->expectedCount - ); - } - } - - throw new PHPUnit_Framework_ExpectationFailedException($message); - } - } - - /** - * Verifies that the current expectation is valid. If everything is OK the - * code should just return, if not it must throw an exception. - * - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function verify() - { - $count = $this->getInvocationCount(); - - if ($count !== $this->expectedCount) { - throw new PHPUnit_Framework_ExpectationFailedException( - sprintf( - 'Method was expected to be called %d times, ' . - 'actually called %d times.', - - $this->expectedCount, - $count - ) - ); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which checks if a method has been invoked zero or more - * times. This matcher will always match. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder -{ - /** - * @return string - */ - public function toString() - { - return 'invoked zero or more times'; - } - - /** - */ - public function verify() - { - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which looks for specific parameters in the invocations. - * - * Checks the parameters of all incoming invocations, the parameter list is - * checked against the defined constraints in $parameters. If the constraint - * is met it will return true in matches(). - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher_Parameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation -{ - /** - * @var array - */ - protected $parameters = array(); - - /** - * @var PHPUnit_Framework_MockObject_Invocation - */ - protected $invocation; - - /** - * @param array $parameters - */ - public function __construct(array $parameters) - { - foreach ($parameters as $parameter) { - if (!($parameter instanceof PHPUnit_Framework_Constraint)) { - $parameter = new PHPUnit_Framework_Constraint_IsEqual( - $parameter - ); - } - - $this->parameters[] = $parameter; - } - } - - /** - * @return string - */ - public function toString() - { - $text = 'with parameter'; - - foreach ($this->parameters as $index => $parameter) { - if ($index > 0) { - $text .= ' and'; - } - - $text .= ' ' . $index . ' ' . $parameter->toString(); - } - - return $text; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) - { - $this->invocation = $invocation; - $this->verify(); - - return count($invocation->parameters) < count($this->parameters); - } - - /** - * Checks if the invocation $invocation matches the current rules. If it - * does the matcher will get the invoked() method called which should check - * if an expectation is met. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * Object containing information on a mocked or stubbed method which - * was invoked. - * @return bool - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function verify() - { - if ($this->invocation === NULL) { - throw new PHPUnit_Framework_ExpectationFailedException( - 'Mocked method does not exist.' - ); - } - - if (count($this->invocation->parameters) < count($this->parameters)) { - throw new PHPUnit_Framework_ExpectationFailedException( - sprintf( - 'Parameter count for invocation %s is too low.', - - $this->invocation->toString() - ) - ); - } - - foreach ($this->parameters as $i => $parameter) { - $parameter->evaluate( - $this->invocation->parameters[$i], - sprintf( - 'Parameter %s for invocation %s does not match expected ' . - 'value.', - - $i, - $this->invocation->toString() - ) - ); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Interface for classes which matches an invocation based on its - * method name, argument, order or call count. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Matcher_Invocation extends PHPUnit_Framework_SelfDescribing, PHPUnit_Framework_MockObject_Verifiable -{ - /** - * Registers the invocation $invocation in the object as being invoked. - * This will only occur after matches() returns true which means the - * current invocation is the correct one. - * - * The matcher can store information from the invocation which can later - * be checked in verify(), or it can check the values directly and throw - * and exception if an expectation is not met. - * - * If the matcher is a stub it will also have a return value. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * Object containing information on a mocked or stubbed method which - * was invoked. - * @return mixed - */ - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation); - - /** - * Checks if the invocation $invocation matches the current rules. If it does - * the matcher will get the invoked() method called which should check if an - * expectation is met. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * Object containing information on a mocked or stubbed method which - * was invoked. - * @return bool - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which does not care about previous state from earlier - * invocations. - * - * This abstract class can be implemented by matchers which does not care about - * state but only the current run-time value of the invocation itself. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - * @abstract - */ -abstract class PHPUnit_Framework_MockObject_Matcher_StatelessInvocation implements PHPUnit_Framework_MockObject_Matcher_Invocation -{ - /** - * Registers the invocation $invocation in the object as being invoked. - * This will only occur after matches() returns true which means the - * current invocation is the correct one. - * - * The matcher can store information from the invocation which can later - * be checked in verify(), or it can check the values directly and throw - * and exception if an expectation is not met. - * - * If the matcher is a stub it will also have a return value. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * Object containing information on a mocked or stubbed method which - * was invoked. - * @return mixed - */ - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) - { - } - - /** - * Checks if the invocation $invocation matches the current rules. If it does - * the matcher will get the invoked() method called which should check if an - * expectation is met. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * Object containing information on a mocked or stubbed method which - * was invoked. - * @return bool - */ - public function verify() - { - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Invocation matcher which checks if a method was invoked at a certain index. - * - * If the expected index number does not match the current invocation index it - * will not match which means it skips all method and parameter matching. Only - * once the index is reached will the method and parameter start matching and - * verifying. - * - * If the index is never reached it will throw an exception in index. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex implements PHPUnit_Framework_MockObject_Matcher_Invocation -{ - /** - * @var integer - */ - protected $sequenceIndex; - - /** - * @var integer - */ - protected $currentIndex = -1; - - /** - * @param integer $sequenceIndex - */ - public function __construct($sequenceIndex) - { - $this->sequenceIndex = $sequenceIndex; - } - - /** - * @return string - */ - public function toString() - { - return 'invoked at sequence index ' . $this->sequenceIndex; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) - { - $this->currentIndex++; - - return $this->currentIndex == $this->sequenceIndex; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - */ - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) - { - } - - /** - * Verifies that the current expectation is valid. If everything is OK the - * code should just return, if not it must throw an exception. - * - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function verify() - { - if ($this->currentIndex < $this->sequenceIndex) { - throw new PHPUnit_Framework_ExpectationFailedException( - sprintf( - 'The expected invocation at index %s was never reached.', - - $this->sequenceIndex - ) - ); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Giorgio Sironi - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Implementation of the Builder pattern for Mock objects. - * - * @package PHPUnit_MockObject - * @author Giorgio Sironi - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_MockBuilder -{ - /** - * @var PHPUnit_Framework_TestCase - */ - protected $testCase; - - /** - * @var string - */ - protected $className; - - /** - * @var array - */ - protected $methods = array(); - - /** - * @var string - */ - protected $mockClassName = ''; - - /** - * @var array - */ - protected $constructorArgs = array(); - - /** - * @var boolean - */ - protected $originalConstructor = TRUE; - - /** - * @var boolean - */ - protected $originalClone = TRUE; - - /** - * @var boolean - */ - protected $autoload = TRUE; - - /** - * @var boolean - */ - protected $cloneArguments = FALSE; - - /** - * @param PHPUnit_Framework_TestCase - * @param string - */ - public function __construct(PHPUnit_Framework_TestCase $testCase, $className) - { - $this->testCase = $testCase; - $this->className = $className; - } - - /** - * Creates a mock object using a fluent interface. - * - * @return PHPUnit_Framework_MockObject_MockObject - */ - public function getMock() - { - return $this->testCase->getMock( - $this->className, - $this->methods, - $this->constructorArgs, - $this->mockClassName, - $this->originalConstructor, - $this->originalClone, - $this->autoload, - $this->cloneArguments - ); - } - - /** - * Creates a mock object for an abstract class using a fluent interface. - * - * @return PHPUnit_Framework_MockObject_MockObject - */ - public function getMockForAbstractClass() - { - return $this->testCase->getMockForAbstractClass( - $this->className, - $this->constructorArgs, - $this->mockClassName, - $this->originalConstructor, - $this->originalClone, - $this->autoload, - $this->methods, - $this->cloneArguments - ); - } - - /** - * Specifies the subset of methods to mock. Default is to mock all of them. - * - * @param array|null $methods - * @return PHPUnit_Framework_MockObject_MockBuilder - */ - public function setMethods($methods) - { - $this->methods = $methods; - - return $this; - } - - /** - * Specifies the arguments for the constructor. - * - * @param array $args - * @return PHPUnit_Framework_MockObject_MockBuilder - */ - public function setConstructorArgs(array $args) - { - $this->constructorArgs = $args; - - return $this; - } - - /** - * Specifies the name for the mock class. - * - * @param string $name - * @return PHPUnit_Framework_MockObject_MockBuilder - */ - public function setMockClassName($name) - { - $this->mockClassName = $name; - - return $this; - } - - /** - * Disables the invocation of the original constructor. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - */ - public function disableOriginalConstructor() - { - $this->originalConstructor = FALSE; - - return $this; - } - - /** - * Enables the invocation of the original constructor. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - * @since Method available since Release 1.2.0 - */ - public function enableOriginalConstructor() - { - $this->originalConstructor = TRUE; - - return $this; - } - - /** - * Disables the invocation of the original clone constructor. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - */ - public function disableOriginalClone() - { - $this->originalClone = FALSE; - - return $this; - } - - /** - * Enables the invocation of the original clone constructor. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - * @since Method available since Release 1.2.0 - */ - public function enableOriginalClone() - { - $this->originalClone = TRUE; - - return $this; - } - - /** - * Disables the use of class autoloading while creating the mock object. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - */ - public function disableAutoload() - { - $this->autoload = FALSE; - - return $this; - } - - /** - * Enables the use of class autoloading while creating the mock object. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - * @since Method available since Release 1.2.0 - */ - public function enableAutoload() - { - $this->autoload = TRUE; - - return $this; - } - - /** - * Disables the cloning of arguments passed to mocked methods. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - * @since Method available since Release 1.2.0 - */ - public function disableArgumentCloning() - { - $this->cloneArguments = FALSE; - - return $this; - } - - /** - * Enables the cloning of arguments passed to mocked methods. - * - * @return PHPUnit_Framework_MockObject_MockBuilder - * @since Method available since Release 1.2.0 - */ - public function enableArgumentCloning() - { - $this->cloneArguments = TRUE; - - return $this; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Main matcher which defines a full expectation using method, parameter and - * invocation matchers. - * This matcher encapsulates all the other matchers and allows the builder to - * set the specific matchers when the appropriate methods are called (once(), - * where() etc.). - * - * All properties are public so that they can easily be accessed by the builder. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Matcher implements PHPUnit_Framework_MockObject_Matcher_Invocation -{ - /** - * @var PHPUnit_Framework_MockObject_Matcher_Invocation - */ - public $invocationMatcher; - - /** - * @var mixed - */ - public $afterMatchBuilderId = NULL; - - /** - * @var boolean - */ - public $afterMatchBuilderIsInvoked = FALSE; - - /** - * @var PHPUnit_Framework_MockObject_Matcher_MethodName - */ - public $methodNameMatcher = NULL; - - /** - * @var PHPUnit_Framework_MockObject_Matcher_Parameters - */ - public $parametersMatcher = NULL; - - /** - * @var PHPUnit_Framework_MockObject_Stub - */ - public $stub = NULL; - - /** - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher - */ - public function __construct(PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher) - { - $this->invocationMatcher = $invocationMatcher; - } - - /** - * @return string - */ - public function toString() - { - $list = array(); - - if ($this->invocationMatcher !== NULL) { - $list[] = $this->invocationMatcher->toString(); - } - - if ($this->methodNameMatcher !== NULL) { - $list[] = 'where ' . $this->methodNameMatcher->toString(); - } - - if ($this->parametersMatcher !== NULL) { - $list[] = 'and ' . $this->parametersMatcher->toString(); - } - - if ($this->afterMatchBuilderId !== NULL) { - $list[] = 'after ' . $this->afterMatchBuilderId; - } - - if ($this->stub !== NULL) { - $list[] = 'will ' . $this->stub->toString(); - } - - return join(' ', $list); - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return mixed - */ - public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) - { - if ($this->invocationMatcher === NULL) { - throw new PHPUnit_Framework_Exception( - 'No invocation matcher is set' - ); - } - - if ($this->methodNameMatcher === NULL) { - throw new PHPUnit_Framework_Exception('No method matcher is set'); - } - - if ($this->afterMatchBuilderId !== NULL) { - $builder = $invocation->object - ->__phpunit_getInvocationMocker() - ->lookupId($this->afterMatchBuilderId); - - if (!$builder) { - throw new PHPUnit_Framework_Exception( - sprintf( - 'No builder found for match builder identification <%s>', - - $this->afterMatchBuilderId - ) - ); - } - - $matcher = $builder->getMatcher(); - - if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) { - $this->afterMatchBuilderIsInvoked = TRUE; - } - } - - $this->invocationMatcher->invoked($invocation); - - try { - if ( $this->parametersMatcher !== NULL && - !$this->parametersMatcher->matches($invocation)) { - $this->parametersMatcher->verify(); - } - } - - catch (PHPUnit_Framework_ExpectationFailedException $e) { - throw new PHPUnit_Framework_ExpectationFailedException( - sprintf( - "Expectation failed for %s when %s\n%s", - - $this->methodNameMatcher->toString(), - $this->invocationMatcher->toString(), - $e->getMessage() - ), - $e->getComparisonFailure() - ); - } - - if ($this->stub) { - return $this->stub->invoke($invocation); - } - - return NULL; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) - { - if ($this->afterMatchBuilderId !== NULL) { - $builder = $invocation->object - ->__phpunit_getInvocationMocker() - ->lookupId($this->afterMatchBuilderId); - - if (!$builder) { - throw new PHPUnit_Framework_Exception( - sprintf( - 'No builder found for match builder identification <%s>', - - $this->afterMatchBuilderId - ) - ); - } - - $matcher = $builder->getMatcher(); - - if (!$matcher) { - return FALSE; - } - - if (!$matcher->invocationMatcher->hasBeenInvoked()) { - return FALSE; - } - } - - if ($this->invocationMatcher === NULL) { - throw new PHPUnit_Framework_Exception( - 'No invocation matcher is set' - ); - } - - if ($this->methodNameMatcher === NULL) { - throw new PHPUnit_Framework_Exception('No method matcher is set'); - } - - if (!$this->invocationMatcher->matches($invocation)) { - return FALSE; - } - - try { - if (!$this->methodNameMatcher->matches($invocation)) { - return FALSE; - } - } - - catch (PHPUnit_Framework_ExpectationFailedException $e) { - throw new PHPUnit_Framework_ExpectationFailedException( - sprintf( - "Expectation failed for %s when %s\n%s", - - $this->methodNameMatcher->toString(), - $this->invocationMatcher->toString(), - $e->getMessage() - ), - $e->getComparisonFailure() - ); - } - - return TRUE; - } - - /** - * @throws PHPUnit_Framework_Exception - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function verify() - { - if ($this->invocationMatcher === NULL) { - throw new PHPUnit_Framework_Exception( - 'No invocation matcher is set' - ); - } - - if ($this->methodNameMatcher === NULL) { - throw new PHPUnit_Framework_Exception('No method matcher is set'); - } - - try { - $this->invocationMatcher->verify(); - - if ($this->parametersMatcher === NULL) { - $this->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters; - } - - $invocationIsAny = get_class($this->invocationMatcher) === 'PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount'; - if (!$invocationIsAny) { - $this->parametersMatcher->verify(); - } - } - - catch (PHPUnit_Framework_ExpectationFailedException $e) { - throw new PHPUnit_Framework_ExpectationFailedException( - sprintf( - "Expectation failed for %s when %s.\n%s", - - $this->methodNameMatcher->toString(), - $this->invocationMatcher->toString(), - $e->getMessage() - ) - ); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Mocker for invocations which are sent from - * PHPUnit_Framework_MockObject_MockObject objects. - * - * Keeps track of all expectations and stubs as well as registering - * identifications for builders. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_InvocationMocker implements PHPUnit_Framework_MockObject_Stub_MatcherCollection, PHPUnit_Framework_MockObject_Invokable, PHPUnit_Framework_MockObject_Builder_Namespace -{ - /** - * @var PHPUnit_Framework_MockObject_Matcher_Invocation[] - */ - protected $matchers = array(); - - /** - * @var PHPUnit_Framework_MockObject_Builder_Match[] - */ - protected $builderMap = array(); - - /** - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher - */ - public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) - { - $this->matchers[] = $matcher; - } - - /** - * @since Method available since Release 1.1.0 - */ - public function hasMatchers() - { - if (empty($this->matchers)) { - return FALSE; - } - - foreach ($this->matchers as $matcher) { - if (!$matcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount) { - return TRUE; - } - } - - return FALSE; - } - - /** - * @param mixed $id - * @return boolean|null - */ - public function lookupId($id) - { - if (isset($this->builderMap[$id])) { - return $this->builderMap[$id]; - } - - return NULL; - } - - /** - * @param mixed $id - * @param PHPUnit_Framework_MockObject_Builder_Match $builder - * @throws PHPUnit_Framework_Exception - */ - public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder) - { - if (isset($this->builderMap[$id])) { - throw new PHPUnit_Framework_Exception( - 'Match builder with id <' . $id . '> is already registered.' - ); - } - - $this->builderMap[$id] = $builder; - } - - /** - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) - { - return new PHPUnit_Framework_MockObject_Builder_InvocationMocker( - $this, $matcher - ); - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return mixed - */ - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - $exception = NULL; - $hasReturnValue = FALSE; - - if (strtolower($invocation->methodName) == '__tostring') { - $returnValue = ''; - } else { - $returnValue = NULL; - } - - foreach ($this->matchers as $match) { - try { - if ($match->matches($invocation)) { - $value = $match->invoked($invocation); - - if (!$hasReturnValue) { - $returnValue = $value; - $hasReturnValue = TRUE; - } - } - } - - catch (Exception $e) { - $exception = $e; - } - } - - if ($exception !== NULL) { - throw $exception; - } - - return $returnValue; - } - - /** - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * @return boolean - */ - public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) - { - foreach ($this->matchers as $matcher) { - if (!$matcher->matches($invocation)) { - return FALSE; - } - } - - return TRUE; - } - - /** - * @return boolean - */ - public function verify() - { - foreach ($this->matchers as $matcher) { - $matcher->verify(); - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Represents a static invocation. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Invocation_Static implements PHPUnit_Framework_MockObject_Invocation, PHPUnit_Framework_SelfDescribing -{ - /** - * @var array - */ - protected static $uncloneableExtensions = array( - 'mysqli' => TRUE, - 'SQLite' => TRUE, - 'sqlite3' => TRUE, - 'tidy' => TRUE, - 'xmlwriter' => TRUE, - 'xsl' => TRUE - ); - - /** - * @var array - */ - protected static $uncloneableClasses = array( - 'Closure', - 'COMPersistHelper', - 'IteratorIterator', - 'RecursiveIteratorIterator', - 'SplFileObject', - 'PDORow', - 'ZipArchive' - ); - - /** - * @var string - */ - public $className; - - /** - * @var string - */ - public $methodName; - - /** - * @var array - */ - public $parameters; - - /** - * @param string $className - * @param string $methodname - * @param array $parameters - * @param boolean $cloneObjects - */ - public function __construct($className, $methodName, array $parameters, $cloneObjects = FALSE) - { - $this->className = $className; - $this->methodName = $methodName; - $this->parameters = $parameters; - - if (!$cloneObjects) { - return; - } - - foreach ($this->parameters as $key => $value) { - if (is_object($value)) { - $this->parameters[$key] = $this->cloneObject($value); - } - } - } - - /** - * @return string - */ - public function toString() - { - return sprintf( - "%s::%s(%s)", - - $this->className, - $this->methodName, - join( - ', ', - array_map( - array('PHPUnit_Util_Type', 'shortenedExport'), - $this->parameters - ) - ) - ); - } - - /** - * @param object $original - * @return object - */ - protected function cloneObject($original) - { - $cloneable = NULL; - $object = new ReflectionObject($original); - - // Check the blacklist before asking PHP reflection to work around - // https://bugs.php.net/bug.php?id=53967 - if ($object->isInternal() && - isset(self::$uncloneableExtensions[$object->getExtensionName()])) { - $cloneable = FALSE; - } - - if ($cloneable === NULL) { - foreach (self::$uncloneableClasses as $class) { - if ($original instanceof $class) { - $cloneable = FALSE; - break; - } - } - } - - if ($cloneable === NULL && method_exists($object, 'isCloneable')) { - $cloneable = $object->isCloneable(); - } - - if ($cloneable === NULL && $object->hasMethod('__clone')) { - $method = $object->getMethod('__clone'); - $cloneable = $method->isPublic(); - } - - if ($cloneable === NULL) { - $cloneable = TRUE; - } - - if ($cloneable) { - try { - return clone $original; - } - - catch (Exception $e) { - return $original; - } - } else { - return $original; - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Represents a non-static invocation. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Invocation_Object extends PHPUnit_Framework_MockObject_Invocation_Static -{ - /** - * @var object - */ - public $object; - - /** - * @param string $className - * @param string $methodname - * @param array $parameters - * @param object $object - * @param object $cloneObjects - */ - public function __construct($className, $methodName, array $parameters, $object, $cloneObjects = FALSE) - { - parent::__construct($className, $methodName, $parameters, $cloneObjects); - $this->object = $object; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Stubs a method by returning a user-defined value. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Stub_Return implements PHPUnit_Framework_MockObject_Stub -{ - protected $value; - - public function __construct($value) - { - $this->value = $value; - } - - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - return $this->value; - } - - public function toString() - { - return sprintf( - 'return user-specified value %s', - - PHPUnit_Util_Type::toString($this->value) - ); - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Stubs a method by returning a user-defined value. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Stub_MatcherCollection -{ - /** - * Adds a new matcher to the collection which can be used as an expectation - * or a stub. - * - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher - * Matcher for invocations to mock objects. - */ - public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Stubs a method by returning an argument that was passed to the mocked method. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Stub_ReturnArgument extends PHPUnit_Framework_MockObject_Stub_Return -{ - protected $argumentIndex; - - public function __construct($argumentIndex) - { - $this->argumentIndex = $argumentIndex; - } - - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - if (isset($invocation->parameters[$this->argumentIndex])) { - return $invocation->parameters[$this->argumentIndex]; - } else { - return NULL; - } - } - - public function toString() - { - return sprintf('return argument #%d', $this->argumentIndex); - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @author Kris Wallsmith - * @copyright 2010 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.1.0 - */ - -/** - * Stubs a method by returning the current object. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @author Kris Wallsmith - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.1.0 - */ -class PHPUnit_Framework_MockObject_Stub_ReturnSelf implements PHPUnit_Framework_MockObject_Stub -{ - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - if (!$invocation instanceof PHPUnit_Framework_MockObject_Invocation_Object) { - throw new PHPUnit_Framework_Exception( - 'The current object can only be returned when mocking an ' . - 'object, not a static class.' - ); - } - - return $invocation->object; - } - - public function toString() - { - return 'return the current object'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Oliver Schlicht - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Stubs a method by raising a user-defined exception. - * - * @package PHPUnit_MockObject - * @author Oliver Schlicht - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Stub_Exception implements PHPUnit_Framework_MockObject_Stub -{ - protected $exception; - - public function __construct(Exception $exception) - { - $this->exception = $exception; - } - - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - throw $this->exception; - } - - public function toString() - { - return sprintf( - 'raise user-specified exception %s', - - PHPUnit_Util_Type::toString($this->exception) - ); - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Patrick Müller - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Stubs a method by returning a user-defined stack of values. - * - * @package PHPUnit_MockObject - * @author Patrick Müller - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls implements PHPUnit_Framework_MockObject_Stub -{ - protected $stack; - protected $value; - - public function __construct($stack) - { - $this->stack = $stack; - } - - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - $this->value = array_shift($this->stack); - - if ($this->value instanceof PHPUnit_Framework_MockObject_Stub) { - $this->value = $this->value->invoke($invocation); - } - - return $this->value; - } - - public function toString() - { - return sprintf( - 'return user-specified value %s', - - PHPUnit_Util_Type::toString($this->value) - ); - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Stub_ReturnCallback implements PHPUnit_Framework_MockObject_Stub -{ - protected $callback; - - public function __construct($callback) - { - $this->callback = $callback; - } - - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - return call_user_func_array($this->callback, $invocation->parameters); - } - - public function toString() - { - if (is_array($this->callback)) { - if (is_object($this->callback[0])) { - $class = get_class($this->callback[0]); - $type = '->'; - } else { - $class = $this->callback[0]; - $type = '::'; - } - - return sprintf( - 'return result of user defined callback %s%s%s() with the ' . - 'passed arguments', - - $class, - $type, - $this->callback[1] - ); - } else { - return 'return result of user defined callback ' . $this->callback . - ' with the passed arguments'; - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.1.0 - */ - -/** - * Stubs a method by returning a value from a map. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.1.0 - */ -class PHPUnit_Framework_MockObject_Stub_ReturnValueMap implements PHPUnit_Framework_MockObject_Stub -{ - protected $valueMap; - - public function __construct(array $valueMap) - { - $this->valueMap = $valueMap; - } - - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) - { - $parameterCount = count($invocation->parameters); - - foreach ($this->valueMap as $map) { - if (!is_array($map) || $parameterCount != count($map) - 1) { - continue; - } - - $return = array_pop($map); - if ($invocation->parameters === $map) { - return $return; - } - } - - return NULL; - } - - public function toString() - { - return 'return value from a map'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Interface for classes which must verify a given expectation. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Verifiable -{ - /** - * Verifies that the current expectation is valid. If everything is OK the - * code should just return, if not it must throw an exception. - * - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function verify(); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Interface for invocations. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Invocation -{ -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * An object that stubs the process of a normal method for a mock object. - * - * The stub object will replace the code for the stubbed method and return a - * specific value instead of the original value. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Stub extends PHPUnit_Framework_SelfDescribing -{ - /** - * Fakes the processing of the invocation $invocation by returning a - * specific value. - * - * @param PHPUnit_Framework_MockObject_Invocation $invocation - * The invocation which was mocked and matched by the current method - * and argument matchers. - * @return mixed - */ - public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Builder interface for parameter matchers. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Builder_ParametersMatch extends PHPUnit_Framework_MockObject_Builder_Match -{ - /** - * Sets the parameters to match for, each parameter to this funtion will - * be part of match. To perform specific matches or constraints create a - * new PHPUnit_Framework_Constraint and use it for the parameter. - * If the parameter value is not a constraint it will use the - * PHPUnit_Framework_Constraint_IsEqual for the value. - * - * Some examples: - * - * // match first parameter with value 2 - * $b->with(2); - * // match first parameter with value 'smock' and second identical to 42 - * $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42)); - * - * - * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch - */ - public function with(); - - /** - * Sets a matcher which allows any kind of parameters. - * - * Some examples: - * - * // match any number of parameters - * $b->withAnyParamers(); - * - * - * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters - */ - public function withAnyParameters(); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Builder interface for invocation order matches. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Builder_Match extends PHPUnit_Framework_MockObject_Builder_Stub -{ - /** - * Defines the expectation which must occur before the current is valid. - * - * @param string $id The identification of the expectation that should - * occur before this one. - * @return PHPUnit_Framework_MockObject_Builder_Stub - */ - public function after($id); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Builder for mocked or stubbed invocations. - * - * Provides methods for building expectations without having to resort to - * instantiating the various matchers manually. These methods also form a - * more natural way of reading the expectation. This class should be together - * with the test case PHPUnit_Framework_MockObject_TestCase. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Framework_MockObject_Builder_InvocationMocker implements PHPUnit_Framework_MockObject_Builder_MethodNameMatch -{ - /** - * @var PHPUnit_Framework_MockObject_Stub_MatcherCollection - */ - protected $collection; - - /** - * @var PHPUnit_Framework_MockObject_Matcher - */ - protected $matcher; - - /** - * @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher - */ - public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher) - { - $this->collection = $collection; - $this->matcher = new PHPUnit_Framework_MockObject_Matcher( - $invocationMatcher - ); - - $this->collection->addMatcher($this->matcher); - } - - /** - * @return PHPUnit_Framework_MockObject_Matcher - */ - public function getMatcher() - { - return $this->matcher; - } - - /** - * @param mixed $id - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function id($id) - { - $this->collection->registerId($id, $this); - - return $this; - } - - /** - * @param PHPUnit_Framework_MockObject_Stub $stub - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function will(PHPUnit_Framework_MockObject_Stub $stub) - { - $this->matcher->stub = $stub; - - return $this; - } - - /** - * @param mixed $id - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function after($id) - { - $this->matcher->afterMatchBuilderId = $id; - - return $this; - } - - /** - * @param mixed $argument, ... - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function with() - { - $args = func_get_args(); - - if ($this->matcher->methodNameMatcher === NULL) { - throw new PHPUnit_Framework_Exception( - 'Method name matcher is not defined, cannot define parameter ' . - ' matcher without one' - ); - } - - if ($this->matcher->parametersMatcher !== NULL) { - throw new PHPUnit_Framework_Exception( - 'Parameter matcher is already defined, cannot redefine' - ); - } - - $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($args); - - return $this; - } - - /** - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function withAnyParameters() - { - if ($this->matcher->methodNameMatcher === NULL) { - throw new PHPUnit_Framework_Exception( - 'Method name matcher is not defined, cannot define parameter ' . - 'matcher without one' - ); - } - - if ($this->matcher->parametersMatcher !== NULL) { - throw new PHPUnit_Framework_Exception( - 'Parameter matcher is already defined, cannot redefine' - ); - } - - $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters; - - return $this; - } - - /** - * @param PHPUnit_Framework_Constraint|string $constraint - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function method($constraint) - { - if ($this->matcher->methodNameMatcher !== NULL) { - throw new PHPUnit_Framework_Exception( - 'Method name matcher is already defined, cannot redefine' - ); - } - - $this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint); - - return $this; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Interface for builders which can register builders with a given identification. - * - * This interface relates to PHPUnit_Framework_MockObject_Builder_Identity. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Builder_Namespace -{ - /** - * Looks up the match builder with identification $id and returns it. - * - * @param string $id The identifiction of the match builder. - * @return PHPUnit_Framework_MockObject_Builder_Match - */ - public function lookupId($id); - - /** - * Registers the match builder $builder with the identification $id. The - * builder can later be looked up using lookupId() to figure out if it - * has been invoked. - * - * @param string $id - * The identification of the match builder. - * @param PHPUnit_Framework_MockObject_Builder_Match $builder - * The builder which is being registered. - */ - public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Builder interface for matcher of method names. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Builder_MethodNameMatch extends PHPUnit_Framework_MockObject_Builder_ParametersMatch -{ - /** - * Adds a new method name match and returns the parameter match object for - * further matching possibilities. - * - * @param PHPUnit_Framework_Constraint $name - * Constraint for matching method, if a string is passed it will use - * the PHPUnit_Framework_Constraint_IsEqual. - * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch - */ - public function method($name); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Builder interface for unique identifiers. - * - * Defines the interface for recording unique identifiers. The identifiers - * can be used to define the invocation order of expectations. The expectation - * is recorded using id() and then defined in order using - * PHPUnit_Framework_MockObject_Builder_Match::after(). - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Builder_Identity -{ - /** - * Sets the identification of the expectation to $id. - * - * @note The identifier is unique per mock object. - * @param string $id Unique identifiation of expectation. - */ - public function id($id); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Builder interface for stubs which are actions replacing an invocation. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_Builder_Stub extends PHPUnit_Framework_MockObject_Builder_Identity -{ - /** - * Stubs the matching method with the stub object $stub. Any invocations of - * the matched method will now be handled by the stub instead. - * - * @param PHPUnit_Framework_MockObject_Stub $stub The stub object. - * @return PHPUnit_Framework_MockObject_Builder_Identity - */ - public function will(PHPUnit_Framework_MockObject_Stub $stub); -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since File available since Release 1.0.0 - */ - -/** - * Interface for all mock objects which are generated by - * PHPUnit_Framework_MockObject_Mock. - * - * @package PHPUnit_MockObject - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.2.3 - * @link http://github.com/sebastianbergmann/phpunit-mock-objects - * @since Interface available since Release 1.0.0 - */ -interface PHPUnit_Framework_MockObject_MockObject /*extends PHPUnit_Framework_MockObject_Verifiable*/ -{ - /** - * Registers a new expectation in the mock object and returns the match - * object which can be infused with further details. - * - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); - - /** - * Registers a new static expectation in the mock object and returns the - * match object which can be infused with further details. - * - * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher - * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker - */ - public static function staticExpects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); - - /** - * @return PHPUnit_Framework_MockObject_InvocationMocker - */ - public function __phpunit_getInvocationMocker(); - - /** - * @return PHPUnit_Framework_MockObject_InvocationMocker - */ - public static function __phpunit_getStaticInvocationMocker(); - - /** - * Verifies that the current expectation is valid. If everything is OK the - * code should just return, if not it must throw an exception. - * - * @throws PHPUnit_Framework_ExpectationFailedException - */ - public function __phpunit_verify(); -} -PHPUnit_MockObject 1.2 -====================== - -This is the list of changes for the PHPUnit_MockObject 1.2 release series. - -PHPUnit_MockObject 1.2.3 ------------------------- - -* Fixed a bug where getting two mocks with different argument cloning options returned the same mock. - -PHPUnit_MockObject 1.2.2 ------------------------- - -* Fixed #100: Removed the unique mock object ID introduced in version 1.2. - -PHPUnit_MockObject 1.2.1 ------------------------- - -* No changes. - -PHPUnit_MockObject 1.2.0 ------------------------- - -* Implemented #47: Make cloning of arguments passed to mocked methods optional. -* Implemented #84: `getMockFromWsdl()` now works with namespaces. -* Fixed #90: Mocks with a fixed class name could only be created once. - -PHPUnit_Selenium - -Copyright (c) 2002-2013, Sebastian Bergmann . -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - * Neither the name of Sebastian Bergmann nor the names of his - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, -INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, -BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -POSSIBILITY OF SUCH DAMAGE. -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.2 - */ - -/** - * TestSuite class for Selenium 1 tests - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.0 - */ -class PHPUnit_Extensions_SeleniumTestSuite extends PHPUnit_Framework_TestSuite -{ - /** - * Overriding the default: Selenium suites are always built from a TestCase class. - * @var boolean - */ - protected $testCase = TRUE; - - /** - * Making the method public. - */ - public function addTestMethod(ReflectionClass $class, ReflectionMethod $method) - { - return parent::addTestMethod($class, $method); - } - - /** - * @param string $className extending PHPUnit_Extensions_SeleniumTestCase - * @return PHPUnit_Extensions_SeleniumTestSuite - */ - public static function fromTestCaseClass($className) - { - $suite = new self(); - $suite->setName($className); - - $class = new ReflectionClass($className); - $classGroups = PHPUnit_Util_Test::getGroups($className); - $staticProperties = $class->getStaticProperties(); - - //BC: renamed seleneseDirectory -> selenesePath - if (!isset($staticProperties['selenesePath']) && isset($staticProperties['seleneseDirectory'])) { - $staticProperties['selenesePath'] = $staticProperties['seleneseDirectory']; - } - - // Create tests from Selenese/HTML files. - if (isset($staticProperties['selenesePath']) && - (is_dir($staticProperties['selenesePath']) || is_file($staticProperties['selenesePath']))) { - - if (is_dir($staticProperties['selenesePath'])) { - $files = array_merge( - self::getSeleneseFiles($staticProperties['selenesePath'], '.htm'), - self::getSeleneseFiles($staticProperties['selenesePath'], '.html') - ); - } else { - $files[] = realpath($staticProperties['selenesePath']); - } - - // Create tests from Selenese/HTML files for multiple browsers. - if (!empty($staticProperties['browsers'])) { - foreach ($staticProperties['browsers'] as $browser) { - $browserSuite = PHPUnit_Extensions_SeleniumBrowserSuite::fromClassAndBrowser($className, $browser); - - foreach ($files as $file) { - self::addGeneratedTestTo($browserSuite, - new $className($file, array(), '', $browser), - $classGroups - ); - } - - $suite->addTest($browserSuite); - } - } - else { - // Create tests from Selenese/HTML files for single browser. - foreach ($files as $file) { - self::addGeneratedTestTo($suite, - new $className($file), - $classGroups); - } - } - } - - // Create tests from test methods for multiple browsers. - if (!empty($staticProperties['browsers'])) { - foreach ($staticProperties['browsers'] as $browser) { - $browserSuite = PHPUnit_Extensions_SeleniumBrowserSuite::fromClassAndBrowser($className, $browser); - foreach ($class->getMethods() as $method) { - $browserSuite->addTestMethod($class, $method); - } - $browserSuite->setupSpecificBrowser($browser); - - $suite->addTest($browserSuite); - } - } - else { - // Create tests from test methods for single browser. - foreach ($class->getMethods() as $method) { - $suite->addTestMethod($class, $method); - } - } - - return $suite; - } - - private static function addGeneratedTestTo(PHPUnit_Framework_TestSuite $suite, PHPUnit_Framework_TestCase $test, $classGroups) - { - list ($methodName, ) = explode(' ', $test->getName()); - $test->setDependencies( - PHPUnit_Util_Test::getDependencies(get_class($test), $methodName) - ); - $suite->addTest($test, $classGroups); - } - - /** - * @param string $directory - * @param string $suffix - * @return array - */ - private static function getSeleneseFiles($directory, $suffix) - { - $facade = new File_Iterator_Facade; - - return $facade->getFilesAsArray($directory, $suffix); - } - -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.0 - */ - -/** - * TestCase class that uses Selenium 2 - * (WebDriver API and JsonWire protocol) to provide - * the functionality required for web testing. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.0 - * @method void acceptAlert() Press OK on an alert, or confirms a dialog - * @method mixed alertText() alertText($value = NULL) Gets the alert dialog text, or sets the text for a prompt dialog - * @method void back() - * @method \PHPUnit_Extensions_Selenium2TestCase_Element byClassName() byClassName($value) - * @method \PHPUnit_Extensions_Selenium2TestCase_Element byCssSelector() byCssSelector($value) - * @method \PHPUnit_Extensions_Selenium2TestCase_Element byId() byId($value) - * @method \PHPUnit_Extensions_Selenium2TestCase_Element byLinkText() byLinkText($value) - * @method \PHPUnit_Extensions_Selenium2TestCase_Element byName() byName($value) - * @method \PHPUnit_Extensions_Selenium2TestCase_Element byTag() byTag($value) - * @method \PHPUnit_Extensions_Selenium2TestCase_Element byXPath() byXPath($value) - * @method void click() click(int $button = 0) Click any mouse button (at the coordinates set by the last moveto command). - * @method void clickOnElement() clickOnElement($id) - * @method string currentScreenshot() BLOB of the image file - * @method void dismissAlert() Press Cancel on an alert, or does not confirm a dialog - * @method \PHPUnit_Extensions_Selenium2TestCase_Element element() element(\PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria) Retrieves an element - * @method array elements() elements(\PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria) Retrieves an array of Element instances - * @method string execute() execute($javaScriptCode) Injects arbitrary JavaScript in the page and returns the last - * @method string executeAsync() executeAsync($javaScriptCode) Injects arbitrary JavaScript and wait for the callback (last element of arguments) to be called - * @method void forward() - * @method void frame() frame(mixed $element) Changes the focus to a frame in the page (by frameCount of type int, htmlId of type string, htmlName of type string or element of type \PHPUnit_Extensions_Selenium2TestCase_Element) - * @method void moveto() moveto(\PHPUnit_Extensions_Selenium2TestCase_Element $element) Move the mouse by an offset of the specificed element. - * @method void refresh() - * @method \PHPUnit_Extensions_Selenium2TestCase_Element_Select select() select($element) - * @method string source() Returns the HTML source of the page - * @method \PHPUnit_Extensions_Selenium2TestCase_Session_Timeouts timeouts() - * @method string title() - * @method void|string url() url($url = NULL) - * @method PHPUnit_Extensions_Selenium2TestCase_ElementCriteria using() using($strategy) Factory Method for Criteria objects - * @method void window() window($name) Changes the focus to another window - * @method string windowHandle() Retrieves the current window handle - * @method string windowHandles() Retrieves a list of all available window handles - * @method string keys() Send a sequence of key strokes to the active element. - * @method void closeWindow() Close the current window. - */ -abstract class PHPUnit_Extensions_Selenium2TestCase extends PHPUnit_Framework_TestCase -{ - const VERSION = '1.3.1'; - - /** - * @var string override to provide code coverage data from the server - */ - protected $coverageScriptUrl; - - /** - * @var PHPUnit_Extensions_Selenium2TestCase_Session - */ - private $session; - - /** - * @var array - */ - private $parameters; - - /** - * @var PHPUnit_Extensions_Selenium2TestCase_SessionStrategy - */ - protected static $sessionStrategy; - - /** - * @var PHPUnit_Extensions_Selenium2TestCase_SessionStrategy - */ - protected static $browserSessionStrategy; - - /** - * @var PHPUnit_Extensions_Selenium2TestCase_SessionStrategy - */ - protected $localSessionStrategy; - - /** - * @var array - */ - private static $lastBrowserParams; - - /** - * @var string - */ - private $testId; - - /** - * @var boolean - */ - private $collectCodeCoverageInformation; - - /** - * @var PHPUnit_Extensions_Selenium2TestCase_KeysHolder - */ - private $keysHolder; - - /** - * @param boolean - */ - public static function shareSession($shareSession) - { - if (!is_bool($shareSession)) { - throw new InvalidArgumentException("The shared session support can only be switched on or off."); - } - if (!$shareSession) { - self::$sessionStrategy = self::defaultSessionStrategy(); - } else { - self::$sessionStrategy = new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Shared(self::defaultSessionStrategy()); - } - } - - private static function sessionStrategy() - { - if (!self::$sessionStrategy) { - self::$sessionStrategy = self::defaultSessionStrategy(); - } - return self::$sessionStrategy; - } - - private static function defaultSessionStrategy() - { - return new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Isolated; - } - - public function __construct($name = NULL, array $data = array(), $dataName = '') - { - parent::__construct($name, $data, $dataName); - $this->parameters = array( - 'host' => 'localhost', - 'port' => 4444, - 'browser' => NULL, - 'browserName' => NULL, - 'desiredCapabilities' => array(), - 'seleniumServerRequestsTimeout' => 60 - ); - - $this->keysHolder = new PHPUnit_Extensions_Selenium2TestCase_KeysHolder(); - } - - public function setupSpecificBrowser($params) - { - $this->setUpSessionStrategy($params); - $params = array_merge($this->parameters, $params); - $this->setHost($params['host']); - $this->setPort($params['port']); - $this->setBrowser($params['browserName']); - $this->parameters['browser'] = $params['browser']; - $this->setDesiredCapabilities($params['desiredCapabilities']); - $this->setSeleniumServerRequestsTimeout( - $params['seleniumServerRequestsTimeout']); - } - - protected function setUpSessionStrategy($params) - { - // This logic enables us to have a session strategy reused for each - // item in self::$browsers. We don't want them both to share one - // and we don't want each test for a specific browser to have a - // new strategy - if ($params == self::$lastBrowserParams) { - // do nothing so we use the same session strategy for this - // browser - } elseif (isset($params['sessionStrategy'])) { - $strat = $params['sessionStrategy']; - if ($strat != "isolated" && $strat != "shared") { - throw new InvalidArgumentException("Session strategy must be either 'isolated' or 'shared'"); - } elseif ($strat == "isolated") { - self::$browserSessionStrategy = new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Isolated; - } else { - self::$browserSessionStrategy = new PHPUnit_Extensions_Selenium2TestCase_SessionStrategy_Shared(self::defaultSessionStrategy()); - } - } else { - self::$browserSessionStrategy = self::defaultSessionStrategy(); - } - self::$lastBrowserParams = $params; - $this->localSessionStrategy = self::$browserSessionStrategy; - - } - - private function getStrategy() - { - if ($this->localSessionStrategy) - return $this->localSessionStrategy; - else - return self::sessionStrategy(); - } - - public function prepareSession() - { - try { - if (!$this->session) { - $this->session = $this->getStrategy()->session($this->parameters); - } - } catch (PHPUnit_Extensions_Selenium2TestCase_NoSeleniumException $e) { - $this->markTestSkipped("The Selenium Server is not active on host {$this->parameters['host']} at port {$this->parameters['port']}."); - } - return $this->session; - } - - public function run(PHPUnit_Framework_TestResult $result = NULL) - { - $this->testId = get_class($this) . '__' . $this->getName(); - - if ($result === NULL) { - $result = $this->createResult(); - } - - - $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation(); - - parent::run($result); - - if ($this->collectCodeCoverageInformation) { - $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage( - $this->coverageScriptUrl, - $this->testId - ); - $result->getCodeCoverage()->append( - $coverage->get(), $this - ); - } - - // do not call this before to give the time to the Listeners to run - $this->getStrategy()->endOfTest($this->session); - - return $result; - } - - /** - * @throws RuntimeException - */ - protected function runTest() - { - $this->prepareSession(); - - $thrownException = NULL; - - if ($this->collectCodeCoverageInformation) { - $this->session->cookie()->remove('PHPUNIT_SELENIUM_TEST_ID'); - $this->session->cookie()->add('PHPUNIT_SELENIUM_TEST_ID', $this->testId)->set(); - } - - try { - $this->setUpPage(); - $result = parent::runTest(); - - if (!empty($this->verificationErrors)) { - $this->fail(implode("\n", $this->verificationErrors)); - } - } catch (Exception $e) { - $thrownException = $e; - } - - - if (NULL !== $thrownException) { - throw $thrownException; - } - - return $result; - } - - - public static function suite($className) - { - return PHPUnit_Extensions_SeleniumTestSuite::fromTestCaseClass($className); - } - - public function onNotSuccessfulTest(Exception $e) - { - $this->getStrategy()->notSuccessfulTest(); - parent::onNotSuccessfulTest($e); - } - - /** - * Delegate method calls to the Session. - * - * @param string $command - * @param array $arguments - * @return mixed - */ - public function __call($command, $arguments) - { - if ($this->session === NULL) { - throw new PHPUnit_Extensions_Selenium2TestCase_Exception("There is currently no active session to execute the '$command' command. You're probably trying to set some option in setUp() with an incorrect setter name. You may consider using setUpPage() instead."); - } - $result = call_user_func_array( - array($this->session, $command), $arguments - ); - - return $result; - } - - /** - * @param string $host - * @throws InvalidArgumentException - */ - public function setHost($host) - { - if (!is_string($host)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $this->parameters['host'] = $host; - } - - public function getHost() - { - return $this->parameters['host']; - } - - /** - * @param integer $port - * @throws InvalidArgumentException - */ - public function setPort($port) - { - if (!is_int($port)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); - } - - $this->parameters['port'] = $port; - } - - public function getPort() - { - return $this->parameters['port']; - } - - /** - * @param string $browser - * @throws InvalidArgumentException - */ - public function setBrowser($browserName) - { - if (!is_string($browserName)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $this->parameters['browserName'] = $browserName; - } - - public function getBrowser() - { - return $this->parameters['browserName']; - } - - /** - * @param string $browserUrl - * @throws InvalidArgumentException - */ - public function setBrowserUrl($browserUrl) - { - if (!is_string($browserUrl)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $this->parameters['browserUrl'] = new PHPUnit_Extensions_Selenium2TestCase_URL($browserUrl); - } - - public function getBrowserUrl() - { - if (isset($this->parameters['browserUrl'])) { - return $this->parameters['browserUrl']; - } - return ''; - } - - /** - * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol - */ - public function setDesiredCapabilities(array $capabilities) - { - $this->parameters['desiredCapabilities'] = $capabilities; - } - - - public function getDesiredCapabilities() - { - return $this->parameters['desiredCapabilities']; - } - - /** - * @param int $timeout seconds - */ - public function setSeleniumServerRequestsTimeout($timeout) - { - $this->parameters['seleniumServerRequestsTimeout'] = $timeout; - } - - public function getSeleniumServerRequestsTimeout() - { - return $this->parameters['seleniumServerRequestsTimeout']; - } - - /** - * Get test id (generated internally) - * @return string - */ - public function getTestId() - { - return $this->testId; - } - - /** - * Get Selenium2 current session id - * @return string - */ - public function getSessionId() - { - if ($this->session) - return $this->session->id(); - - return FALSE; - } - - /** - * Wait until callback isn't null or timeout occurs - * - * @param $callback - * @param null $timeout - * @return mixed - */ - public function waitUntil($callback, $timeout = null) - { - $waitUntil = new PHPUnit_Extensions_Selenium2TestCase_WaitUntil($this); - return $waitUntil->run($callback, $timeout); - } - - /** - * Sends a special key - * Deprecated due to issues with IE webdriver. Use keys() method instead - * @deprecated - * @param string $name - * @throws PHPUnit_Extensions_Selenium2TestCase_Exception - * @see PHPUnit_Extensions_Selenium2TestCase_KeysHolder - */ - public function keysSpecial($name) - { - $names = explode(',', $name); - - foreach ($names as $key) { - $this->keys($this->keysHolder->specialKey(trim($key))); - } - } - - /** - * setUp method that is called after the session has been prepared. - * It is possible to use session-specific commands like url() here. - */ - public function setUpPage() - { - - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.0.0 - */ - -/** - * Implementation of the Selenium RC client/server protocol. - * - * @package PHPUnit_Selenium - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.0.0 - */ -class PHPUnit_Extensions_SeleniumTestCase_Driver -{ - /** - * @var PHPUnit_Extensions_SeleniumTestCase - */ - protected $testCase; - - /** - * @var string - */ - protected $testId; - - /** - * @var string - */ - protected $name; - - /** - * @var string - */ - protected $browser; - - /** - * @var string - */ - protected $browserUrl; - - /** - * @var boolean - */ - protected $collectCodeCoverageInformation = FALSE; - - /** - * @var string - */ - protected $host = 'localhost'; - - /** - * @var integer - */ - protected $port = 4444; - - /** - * @var integer - */ - protected $httpTimeout = 45; - - /** - * @var integer - */ - protected $seleniumTimeout = 30; - - /** - * @var string - */ - protected $sessionId; - - /** - * @var integer - */ - protected $sleep = 0; - - /** - * @var boolean - */ - protected $useWaitForPageToLoad = TRUE; - - /** - * @var boolean - */ - protected $wait = 5; - - /** - * @var array - */ - protected static $autoGeneratedCommands = array(); - - /** - * @var array - */ - protected $commands = array(); - - /** - * @var array $userCommands A numerical array which holds custom user commands. - */ - protected $userCommands = array(); - - /** - * @var array - */ - protected $verificationErrors = array(); - - /** - * @var array - */ - private $webDriverCapabilities; - - public function __construct() - { - if (empty(self::$autoGeneratedCommands)) { - self::autoGenerateCommands(); - } - } - - /** - * Only browserName is supported. - */ - public function setWebDriverCapabilities(array $capabilities) - { - $this->webDriverCapabilities = $capabilities; - } - - /** - * @return string - */ - public function start() - { - if ($this->browserUrl == NULL) { - throw new PHPUnit_Framework_Exception( - 'setBrowserUrl() needs to be called before start().' - ); - } - - if ($this->webDriverCapabilities !== NULL) { - $seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($this->host, $this->port); - $driver = new PHPUnit_Extensions_Selenium2TestCase_Driver($seleniumServerUrl); - $session = $driver->startSession($this->webDriverCapabilities, new PHPUnit_Extensions_Selenium2TestCase_URL($this->browserUrl)); - $webDriverSessionId = $session->id(); - $this->sessionId = $this->getString( - 'getNewBrowserSession', - array($this->browser, $this->browserUrl, '', - "webdriver.remote.sessionid=$webDriverSessionId") - ); - - $this->doCommand('setTimeout', array($this->seleniumTimeout * 1000)); - } - - if (!isset($this->sessionId)) { - $this->sessionId = $this->getString( - 'getNewBrowserSession', - array($this->browser, $this->browserUrl) - ); - - $this->doCommand('setTimeout', array($this->seleniumTimeout * 1000)); - } - - return $this->sessionId; - } - - /** - * @return string - * @since Method available since Release 1.1.0 - */ - public function getSessionId() - { - return $this->sessionId; - } - - /** - * @param string - * @since Method available since Release 1.2.0 - */ - public function setSessionId($sessionId) - { - $this->sessionId = $sessionId; - } - - /** - */ - public function stop() - { - if (!isset($this->sessionId)) { - return; - } - - $this->doCommand('testComplete'); - - $this->sessionId = NULL; - } - - /** - * @param boolean $flag - * @throws InvalidArgumentException - */ - public function setCollectCodeCoverageInformation($flag) - { - if (!is_bool($flag)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean'); - } - - $this->collectCodeCoverageInformation = $flag; - } - - /** - * @param PHPUnit_Extensions_SeleniumTestCase $testCase - */ - public function setTestCase(PHPUnit_Extensions_SeleniumTestCase $testCase) - { - $this->testCase = $testCase; - } - - /** - * @param integer $testId - */ - public function setTestId($testId) - { - $this->testId = $testId; - } - - /** - * @param string $name - * @throws InvalidArgumentException - */ - public function setName($name) - { - if (!is_string($name)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $this->name = $name; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $browser - * @throws InvalidArgumentException - */ - public function setBrowser($browser) - { - if (!is_string($browser)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $this->browser = $browser; - } - - /** - * @return string - */ - public function getBrowser() - { - return $this->browser; - } - - /** - * @param string $browserUrl - * @throws InvalidArgumentException - */ - public function setBrowserUrl($browserUrl) - { - if (!is_string($browserUrl)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $this->browserUrl = $browserUrl; - } - - /** - * @param string $host - * @throws InvalidArgumentException - */ - public function setHost($host) - { - if (!is_string($host)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - - $this->host = $host; - } - - /** - * @return string - * @since Method available since Release 1.1.0 - */ - public function getHost() - { - return $this->host; - } - - /** - * @param integer $port - * @throws InvalidArgumentException - */ - public function setPort($port) - { - if (!is_int($port)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); - } - - $this->port = $port; - } - - /** - * @return integer - * @since Method available since Release 1.1.0 - */ - public function getPort() - { - return $this->port; - } - - /** - * @param integer $timeout for Selenium RC in seconds - * @throws InvalidArgumentException - */ - public function setTimeout($timeout) - { - if (!is_int($timeout)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); - } - - $this->seleniumTimeout = $timeout; - } - - /** - * @param integer $timeout for HTTP connection to Selenium RC in seconds - * @throws InvalidArgumentException - */ - public function setHttpTimeout($timeout) - { - if (!is_int($timeout)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); - } - - $this->httpTimeout = $timeout; - } - - /** - * @param integer $seconds - * @throws InvalidArgumentException - */ - public function setSleep($seconds) - { - if (!is_int($seconds)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); - } - - $this->sleep = $seconds; - } - - /** - * Sets the number of seconds to sleep() after *AndWait commands - * when setWaitForPageToLoad(FALSE) is used. - * - * @param integer $seconds - * @throws InvalidArgumentException - */ - public function setWait($seconds) - { - if (!is_int($seconds)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer'); - } - - $this->wait = $seconds; - } - - /** - * Sets whether waitForPageToLoad (TRUE) or sleep() (FALSE) - * is used after *AndWait commands. - * - * @param boolean $flag - * @throws InvalidArgumentException - */ - public function setWaitForPageToLoad($flag) - { - if (!is_bool($flag)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean'); - } - - $this->useWaitForPageToLoad = $flag; - } - - /** - * Adds allowed user commands into {@link self::$userCommands}. See - * {@link self::__call()} (switch/case -> default) for usage. - * - * @param string $command A command. - * - * @return $this - * @see self::__call() - */ - public function addUserCommand($command) - { - if (!is_string($command)) { - throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); - } - $this->userCommands[] = $command; - return $this; - } - - /** - * This method implements the Selenium RC protocol. - * - * @param string $command - * @param array $arguments - * @return mixed - * @method unknown addLocationStrategy() - * @method unknown addLocationStrategyAndWait() - * @method unknown addScript() - * @method unknown addScriptAndWait() - * @method unknown addSelection() - * @method unknown addSelectionAndWait() - * @method unknown allowNativeXpath() - * @method unknown allowNativeXpathAndWait() - * @method unknown altKeyDown() - * @method unknown altKeyDownAndWait() - * @method unknown altKeyUp() - * @method unknown altKeyUpAndWait() - * @method unknown answerOnNextPrompt() - * @method unknown assignId() - * @method unknown assignIdAndWait() - * @method unknown attachFile() - * @method unknown break() - * @method unknown captureEntirePageScreenshot() - * @method unknown captureEntirePageScreenshotAndWait() - * @method unknown captureEntirePageScreenshotToStringAndWait() - * @method unknown captureScreenshotAndWait() - * @method unknown captureScreenshotToStringAndWait() - * @method unknown check() - * @method unknown checkAndWait() - * @method unknown chooseCancelOnNextConfirmation() - * @method unknown chooseCancelOnNextConfirmationAndWait() - * @method unknown chooseOkOnNextConfirmation() - * @method unknown chooseOkOnNextConfirmationAndWait() - * @method unknown click() - * @method unknown clickAndWait() - * @method unknown clickAt() - * @method unknown clickAtAndWait() - * @method unknown close() - * @method unknown contextMenu() - * @method unknown contextMenuAndWait() - * @method unknown contextMenuAt() - * @method unknown contextMenuAtAndWait() - * @method unknown controlKeyDown() - * @method unknown controlKeyDownAndWait() - * @method unknown controlKeyUp() - * @method unknown controlKeyUpAndWait() - * @method unknown createCookie() - * @method unknown createCookieAndWait() - * @method unknown deleteAllVisibleCookies() - * @method unknown deleteAllVisibleCookiesAndWait() - * @method unknown deleteCookie() - * @method unknown deleteCookieAndWait() - * @method unknown deselectPopUp() - * @method unknown deselectPopUpAndWait() - * @method unknown doubleClick() - * @method unknown doubleClickAndWait() - * @method unknown doubleClickAt() - * @method unknown doubleClickAtAndWait() - * @method unknown dragAndDrop() - * @method unknown dragAndDropAndWait() - * @method unknown dragAndDropToObject() - * @method unknown dragAndDropToObjectAndWait() - * @method unknown dragDrop() - * @method unknown dragDropAndWait() - * @method unknown echo() - * @method unknown fireEvent() - * @method unknown fireEventAndWait() - * @method unknown focus() - * @method unknown focusAndWait() - * @method string getAlert() - * @method array getAllButtons() - * @method array getAllFields() - * @method array getAllLinks() - * @method array getAllWindowIds() - * @method array getAllWindowNames() - * @method array getAllWindowTitles() - * @method string getAttribute(string $attributeLocator) - * @method array getAttributeFromAllWindows(string $attributeName) - * @method string getBodyText() - * @method string getConfirmation() - * @method string getCookie() - * @method string getCookieByName(string $name) - * @method integer getCssCount(string $locator) - * @method integer getCursorPosition(string $locator) - * @method integer getElementHeight(string $locator) - * @method integer getElementIndex(string $locator) - * @method integer getElementPositionLeft(string $locator) - * @method integer getElementPositionTop(string $locator) - * @method integer getElementWidth(string $locator) - * @method string getEval(string $script) - * @method string getExpression(string $expression) - * @method string getHtmlSource() - * @method string getLocation() - * @method string getLogMessages() - * @method integer getMouseSpeed() - * @method string getPrompt() - * @method array getSelectOptions(string $selectLocator) - * @method string getSelectedId(string $selectLocator) - * @method array getSelectedIds(string $selectLocator) - * @method string getSelectedIndex(string $selectLocator) - * @method array getSelectedIndexes(string $selectLocator) - * @method string getSelectedLabel(string $selectLocator) - * @method array getSelectedLabels(string $selectLocator) - * @method string getSelectedValue(string $selectLocator) - * @method array getSelectedValues(string $selectLocator) - * @method unknown getSpeed() - * @method unknown getSpeedAndWait() - * @method string getTable(string $tableCellAddress) - * @method string getText(string $locator) - * @method string getTitle() - * @method string getValue(string $locator) - * @method boolean getWhetherThisFrameMatchFrameExpression(string $currentFrameString, string $target) - * @method boolean getWhetherThisWindowMatchWindowExpression(string $currentWindowString, string $target) - * @method integer getXpathCount(string $xpath) - * @method unknown goBack() - * @method unknown goBackAndWait() - * @method unknown highlight(string $locator) - * @method unknown highlightAndWait(string $locator) - * @method unknown ignoreAttributesWithoutValue(string $ignore) - * @method unknown ignoreAttributesWithoutValueAndWait(string $ignore) - * @method boolean isAlertPresent() - * @method boolean isChecked(locator) - * @method boolean isConfirmationPresent() - * @method boolean isCookiePresent(string $name) - * @method boolean isEditable(string $locator) - * @method boolean isElementPresent(string $locator) - * @method boolean isOrdered(string $locator1, string $locator2) - * @method boolean isPromptPresent() - * @method boolean isSomethingSelected(string $selectLocator) - * @method boolean isTextPresent(pattern) - * @method boolean isVisible(locator) - * @method unknown keyDown() - * @method unknown keyDownAndWait() - * @method unknown keyDownNative() - * @method unknown keyDownNativeAndWait() - * @method unknown keyPress() - * @method unknown keyPressAndWait() - * @method unknown keyPressNative() - * @method unknown keyPressNativeAndWait() - * @method unknown keyUp() - * @method unknown keyUpAndWait() - * @method unknown keyUpNative() - * @method unknown keyUpNativeAndWait() - * @method unknown metaKeyDown() - * @method unknown metaKeyDownAndWait() - * @method unknown metaKeyUp() - * @method unknown metaKeyUpAndWait() - * @method unknown mouseDown() - * @method unknown mouseDownAndWait() - * @method unknown mouseDownAt() - * @method unknown mouseDownAtAndWait() - * @method unknown mouseMove() - * @method unknown mouseMoveAndWait() - * @method unknown mouseMoveAt() - * @method unknown mouseMoveAtAndWait() - * @method unknown mouseOut() - * @method unknown mouseOutAndWait() - * @method unknown mouseOver() - * @method unknown mouseOverAndWait() - * @method unknown mouseUp() - * @method unknown mouseUpAndWait() - * @method unknown mouseUpAt() - * @method unknown mouseUpAtAndWait() - * @method unknown mouseUpRight() - * @method unknown mouseUpRightAndWait() - * @method unknown mouseUpRightAt() - * @method unknown mouseUpRightAtAndWait() - * @method unknown open() - * @method unknown openWindow() - * @method unknown openWindowAndWait() - * @method unknown pause() - * @method unknown refresh() - * @method unknown refreshAndWait() - * @method unknown removeAllSelections() - * @method unknown removeAllSelectionsAndWait() - * @method unknown removeScript() - * @method unknown removeScriptAndWait() - * @method unknown removeSelection() - * @method unknown removeSelectionAndWait() - * @method unknown retrieveLastRemoteControlLogs() - * @method unknown rollup() - * @method unknown rollupAndWait() - * @method unknown runScript() - * @method unknown runScriptAndWait() - * @method unknown select() - * @method unknown selectAndWait() - * @method unknown selectFrame() - * @method unknown selectPopUp() - * @method unknown selectPopUpAndWait() - * @method unknown selectWindow() - * @method unknown setBrowserLogLevel() - * @method unknown setBrowserLogLevelAndWait() - * @method unknown setContext() - * @method unknown setCursorPosition() - * @method unknown setCursorPositionAndWait() - * @method unknown setMouseSpeed() - * @method unknown setMouseSpeedAndWait() - * @method unknown setSpeed() - * @method unknown setSpeedAndWait() - * @method unknown shiftKeyDown() - * @method unknown shiftKeyDownAndWait() - * @method unknown shiftKeyUp() - * @method unknown shiftKeyUpAndWait() - * @method unknown shutDownSeleniumServer() - * @method unknown store() - * @method unknown submit() - * @method unknown submitAndWait() - * @method unknown type() - * @method unknown typeAndWait() - * @method unknown typeKeys() - * @method unknown typeKeysAndWait() - * @method unknown uncheck() - * @method unknown uncheckAndWait() - * @method unknown useXpathLibrary() - * @method unknown useXpathLibraryAndWait() - * @method unknown waitForCondition() - * @method unknown waitForElementPresent() - * @method unknown waitForElementNotPresent() - * @method unknown waitForPageToLoad() - * @method unknown waitForPopUp() - * @method unknown windowFocus() - * @method unknown windowMaximize() - */ - public function __call($command, $arguments) - { - $arguments = $this->preprocessParameters($arguments); - - $wait = FALSE; - - if (substr($command, -7, 7) == 'AndWait') { - $command = substr($command, 0, -7); - $wait = TRUE; - } - - switch ($command) { - case 'addLocationStrategy': - case 'addScript': - case 'addSelection': - case 'allowNativeXpath': - case 'altKeyDown': - case 'altKeyUp': - case 'answerOnNextPrompt': - case 'assignId': - case 'attachFile': - case 'break': - case 'captureEntirePageScreenshot': - case 'captureScreenshot': - case 'check': - case 'chooseCancelOnNextConfirmation': - case 'chooseOkOnNextConfirmation': - case 'click': - case 'clickAt': - case 'close': - case 'contextMenu': - case 'contextMenuAt': - case 'controlKeyDown': - case 'controlKeyUp': - case 'createCookie': - case 'deleteAllVisibleCookies': - case 'deleteCookie': - case 'deselectPopUp': - case 'doubleClick': - case 'doubleClickAt': - case 'dragAndDrop': - case 'dragAndDropToObject': - case 'dragDrop': - case 'echo': - case 'fireEvent': - case 'focus': - case 'goBack': - case 'highlight': - case 'ignoreAttributesWithoutValue': - case 'keyDown': - case 'keyDownNative': - case 'keyPress': - case 'keyPressNative': - case 'keyUp': - case 'keyUpNative': - case 'metaKeyDown': - case 'metaKeyUp': - case 'mouseDown': - case 'mouseDownAt': - case 'mouseMove': - case 'mouseMoveAt': - case 'mouseOut': - case 'mouseOver': - case 'mouseUp': - case 'mouseUpAt': - case 'mouseUpRight': - case 'mouseUpRightAt': - case 'open': - case 'openWindow': - case 'pause': - case 'refresh': - case 'removeAllSelections': - case 'removeScript': - case 'removeSelection': - case 'retrieveLastRemoteControlLogs': - case 'rollup': - case 'runScript': - case 'select': - case 'selectFrame': - case 'selectPopUp': - case 'selectWindow': - case 'setBrowserLogLevel': - case 'setContext': - case 'setCursorPosition': - case 'setMouseSpeed': - case 'setSpeed': - case 'shiftKeyDown': - case 'shiftKeyUp': - case 'shutDownSeleniumServer': - case 'store': - case 'submit': - case 'type': - case 'typeKeys': - case 'uncheck': - case 'useXpathLibrary': - case 'windowFocus': - case 'windowMaximize': - case isset(self::$autoGeneratedCommands[$command]): { - // Pre-Command Actions - switch ($command) { - case 'open': - case 'openWindow': { - if ($this->collectCodeCoverageInformation) { - $this->deleteCookie('PHPUNIT_SELENIUM_TEST_ID', 'path=/'); - - $this->createCookie( - 'PHPUNIT_SELENIUM_TEST_ID=' . $this->testId, - 'path=/' - ); - } - } - break; - case 'store': - // store is a synonym of storeExpression - // and RC only understands storeExpression - $command = 'storeExpression'; - break; - } - - if (isset(self::$autoGeneratedCommands[$command]) && self::$autoGeneratedCommands[$command]['functionHelper']) { - $helperArguments = array($command, $arguments, self::$autoGeneratedCommands[$command]); - call_user_func_array(array($this, self::$autoGeneratedCommands[$command]['functionHelper']), $helperArguments); - } else { - $this->doCommand($command, $arguments); - } - - // Post-Command Actions - switch ($command) { - case 'addLocationStrategy': - case 'allowNativeXpath': - case 'assignId': - case 'captureEntirePageScreenshot': - case 'captureScreenshot': { - // intentionally empty - } - break; - - default: { - if ($wait) { - if ($this->useWaitForPageToLoad) { - $this->waitForPageToLoad($this->seleniumTimeout * 1000); - } else { - sleep($this->wait); - } - } - - if ($this->sleep > 0) { - sleep($this->sleep); - } - - $this->testCase->runDefaultAssertions($command); - } - } - } - break; - - case 'getWhetherThisFrameMatchFrameExpression': - case 'getWhetherThisWindowMatchWindowExpression': - case 'isAlertPresent': - case 'isChecked': - case 'isConfirmationPresent': - case 'isCookiePresent': - case 'isEditable': - case 'isElementPresent': - case 'isOrdered': - case 'isPromptPresent': - case 'isSomethingSelected': - case 'isTextPresent': - case 'isVisible': { - return $this->getBoolean($command, $arguments); - } - break; - - case 'getCssCount': - case 'getCursorPosition': - case 'getElementHeight': - case 'getElementIndex': - case 'getElementPositionLeft': - case 'getElementPositionTop': - case 'getElementWidth': - case 'getMouseSpeed': - case 'getSpeed': - case 'getXpathCount': { - $result = $this->getNumber($command, $arguments); - - if ($wait) { - $this->waitForPageToLoad($this->seleniumTimeout * 1000); - } - - return $result; - } - break; - - case 'getAlert': - case 'getAttribute': - case 'getBodyText': - case 'getConfirmation': - case 'getCookie': - case 'getCookieByName': - case 'getEval': - case 'getExpression': - case 'getHtmlSource': - case 'getLocation': - case 'getLogMessages': - case 'getPrompt': - case 'getSelectedId': - case 'getSelectedIndex': - case 'getSelectedLabel': - case 'getSelectedValue': - case 'getTable': - case 'getText': - case 'getTitle': - case 'captureEntirePageScreenshotToString': - case 'captureScreenshotToString': - case 'getValue': { - $result = $this->getString($command, $arguments); - - if ($wait) { - $this->waitForPageToLoad($this->seleniumTimeout * 1000); - } - - return $result; - } - break; - - case 'getAllButtons': - case 'getAllFields': - case 'getAllLinks': - case 'getAllWindowIds': - case 'getAllWindowNames': - case 'getAllWindowTitles': - case 'getAttributeFromAllWindows': - case 'getSelectedIds': - case 'getSelectedIndexes': - case 'getSelectedLabels': - case 'getSelectedValues': - case 'getSelectOptions': { - $result = $this->getStringArray($command, $arguments); - - if ($wait) { - $this->waitForPageToLoad($this->seleniumTimeout * 1000); - } - - return $result; - } - break; - - case 'waitForCondition': - case 'waitForElementPresent': - case 'waitForElementNotPresent': - case 'waitForFrameToLoad': - case 'waitForPopUp': { - if (count($arguments) == 1) { - $arguments[] = $this->seleniumTimeout * 1000; - } - - $this->doCommand($command, $arguments); - $this->testCase->runDefaultAssertions($command); - } - break; - - case 'waitForPageToLoad': { - if (empty($arguments)) { - $arguments[] = $this->seleniumTimeout * 1000; - } - - $this->doCommand($command, $arguments); - $this->testCase->runDefaultAssertions($command); - } - break; - - default: { - if (!in_array($command, $this->userCommands)) { - throw new BadMethodCallException( - "Method $command not defined." - ); - } - $this->doCommand($command, $arguments); - } - } - } - - /** - * Send a command to the Selenium RC server. - * - * @param string $command - * @param array $arguments - * @param array $namedArguments - * @return string - * @author Seth Casana - */ - protected function doCommand($command, array $arguments = array(), array $namedArguments = array()) - { - $url = sprintf( - 'http://%s:%s/selenium-server/driver/', - $this->host, - $this->port - ); - - $numArguments = count($arguments); - $postData = sprintf('cmd=%s', urlencode($command)); - for ($i = 0; $i < $numArguments; $i++) { - $argNum = strval($i + 1); - - if ($arguments[$i] == ' ') { - $postData .= sprintf('&%s=%s', $argNum, urlencode($arguments[$i])); - } else { - $postData .= sprintf('&%s=%s', $argNum, urlencode(trim($arguments[$i]))); - } - } - foreach ($namedArguments as $key => $value) { - $postData .= sprintf('&%s=%s', $key, urlencode($value)); - } - - if (isset($this->sessionId)) { - $postData .= sprintf('&%s=%s', 'sessionId', $this->sessionId); - } - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_POST, TRUE); - curl_setopt($curl, CURLOPT_POSTFIELDS, $postData); - curl_setopt($curl, CURLOPT_HTTPHEADER, array( - 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' - )); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 60); - - $response = curl_exec($curl); - $info = curl_getinfo($curl); - - if (!$response) { - throw new RuntimeException("CURL error while accessing the Selenium Server at '$url': " . curl_error($curl)); - } - - curl_close($curl); - - if (!preg_match('/^OK/', $response)) { - throw new RuntimeException("Invalid response while accessing the Selenium Server at '$url': " . $response); - } - - if ($info['http_code'] != 200) { - throw new RuntimeException( - 'The response from the Selenium RC server is invalid: ' . - $response - ); - } - - return $response; - } - - protected function preprocessParameters($params) - { - foreach ($params as $key => $param ) { - if (is_string($param) && (strlen($param) > 0)) { - $params[$key] = $this->getString('getExpression', array($param)); - } - } - return $params; - } - - /** - * Send a command to the Selenium RC server and treat the result - * as a boolean. - * - * @param string $command - * @param array $arguments - * @return boolean - * @author Shin Ohno - * @author Bjoern Schotte - */ - protected function getBoolean($command, array $arguments) - { - $result = $this->getString($command, $arguments); - - switch ($result) { - case 'true': return TRUE; - - case 'false': return FALSE; - - default: { - throw new PHPUnit_Framework_Exception( - 'Result is neither "true" nor "false": ' . PHPUnit_Util_Type::export($result) - ); - } - } - } - - /** - * Send a command to the Selenium RC server and treat the result - * as a number. - * - * @param string $command - * @param array $arguments - * @return numeric - * @author Shin Ohno - * @author Bjoern Schotte - */ - protected function getNumber($command, array $arguments) - { - $result = $this->getString($command, $arguments); - - if (!is_numeric($result)) { - throw new PHPUnit_Framework_Exception( - 'Result is not numeric: ' . PHPUnit_Util_Type::export($result) - ); - } - - return $result; - } - - /** - * Send a command to the Selenium RC server and treat the result - * as a string. - * - * @param string $command - * @param array $arguments - * @return string - * @author Shin Ohno - * @author Bjoern Schotte - */ - protected function getString($command, array $arguments) - { - try { - $result = $this->doCommand($command, $arguments); - } - - catch (RuntimeException $e) { - throw $e; - } - - return (strlen($result) > 3) ? substr($result, 3) : ''; - } - - /** - * Send a command to the Selenium RC server and treat the result - * as an array of strings. - * - * @param string $command - * @param array $arguments - * @return array - * @author Shin Ohno - * @author Bjoern Schotte - */ - protected function getStringArray($command, array $arguments) - { - $csv = $this->getString($command, $arguments); - $token = ''; - $tokens = array(); - $letters = preg_split('//', $csv, -1, PREG_SPLIT_NO_EMPTY); - $count = count($letters); - - for ($i = 0; $i < $count; $i++) { - $letter = $letters[$i]; - - switch($letter) { - case '\\': { - $letter = $letters[++$i]; - $token .= $letter; - } - break; - - case ',': { - $tokens[] = $token; - $token = ''; - } - break; - - default: { - $token .= $letter; - } - } - } - - $tokens[] = $token; - - return $tokens; - } - - public function getVerificationErrors() - { - return $this->verificationErrors; - } - - public function clearVerificationErrors() - { - $this->verificationErrors = array(); - } - - protected function assertCommand($command, $arguments, $info) - { - $method = $info['originalMethod']; - $requiresTarget = $info['requiresTarget']; - $result = $this->__call($method, $arguments); - $message = "Failed command: " . $command . "('" - . (array_key_exists(0, $arguments) ? $arguments[0] . "'" : '') - . (array_key_exists(1, $arguments) ? ", '" . $arguments[1] . "'" : '') - . ")"; - - if ($info['isBoolean']) { - if (!isset($info['negative']) || !$info['negative']) { - PHPUnit_Framework_Assert::assertTrue($result, $message); - } else { - PHPUnit_Framework_Assert::assertFalse($result, $message); - } - } else { - if ($requiresTarget === TRUE) { - $expected = $arguments[1]; - } else { - $expected = $arguments[0]; - } - - if (strpos($expected, 'exact:') === 0) { - $expected = substr($expected, strlen('exact:')); - - if (!isset($info['negative']) || !$info['negative']) { - PHPUnit_Framework_Assert::assertEquals($expected, $result, $message); - } else { - PHPUnit_Framework_Assert::assertNotEquals($expected, $result, $message); - } - } else { - $caseInsensitive = FALSE; - - if (strpos($expected, 'regexp:') === 0) { - $expected = substr($expected, strlen('regexp:')); - } - - else if (strpos($expected, 'regexpi:') === 0) { - $expected = substr($expected, strlen('regexpi:')); - $caseInsensitive = TRUE; - } - - else { - if (strpos($expected, 'glob:') === 0) { - $expected = substr($expected, strlen('glob:')); - } - - $expected = '^' . str_replace( - array('*', '?'), array('.*', '.?'), $expected - ) . '$'; - } - - $expected = '/' . str_replace('/', '\/', $expected) . '/'; - - if ($caseInsensitive) { - $expected .= 'i'; - } - - if (!isset($info['negative']) || !$info['negative']) { - PHPUnit_Framework_Assert::assertRegExp( - $expected, $result, $message - ); - } else { - PHPUnit_Framework_Assert::assertNotRegExp( - $expected, $result, $message - ); - } - } - } - } - - protected function verifyCommand($command, $arguments, $info) - { - try { - $this->assertCommand($command, $arguments, $info); - } - - catch (PHPUnit_Framework_AssertionFailedError $e) { - array_push($this->verificationErrors, $e->toString()); - } - } - - protected function waitForCommand($command, $arguments, $info) - { - $lastExceptionMessage = ''; - for ($second = 0; ; $second++) { - if ($second > $this->httpTimeout) { - PHPUnit_Framework_Assert::fail( - "WaitFor timeout. \n" - . "Last exception message: \n" . $lastExceptionMessage - ); - } - - try { - $this->assertCommand($command, $arguments, $info); - return; - } - - catch (Exception $e) { - $lastExceptionMessage = $e->getMessage(); - } - - sleep(1); - } - } - - /** - * Parses the docblock of PHPUnit_Extensions_SeleniumTestCase_Driver::__call - * for get*(), is*(), assert*(), verify*(), assertNot*(), verifyNot*(), - * store*(), waitFor*(), and waitForNot*() methods. - */ - protected static function autoGenerateCommands() - { - $method = new ReflectionMethod(__CLASS__, '__call'); - $docComment = $method->getDocComment(); - - if (preg_match_all('(@method\s+(\w+)\s+([\w]+)\((.*)\))', $docComment, $matches)) { - foreach ($matches[2] as $methodKey => $method) { - if (preg_match('/^(get|is)([A-Z].+)$/', $method, $methodMatches)) { - $baseName = $methodMatches[2]; - $isBoolean = $methodMatches[1] == 'is'; - $requiresTarget = (strlen($matches[3][$methodKey]) > 0); - - if (preg_match('/^(.*)Present$/', $baseName, $methodMatches)) { - $notBaseName = $methodMatches[1] . 'NotPresent'; - } else { - $notBaseName = 'Not' . $baseName; - } - - self::$autoGeneratedCommands['store' . $baseName] = array( - 'functionHelper' => FALSE - ); - - self::$autoGeneratedCommands['assert' . $baseName] = array( - 'originalMethod' => $method, - 'isBoolean' => $isBoolean, - 'functionHelper' => 'assertCommand', - 'requiresTarget' => $requiresTarget - ); - - self::$autoGeneratedCommands['assert' . $notBaseName] = array( - 'originalMethod' => $method, - 'isBoolean' => $isBoolean, - 'negative' => TRUE, - 'functionHelper' => 'assertCommand', - 'requiresTarget' => $requiresTarget - ); - - self::$autoGeneratedCommands['verify' . $baseName] = array( - 'originalMethod' => $method, - 'isBoolean' => $isBoolean, - 'functionHelper' => 'verifyCommand', - 'requiresTarget' => $requiresTarget - ); - - self::$autoGeneratedCommands['verify' . $notBaseName] = array( - 'originalMethod' => $method, - 'isBoolean' => $isBoolean, - 'negative' => TRUE, - 'functionHelper' => 'verifyCommand', - 'requiresTarget' => $requiresTarget - ); - - self::$autoGeneratedCommands['waitFor' . $baseName] = array( - 'originalMethod' => $method, - 'isBoolean' => $isBoolean, - 'functionHelper' => 'waitForCommand', - 'requiresTarget' => $requiresTarget - ); - - self::$autoGeneratedCommands['waitFor' . $notBaseName] = array( - 'originalMethod' => $method, - 'isBoolean' => $isBoolean, - 'negative' => TRUE, - 'functionHelper' => 'waitForCommand', - 'requiresTarget' => $requiresTarget - ); - } - } - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.6 - */ - -/** - * TestSuite class for a set of tests from a single Testcase Class - * executed with a particular browser. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.6 - */ -class PHPUnit_Extensions_SeleniumBrowserSuite extends PHPUnit_Framework_TestSuite -{ - /** - * Overriding the default: Selenium suites are always built from a TestCase class. - * @var boolean - */ - protected $testCase = TRUE; - - public function addTestMethod(ReflectionClass $class, ReflectionMethod $method) - { - return parent::addTestMethod($class, $method); - } - - public static function fromClassAndBrowser($className, array $browser) - { - $browserSuite = new self(); - if (isset($browser['browserName'])) { - $name = $browser['browserName']; - } else if (isset($browser['name'])) { - $name = $browser['name']; - } else { - $name = $browser['browser']; - } - $browserSuite->setName($className . ': ' . $name); - return $browserSuite; - } - - public function setupSpecificBrowser(array $browser) - { - $this->browserOnAllTests($this, $browser); - } - - private function browserOnAllTests(PHPUnit_Framework_TestSuite $suite, array $browser) - { - foreach ($suite->tests() as $test) { - if ($test instanceof PHPUnit_Framework_TestSuite) { - $this->browserOnAllTests($test, $browser); - } else { - $test->setupSpecificBrowser($browser); - } - } - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.0.0 - */ - -/** - * TestCase class that uses Selenium to provide - * the functionality required for web testing. - * - * @package PHPUnit_Selenium - * @author Sebastian Bergmann - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.0.0 - * - * @method unknown addLocationStrategy() - * @method unknown addLocationStrategyAndWait() - * @method unknown addScript() - * @method unknown addScriptAndWait() - * @method unknown addSelection() - * @method unknown addSelectionAndWait() - * @method unknown allowNativeXpath() - * @method unknown allowNativeXpathAndWait() - * @method unknown altKeyDown() - * @method unknown altKeyDownAndWait() - * @method unknown altKeyUp() - * @method unknown altKeyUpAndWait() - * @method unknown answerOnNextPrompt() - * @method unknown assignId() - * @method unknown assignIdAndWait() - * @method unknown assertAlert - * @method unknown assertAlertNotPresent - * @method unknown assertAlertPresent - * @method unknown assertAllButtons - * @method unknown assertAllFields - * @method unknown assertAllLinks - * @method unknown assertAllWindowIds - * @method unknown assertAllWindowNames - * @method unknown assertAllWindowTitles - * @method unknown assertAttribute - * @method unknown assertAttributeFromAllWindows - * @method unknown assertBodyText - * @method unknown assertChecked - * @method unknown assertConfirmation - * @method unknown assertConfirmationNotPresent - * @method unknown assertConfirmationPresent - * @method unknown assertCookie - * @method unknown assertCookieByName - * @method unknown assertCookieNotPresent - * @method unknown assertCookiePresent - * @method unknown assertCssCount - * @method unknown assertCursorPosition - * @method unknown assertEditable - * @method unknown assertElementHeight - * @method unknown assertElementIndex - * @method unknown assertElementNotPresent - * @method unknown assertElementPositionLeft - * @method unknown assertElementPositionTop - * @method unknown assertElementPresent - * @method unknown assertElementWidth - * @method unknown assertEval - * @method unknown assertExpression - * @method unknown assertHtmlSource - * @method unknown assertLocation - * @method unknown assertLogMessages - * @method unknown assertMouseSpeed - * @method unknown assertNotAlert - * @method unknown assertNotAllButtons - * @method unknown assertNotAllFields - * @method unknown assertNotAllLinks - * @method unknown assertNotAllWindowIds - * @method unknown assertNotAllWindowNames - * @method unknown assertNotAllWindowTitles - * @method unknown assertNotAttribute - * @method unknown assertNotAttributeFromAllWindows - * @method unknown assertNotBodyText - * @method unknown assertNotChecked - * @method unknown assertNotConfirmation - * @method unknown assertNotCookie - * @method unknown assertNotCookieByName - * @method unknown assertNotCssCount - * @method unknown assertNotCursorPosition - * @method unknown assertNotEditable - * @method unknown assertNotElementHeight - * @method unknown assertNotElementIndex - * @method unknown assertNotElementPositionLeft - * @method unknown assertNotElementPositionTop - * @method unknown assertNotElementWidth - * @method unknown assertNotEval - * @method unknown assertNotExpression - * @method unknown assertNotHtmlSource - * @method unknown assertNotLocation - * @method unknown assertNotLogMessages - * @method unknown assertNotMouseSpeed - * @method unknown assertNotOrdered - * @method unknown assertNotPrompt - * @method unknown assertNotSelectOptions - * @method unknown assertNotSelectedId - * @method unknown assertNotSelectedIds - * @method unknown assertNotSelectedIndex - * @method unknown assertNotSelectedIndexes - * @method unknown assertNotSelectedLabel - * @method unknown assertNotSelectedLabels - * @method unknown assertNotSelectedValue - * @method unknown assertNotSelectedValues - * @method unknown assertNotSomethingSelected - * @method unknown assertNotSpeed - * @method unknown assertNotSpeedAndWait - * @method unknown assertNotTable - * @method unknown assertNotText - * @method unknown assertNotTitle - * @method unknown assertNotValue - * @method unknown assertNotVisible - * @method unknown assertNotWhetherThisFrameMatchFrameExpression - * @method unknown assertNotWhetherThisWindowMatchWindowExpression - * @method unknown assertNotXpathCount - * @method unknown assertOrdered - * @method unknown assertPrompt - * @method unknown assertPromptNotPresent - * @method unknown assertPromptPresent - * @method unknown assertSelectOptions - * @method unknown assertSelectedId - * @method unknown assertSelectedIds - * @method unknown assertSelectedIndex - * @method unknown assertSelectedIndexes - * @method unknown assertSelectedLabel - * @method unknown assertSelectedLabels - * @method unknown assertSelectedValue - * @method unknown assertSelectedValues - * @method unknown assertSomethingSelected - * @method unknown assertSpeed - * @method unknown assertSpeedAndWait - * @method unknown assertTable - * @method unknown assertText - * @method unknown assertTextNotPresent - * @method unknown assertTextPresent - * @method unknown assertTitle - * @method unknown assertValue - * @method unknown assertVisible - * @method unknown assertWhetherThisFrameMatchFrameExpression - * @method unknown assertWhetherThisWindowMatchWindowExpression - * @method unknown assertXpathCount - * @method unknown attachFile() - * @method unknown break() - * @method unknown captureEntirePageScreenshot() - * @method unknown captureEntirePageScreenshotAndWait() - * @method unknown captureEntirePageScreenshotToStringAndWait() - * @method unknown captureScreenshotAndWait() - * @method unknown captureScreenshotToStringAndWait() - * @method unknown check() - * @method unknown checkAndWait() - * @method unknown chooseCancelOnNextConfirmation() - * @method unknown chooseCancelOnNextConfirmationAndWait() - * @method unknown chooseOkOnNextConfirmation() - * @method unknown chooseOkOnNextConfirmationAndWait() - * @method unknown click() - * @method unknown clickAndWait() - * @method unknown clickAt() - * @method unknown clickAtAndWait() - * @method unknown close() - * @method unknown contextMenu() - * @method unknown contextMenuAndWait() - * @method unknown contextMenuAt() - * @method unknown contextMenuAtAndWait() - * @method unknown controlKeyDown() - * @method unknown controlKeyDownAndWait() - * @method unknown controlKeyUp() - * @method unknown controlKeyUpAndWait() - * @method unknown createCookie() - * @method unknown createCookieAndWait() - * @method unknown deleteAllVisibleCookies() - * @method unknown deleteAllVisibleCookiesAndWait() - * @method unknown deleteCookie() - * @method unknown deleteCookieAndWait() - * @method unknown deselectPopUp() - * @method unknown deselectPopUpAndWait() - * @method unknown doubleClick() - * @method unknown doubleClickAndWait() - * @method unknown doubleClickAt() - * @method unknown doubleClickAtAndWait() - * @method unknown dragAndDrop() - * @method unknown dragAndDropAndWait() - * @method unknown dragAndDropToObject() - * @method unknown dragAndDropToObjectAndWait() - * @method unknown dragDrop() - * @method unknown dragDropAndWait() - * @method unknown echo() - * @method unknown fireEvent() - * @method unknown fireEventAndWait() - * @method unknown focus() - * @method unknown focusAndWait() - * @method string getAlert() - * @method array getAllButtons() - * @method array getAllFields() - * @method array getAllLinks() - * @method array getAllWindowIds() - * @method array getAllWindowNames() - * @method array getAllWindowTitles() - * @method string getAttribute() - * @method array getAttributeFromAllWindows() - * @method string getBodyText() - * @method string getConfirmation() - * @method string getCookie() - * @method string getCookieByName() - * @method integer getCursorPosition() - * @method integer getElementHeight() - * @method integer getElementIndex() - * @method integer getElementPositionLeft() - * @method integer getElementPositionTop() - * @method integer getElementWidth() - * @method string getEval() - * @method string getExpression() - * @method string getHtmlSource() - * @method string getLocation() - * @method string getLogMessages() - * @method integer getMouseSpeed() - * @method string getPrompt() - * @method array getSelectOptions() - * @method string getSelectedId() - * @method array getSelectedIds() - * @method string getSelectedIndex() - * @method array getSelectedIndexes() - * @method string getSelectedLabel() - * @method array getSelectedLabels() - * @method string getSelectedValue() - * @method array getSelectedValues() - * @method unknown getSpeed() - * @method unknown getSpeedAndWait() - * @method string getTable() - * @method string getText() - * @method string getTitle() - * @method string getValue() - * @method boolean getWhetherThisFrameMatchFrameExpression() - * @method boolean getWhetherThisWindowMatchWindowExpression() - * @method integer getXpathCount() - * @method unknown goBack() - * @method unknown goBackAndWait() - * @method unknown highlight() - * @method unknown highlightAndWait() - * @method unknown ignoreAttributesWithoutValue() - * @method unknown ignoreAttributesWithoutValueAndWait() - * @method boolean isAlertPresent() - * @method boolean isChecked() - * @method boolean isConfirmationPresent() - * @method boolean isCookiePresent() - * @method boolean isEditable() - * @method boolean isElementPresent() - * @method boolean isOrdered() - * @method boolean isPromptPresent() - * @method boolean isSomethingSelected() - * @method boolean isTextPresent() - * @method boolean isVisible() - * @method unknown keyDown() - * @method unknown keyDownAndWait() - * @method unknown keyDownNative() - * @method unknown keyDownNativeAndWait() - * @method unknown keyPress() - * @method unknown keyPressAndWait() - * @method unknown keyPressNative() - * @method unknown keyPressNativeAndWait() - * @method unknown keyUp() - * @method unknown keyUpAndWait() - * @method unknown keyUpNative() - * @method unknown keyUpNativeAndWait() - * @method unknown metaKeyDown() - * @method unknown metaKeyDownAndWait() - * @method unknown metaKeyUp() - * @method unknown metaKeyUpAndWait() - * @method unknown mouseDown() - * @method unknown mouseDownAndWait() - * @method unknown mouseDownAt() - * @method unknown mouseDownAtAndWait() - * @method unknown mouseMove() - * @method unknown mouseMoveAndWait() - * @method unknown mouseMoveAt() - * @method unknown mouseMoveAtAndWait() - * @method unknown mouseOut() - * @method unknown mouseOutAndWait() - * @method unknown mouseOver() - * @method unknown mouseOverAndWait() - * @method unknown mouseUp() - * @method unknown mouseUpAndWait() - * @method unknown mouseUpAt() - * @method unknown mouseUpAtAndWait() - * @method unknown mouseUpRight() - * @method unknown mouseUpRightAndWait() - * @method unknown mouseUpRightAt() - * @method unknown mouseUpRightAtAndWait() - * @method unknown open() - * @method unknown openWindow() - * @method unknown openWindowAndWait() - * @method unknown pause() - * @method unknown refresh() - * @method unknown refreshAndWait() - * @method unknown removeAllSelections() - * @method unknown removeAllSelectionsAndWait() - * @method unknown removeScript() - * @method unknown removeScriptAndWait() - * @method unknown removeSelection() - * @method unknown removeSelectionAndWait() - * @method unknown retrieveLastRemoteControlLogs() - * @method unknown rollup() - * @method unknown rollupAndWait() - * @method unknown runScript() - * @method unknown runScriptAndWait() - * @method unknown select() - * @method unknown selectAndWait() - * @method unknown selectFrame() - * @method unknown selectPopUp() - * @method unknown selectPopUpAndWait() - * @method unknown selectWindow() - * @method unknown setBrowserLogLevel() - * @method unknown setBrowserLogLevelAndWait() - * @method unknown setContext() - * @method unknown setCursorPosition() - * @method unknown setCursorPositionAndWait() - * @method unknown setMouseSpeed() - * @method unknown setMouseSpeedAndWait() - * @method unknown setSpeed() - * @method unknown setSpeedAndWait() - * @method unknown shiftKeyDown() - * @method unknown shiftKeyDownAndWait() - * @method unknown shiftKeyUp() - * @method unknown shiftKeyUpAndWait() - * @method unknown shutDownSeleniumServer() - * @method unknown store() - * @method unknown submit() - * @method unknown submitAndWait() - * @method unknown type() - * @method unknown typeAndWait() - * @method unknown typeKeys() - * @method unknown typeKeysAndWait() - * @method unknown uncheck() - * @method unknown uncheckAndWait() - * @method unknown useXpathLibrary() - * @method unknown useXpathLibraryAndWait() - * @method unknown waitForAlert - * @method unknown waitForAlertNotPresent - * @method unknown waitForAlertPresent - * @method unknown waitForAllButtons - * @method unknown waitForAllFields - * @method unknown waitForAllLinks - * @method unknown waitForAllWindowIds - * @method unknown waitForAllWindowNames - * @method unknown waitForAllWindowTitles - * @method unknown waitForAttribute - * @method unknown waitForAttributeFromAllWindows - * @method unknown waitForBodyText - * @method unknown waitForChecked - * @method unknown waitForCondition() - * @method unknown waitForConfirmation - * @method unknown waitForConfirmationNotPresent - * @method unknown waitForConfirmationPresent - * @method unknown waitForCookie - * @method unknown waitForCookieByName - * @method unknown waitForCookieNotPresent - * @method unknown waitForCookiePresent - * @method unknown waitForCssCount - * @method unknown waitForCursorPosition - * @method unknown waitForEditable - * @method unknown waitForElementHeight - * @method unknown waitForElementIndex - * @method unknown waitForElementNotPresent - * @method unknown waitForElementPositionLeft - * @method unknown waitForElementPositionTop - * @method unknown waitForElementPresent - * @method unknown waitForElementWidth - * @method unknown waitForEval - * @method unknown waitForExpression - * @method unknown waitForHtmlSource - * @method unknown waitForLocation - * @method unknown waitForLogMessages - * @method unknown waitForMouseSpeed - * @method unknown waitForNotAlert - * @method unknown waitForNotAllButtons - * @method unknown waitForNotAllFields - * @method unknown waitForNotAllLinks - * @method unknown waitForNotAllWindowIds - * @method unknown waitForNotAllWindowNames - * @method unknown waitForNotAllWindowTitles - * @method unknown waitForNotAttribute - * @method unknown waitForNotAttributeFromAllWindows - * @method unknown waitForNotBodyText - * @method unknown waitForNotChecked - * @method unknown waitForNotConfirmation - * @method unknown waitForNotCookie - * @method unknown waitForNotCookieByName - * @method unknown waitForNotCssCount - * @method unknown waitForNotCursorPosition - * @method unknown waitForNotEditable - * @method unknown waitForNotElementHeight - * @method unknown waitForNotElementIndex - * @method unknown waitForNotElementPositionLeft - * @method unknown waitForNotElementPositionTop - * @method unknown waitForNotElementWidth - * @method unknown waitForNotEval - * @method unknown waitForNotExpression - * @method unknown waitForNotHtmlSource - * @method unknown waitForNotLocation - * @method unknown waitForNotLogMessages - * @method unknown waitForNotMouseSpeed - * @method unknown waitForNotOrdered - * @method unknown waitForNotPrompt - * @method unknown waitForNotSelectOptions - * @method unknown waitForNotSelectedId - * @method unknown waitForNotSelectedIds - * @method unknown waitForNotSelectedIndex - * @method unknown waitForNotSelectedIndexes - * @method unknown waitForNotSelectedLabel - * @method unknown waitForNotSelectedLabels - * @method unknown waitForNotSelectedValue - * @method unknown waitForNotSelectedValues - * @method unknown waitForNotSomethingSelected - * @method unknown waitForNotSpeed - * @method unknown waitForNotSpeedAndWait - * @method unknown waitForNotTable - * @method unknown waitForNotText - * @method unknown waitForNotTitle - * @method unknown waitForNotValue - * @method unknown waitForNotVisible - * @method unknown waitForNotWhetherThisFrameMatchFrameExpression - * @method unknown waitForNotWhetherThisWindowMatchWindowExpression - * @method unknown waitForNotXpathCount - * @method unknown waitForOrdered - * @method unknown waitForPageToLoad() - * @method unknown waitForPopUp() - * @method unknown waitForPrompt - * @method unknown waitForPromptNotPresent - * @method unknown waitForPromptPresent - * @method unknown waitForSelectOptions - * @method unknown waitForSelectedId - * @method unknown waitForSelectedIds - * @method unknown waitForSelectedIndex - * @method unknown waitForSelectedIndexes - * @method unknown waitForSelectedLabel - * @method unknown waitForSelectedLabels - * @method unknown waitForSelectedValue - * @method unknown waitForSelectedValues - * @method unknown waitForSomethingSelected - * @method unknown waitForSpeed - * @method unknown waitForSpeedAndWait - * @method unknown waitForTable - * @method unknown waitForText - * @method unknown waitForTextNotPresent - * @method unknown waitForTextPresent - * @method unknown waitForTitle - * @method unknown waitForValue - * @method unknown waitForVisible - * @method unknown waitForWhetherThisFrameMatchFrameExpression - * @method unknown waitForWhetherThisWindowMatchWindowExpression - * @method unknown waitForXpathCount - * @method unknown windowFocus() - * @method unknown windowMaximize() - */ -abstract class PHPUnit_Extensions_SeleniumTestCase extends PHPUnit_Framework_TestCase -{ - /** - * @var array - */ - public static $browsers = array(); - - /** - * @var string - */ - protected $browserName; - - /** - * @var boolean - */ - protected $collectCodeCoverageInformation = FALSE; - - /** - * @var string - */ - protected $coverageScriptUrl = ''; - - /** - * @var PHPUnit_Extensions_SeleniumTestCase_Driver[] - */ - protected $drivers = array(); - - /** - * @var boolean - */ - protected $inDefaultAssertions = FALSE; - - /** - * @var string - */ - protected $testId; - - /** - * @var array - * @access protected - */ - protected $verificationErrors = array(); - - /** - * @var boolean - */ - protected $captureScreenshotOnFailure = FALSE; - - /** - * @var string - */ - protected $screenshotPath = ''; - - /** - * @var string - */ - protected $screenshotUrl = ''; - - /** - * @var integer the number of seconds to wait before declaring - * the Selenium server not reachable - */ - protected $serverConnectionTimeOut = 10; - - /** - * @var boolean - */ - private $serverRunning; - - /** - * @var boolean - */ - private static $shareSession; - - /** - * The last sessionId used for running a test. - * @var string - */ - private static $sessionId; - - /** - * @param boolean - */ - public static function shareSession($shareSession) - { - self::$shareSession = $shareSession; - } - - /** - * @param string $name - * @param array $data - * @param string $dataName - * @param array $browser - * @throws InvalidArgumentException - */ - public function __construct($name = NULL, array $data = array(), $dataName = '') - { - parent::__construct($name, $data, $dataName); - $this->testId = md5(uniqid(rand(), TRUE)); - $this->getDriver(array()); - } - - public function setupSpecificBrowser(array $browser) - { - $this->getDriver($browser); - } - - /** - * Stops any shared session still open at the end of the current - * PHPUnit process. - */ - public function __destruct() - { - $this->stopSession(); - } - - /** - * @param string $className - * @return PHPUnit_Framework_TestSuite - */ - public static function suite($className) - { - return PHPUnit_Extensions_SeleniumTestSuite::fromTestCaseClass($className); - } - - /** - * Runs the test case and collects the results in a TestResult object. - * If no TestResult object is passed a new one will be created. - * - * @param PHPUnit_Framework_TestResult $result - * @return PHPUnit_Framework_TestResult - * @throws InvalidArgumentException - */ - public function run(PHPUnit_Framework_TestResult $result = NULL) - { - if ($result === NULL) { - $result = $this->createResult(); - } - - $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation(); - - foreach ($this->drivers as $driver) { - $driver->setCollectCodeCoverageInformation( - $this->collectCodeCoverageInformation - ); - } - - parent::run($result); - - if ($this->collectCodeCoverageInformation) { - $result->getCodeCoverage()->append( - $this->getCodeCoverage(), $this - ); - } - - return $result; - } - - /** - * @param array $browser - * @return PHPUnit_Extensions_SeleniumTestCase_Driver - */ - protected function getDriver(array $browser) - { - if (isset($browser['name'])) { - if (!is_string($browser['name'])) { - throw new InvalidArgumentException( - 'Array element "name" is no string.' - ); - } - } else { - $browser['name'] = ''; - } - - if (isset($browser['browser'])) { - if (!is_string($browser['browser'])) { - throw new InvalidArgumentException( - 'Array element "browser" is no string.' - ); - } - } else { - $browser['browser'] = ''; - } - - if (isset($browser['host'])) { - if (!is_string($browser['host'])) { - throw new InvalidArgumentException( - 'Array element "host" is no string.' - ); - } - } else { - $browser['host'] = 'localhost'; - } - - if (isset($browser['port'])) { - if (!is_int($browser['port'])) { - throw new InvalidArgumentException( - 'Array element "port" is no integer.' - ); - } - } else { - $browser['port'] = 4444; - } - - if (isset($browser['timeout'])) { - if (!is_int($browser['timeout'])) { - throw new InvalidArgumentException( - 'Array element "timeout" is no integer.' - ); - } - } else { - $browser['timeout'] = 30; - } - - if (isset($browser['httpTimeout'])) { - if (!is_int($browser['httpTimeout'])) { - throw new InvalidArgumentException( - 'Array element "httpTimeout" is no integer.' - ); - } - } else { - $browser['httpTimeout'] = 45; - } - - $driver = new PHPUnit_Extensions_SeleniumTestCase_Driver; - $driver->setName($browser['name']); - $driver->setBrowser($browser['browser']); - $driver->setHost($browser['host']); - $driver->setPort($browser['port']); - $driver->setTimeout($browser['timeout']); - $driver->setHttpTimeout($browser['httpTimeout']); - $driver->setTestCase($this); - $driver->setTestId($this->testId); - - $this->drivers[0] = $driver; - - return $driver; - } - - public function skipWithNoServerRunning() - { - try { - fsockopen($this->drivers[0]->getHost(), $this->drivers[0]->getPort(), $errno, $errstr, $this->serverConnectionTimeOut); - $this->serverRunning = TRUE; - } catch (PHPUnit_Framework_Error_Warning $e) { - $this->markTestSkipped( - sprintf( - 'Could not connect to the Selenium Server on %s:%d.', - $this->drivers[0]->getHost(), - $this->drivers[0]->getPort() - ) - ); - $this->serverRunning = FALSE; - } - } - - /** - * @return string - */ - protected function prepareTestSession() - { - $testCaseClassVars = get_class_vars(get_class($this)); - if ($testCaseClassVars['browsers']) { - return $this->start(); - } - if (self::$shareSession && self::$sessionId !== NULL) { - $this->setSessionId(self::$sessionId); - $this->selectWindow('null'); - } else { - self::$sessionId = $this->start(); - } - - return self::$sessionId; - } - - /** - * @throws RuntimeException - */ - protected function runTest() - { - $this->skipWithNoServerRunning(); - - $this->prepareTestSession(); - - if (!is_file($this->getName(FALSE))) { - $result = parent::runTest(); - } else { - $this->runSelenese($this->getName(FALSE)); - $result = NULL; - } - - if (!empty($this->verificationErrors)) { - $this->fail(implode("\n", $this->verificationErrors)); - } - - if (!self::$shareSession) { - $this->stopSession(); - } - - return $result; - } - - private function stopSession() - { - try { - $this->stop(); - } catch (RuntimeException $e) { } - } - - /** - * Returns a string representation of the test case. - * - * @return string - */ - public function toString() - { - $buffer = parent::toString(); - - if (!empty($this->browserName)) { - $buffer .= ' with browser ' . $this->browserName; - } - - return $buffer; - } - - /** - * Runs a test from a Selenese (HTML) specification. - * - * @param string $filename - */ - public function runSelenese($filename) - { - $document = PHPUnit_Util_XML::loadFile($filename, TRUE); - $xpath = new DOMXPath($document); - $rows = $xpath->query('body/table/tbody/tr'); - - foreach ($rows as $row) { - $action = NULL; - $arguments = array(); - $columns = $xpath->query('td', $row); - - foreach ($columns as $column) { - if ($action === NULL) { - $action = PHPUnit_Util_XML::nodeToText($column); - } else { - $arguments[] = PHPUnit_Util_XML::nodeToText($column); - } - } - - if (method_exists($this, $action)) { - call_user_func_array(array($this, $action), $arguments); - } else { - $this->__call($action, $arguments); - } - } - } - - /** - * Delegate method calls to the driver. - * - * @param string $command - * @param array $arguments - * @return mixed - */ - public function __call($command, $arguments) - { - $result = call_user_func_array( - array($this->drivers[0], $command), $arguments - ); - - $this->verificationErrors = array_merge( - $this->verificationErrors, $this->drivers[0]->getVerificationErrors() - ); - - $this->drivers[0]->clearVerificationErrors(); - - return $result; - } - - /** - * Asserts that an element's value is equal to a given string. - * - * @param string $locator - * @param string $text - * @param string $message - */ - public function assertElementValueEquals($locator, $text, $message = '') - { - $this->assertEquals($text, $this->getValue($locator), $message); - } - - /** - * Asserts that an element's value is not equal to a given string. - * - * @param string $locator - * @param string $text - * @param string $message - */ - public function assertElementValueNotEquals($locator, $text, $message = '') - { - $this->assertNotEquals($text, $this->getValue($locator), $message); - } - - /** - * Asserts that an element's value contains a given string. - * - * @param string $locator - * @param string $text - * @param string $message - */ - public function assertElementValueContains($locator, $text, $message = '') - { - $this->assertContains($text, $this->getValue($locator), $message); - } - - /** - * Asserts that an element's value does not contain a given string. - * - * @param string $locator - * @param string $text - * @param string $message - */ - public function assertElementValueNotContains($locator, $text, $message = '') - { - $this->assertNotContains($text, $this->getValue($locator), $message); - } - - /** - * Asserts that an element contains a given string. - * - * @param string $locator - * @param string $text - * @param string $message - */ - public function assertElementContainsText($locator, $text, $message = '') - { - $this->assertContains($text, $this->getText($locator), $message); - } - - /** - * Asserts that an element does not contain a given string. - * - * @param string $locator - * @param string $text - * @param string $message - */ - public function assertElementNotContainsText($locator, $text, $message = '') - { - $this->assertNotContains($text, $this->getText($locator), $message); - } - - /** - * Asserts that a select element has a specific option. - * - * @param string $selectLocator - * @param string $option - * @param string $message - */ - public function assertSelectHasOption($selectLocator, $option, $message = '') - { - $this->assertContains($option, $this->getSelectOptions($selectLocator), $message); - } - - /** - * Asserts that a select element does not have a specific option. - * - * @param string $selectLocator - * @param string $option - * @param string $message - */ - public function assertSelectNotHasOption($selectLocator, $option, $message = '') - { - $this->assertNotContains($option, $this->getSelectOptions($selectLocator), $message); - } - - /** - * Asserts that a specific label is selected. - * - * @param string $selectLocator - * @param string $value - * @param string $message - */ - public function assertSelected($selectLocator, $option, $message = '') - { - if ($message == '') { - $message = sprintf( - 'Label "%s" not selected in "%s".', - $option, - $selectLocator - ); - } - - $this->assertEquals( - $option, - $this->getSelectedLabel($selectLocator), - $message - ); - } - - /** - * Asserts that a specific label is not selected. - * - * @param string $selectLocator - * @param string $value - * @param string $message - */ - public function assertNotSelected($selectLocator, $option, $message = '') - { - if ($message == '') { - $message = sprintf( - 'Label "%s" selected in "%s".', - $option, - $selectLocator - ); - } - - $this->assertNotEquals( - $option, - $this->getSelectedLabel($selectLocator), - $message - ); - } - - /** - * Asserts that a specific value is selected. - * - * @param string $selectLocator - * @param string $value - * @param string $message - */ - public function assertIsSelected($selectLocator, $value, $message = '') - { - if ($message == '') { - $message = sprintf( - 'Value "%s" not selected in "%s".', - $value, - $selectLocator - ); - } - - $this->assertEquals( - $value, $this->getSelectedValue($selectLocator), - $message - ); - } - - /** - * Asserts that a specific value is not selected. - * - * @param string $selectLocator - * @param string $value - * @param string $message - */ - public function assertIsNotSelected($selectLocator, $value, $message = '') - { - if ($message == '') { - $message = sprintf( - 'Value "%s" selected in "%s".', - $value, - $selectLocator - ); - } - - $this->assertNotEquals( - $value, - $this->getSelectedValue($selectLocator), - $message - ); - } - - /** - * Template Method that is called after Selenium actions. - * - * @param string $action - */ - protected function defaultAssertions($action) - { - } - - /** - * @return array - */ - protected function getCodeCoverage() - { - $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage( - $this->coverageScriptUrl, - $this->testId - ); - return $coverage->get(); - } - - /** - * @param string $action - */ - public function runDefaultAssertions($action) - { - if (!$this->inDefaultAssertions) { - $this->inDefaultAssertions = TRUE; - $this->defaultAssertions($action); - $this->inDefaultAssertions = FALSE; - } - } - - /** - * This method is called when a test method did not execute successfully. - * - * @param Exception $e - */ - protected function onNotSuccessfulTest(Exception $e) - { - if (!$this->serverRunning) { - throw $e; - } - - try { - $this->restoreSessionStateAfterFailedTest(); - $buffer = ''; - - if ($this->captureScreenshotOnFailure) { - $buffer .= 'Current URL: ' . $this->drivers[0]->getLocation() . - "\n"; - - $screenshotInfo = $this->takeScreenshot(); - if ($screenshotInfo != '') { - $buffer .= $screenshotInfo; - } - } - - $this->stopSession(); - } catch (Exception $another) { - $buffer = "Issues while capturing the screenshot:\n" . $another->getMessage(); - } - - if ($e instanceof PHPUnit_Framework_ExpectationFailedException - && is_object($e->getComparisonFailure())) { - $message = $e->getComparisonFailure()->toString(); - } else { - $message = $e->getMessage(); - } - - $buffer .= "\n" . $message; - - // gain the screenshot path, lose the stack trace - if ($this->captureScreenshotOnFailure) { - throw new PHPUnit_Framework_Error($buffer, $e->getCode(), $e->getFile(), $e->getLine(), $e); - } - - // yes to stack trace and everything - if ($e instanceof PHPUnit_Framework_IncompleteTestError - || $e instanceof PHPUnit_Framework_SkippedTestError - || $e instanceof PHPUnit_Framework_AssertionFailedError) { - throw $e; - } - - // yes to stack trace, only for F tests - // PHPUnit issue 471 prevents getTrace() from being useful - throw new PHPUnit_Framework_Error($buffer, $e->getCode(), $e->getFile(), $e->getLine(), $e); - } - - private function restoreSessionStateAfterFailedTest() - { - self::$sessionId = NULL; - } - - /** - * Returns correct path to screenshot save path. - * - * @return string - */ - protected function getScreenshotPath() - { - $path = $this->screenshotPath; - - if (!in_array(substr($path, strlen($path) -1, 1), array("/","\\"))) { - $path .= DIRECTORY_SEPARATOR; - } - - return $path; - } - - /** - * Take a screenshot and return information about it. - * Return an empty string if the screenshotPath and screenshotUrl - * properties are empty. - * Issue #88. - * - * @access protected - * @return string - */ - protected function takeScreenshot() - { - if (!empty($this->screenshotPath) && - !empty($this->screenshotUrl)) { - $filename = $this->getScreenshotPath() . $this->testId . '.png'; - - $this->drivers[0]->captureEntirePageScreenshot($filename); - - return 'Screenshot: ' . $this->screenshotUrl . '/' . - $this->testId . ".png\n"; - } else { - return ''; - } - } - - /** - * Pause support for runSelenese() HTML cases - * @param $milliseconds - */ - protected function pause($milliseconds){ - sleep(round($milliseconds/1000)); - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.4 - */ - -/** - * Retrieves the value of a CSS property. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.4 - */ -class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Css - extends PHPUnit_Extensions_Selenium2TestCase_Command -{ - /** - * @param array $propertyName - */ - public function __construct($propertyName, - PHPUnit_Extensions_Selenium2TestCase_URL $cssResourceBaseUrl) - { - $this->jsonParameters = array(); - $this->url = $cssResourceBaseUrl->descend($propertyName); - } - - public function httpMethod() - { - return 'GET'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.0 - */ - -/** - * Class for implementing commands that just return a value - * (obtained with GET). - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.0 - */ -class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_GenericAccessor - extends PHPUnit_Extensions_Selenium2TestCase_Command -{ - public function httpMethod() - { - return 'GET'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.4 - */ - -/** - * Checks equality (same element on the page) with another DOM element. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.4 - */ -class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Equals - extends PHPUnit_Extensions_Selenium2TestCase_Command -{ - /** - * @param array $parameter - */ - public function __construct($parameter, - PHPUnit_Extensions_Selenium2TestCase_URL $equalsResourceBaseUrl) - { - $this->jsonParameters = array(); - if (!($parameter instanceof PHPUnit_Extensions_Selenium2TestCase_Element)) { - throw new InvalidArgumentException("Elements can only test equality with other Element instances."); - } - $this->url = $equalsResourceBaseUrl->descend($parameter->getId()); - } - - public function httpMethod() - { - return 'GET'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.4 - */ - -/** - * Class for implementing commands that just accomplishes an action (via POST). - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2012 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.4 - */ -class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_GenericPost - extends PHPUnit_Extensions_Selenium2TestCase_Command -{ - public function httpMethod() - { - return 'POST'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.0 - */ - -/** - * Get and set the element's value attribute. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.0 - */ -class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Value - extends PHPUnit_Extensions_Selenium2TestCase_SessionCommand_Keys -{ - public function httpMethod() - { - if ($this->jsonParameters) { - return 'POST'; - } - - return 'GET'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.4 - */ - -/** - * Retrieves an attribute of a DOM element. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.4 - */ -class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Attribute - extends PHPUnit_Extensions_Selenium2TestCase_Command -{ - /** - * @param array $parameter - */ - public function __construct($parameter, - PHPUnit_Extensions_Selenium2TestCase_URL $attributeResourceBaseUrl) - { - $this->jsonParameters = array(); - $this->url = $attributeResourceBaseUrl->descend($parameter); - } - - public function httpMethod() - { - return 'GET'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.0 - */ - -/** - * Clicks ok on an alert popup. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.0 - */ -class PHPUnit_Extensions_Selenium2TestCase_ElementCommand_Click - extends PHPUnit_Extensions_Selenium2TestCase_Command -{ - public function httpMethod() - { - return 'POST'; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Ivan Kurnosov - * @copyright 2010-2011 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.12 - */ - -/** - * Class-mapper, that converts requested special key into correspondent Unicode character - * - * @package PHPUnit_Selenium - * @author Ivan Kurnosov - * @copyright 2010-2011 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - * @since Class available since Release 1.2.12 - * @see http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value - */ -class PHPUnit_Extensions_Selenium2TestCase_KeysHolder -{ - private $_keys = array( - 'null' => "\xEE\x80\x80", - 'cancel' => "\xEE\x80\x81", - 'help' => "\xEE\x80\x82", - 'backspace' => "\xEE\x80\x83", - 'tab' => "\xEE\x80\x84", - 'clear' => "\xEE\x80\x85", - 'return' => "\xEE\x80\x86", - 'enter' => "\xEE\x80\x87", - 'shift' => "\xEE\x80\x88", - 'control' => "\xEE\x80\x89", - 'alt' => "\xEE\x80\x8A", - 'pause' => "\xEE\x80\x8B", - 'escape' => "\xEE\x80\x8C", - 'space' => "\xEE\x80\x8D", - 'pageup' => "\xEE\x80\x8E", - 'pagedown' => "\xEE\x80\x8F", - 'end' => "\xEE\x80\x90", - 'home' => "\xEE\x80\x91", - 'left' => "\xEE\x80\x92", - 'up' => "\xEE\x80\x93", - 'right' => "\xEE\x80\x94", - 'down' => "\xEE\x80\x95", - 'insert' => "\xEE\x80\x96", - 'delete' => "\xEE\x80\x97", - 'semicolon' => "\xEE\x80\x98", - 'equals' => "\xEE\x80\x99", - 'numpad0' => "\xEE\x80\x9A", - 'numpad1' => "\xEE\x80\x9B", - 'numpad2' => "\xEE\x80\x9C", - 'numpad3' => "\xEE\x80\x9D", - 'numpad4' => "\xEE\x80\x9E", - 'numpad5' => "\xEE\x80\x9F", - 'numpad6' => "\xEE\x80\xA0", - 'numpad7' => "\xEE\x80\xA1", - 'numpad8' => "\xEE\x80\xA2", - 'numpad9' => "\xEE\x80\xA3", - 'multiply' => "\xEE\x80\xA4", - 'add' => "\xEE\x80\xA5", - 'separator' => "\xEE\x80\xA6", - 'subtract' => "\xEE\x80\xA7", - 'decimal' => "\xEE\x80\xA8", - 'divide' => "\xEE\x80\xA9", - 'f1' => "\xEE\x80\xB1", - 'f2' => "\xEE\x80\xB2", - 'f3' => "\xEE\x80\xB3", - 'f4' => "\xEE\x80\xB4", - 'f5' => "\xEE\x80\xB5", - 'f6' => "\xEE\x80\xB6", - 'f7' => "\xEE\x80\xB7", - 'f8' => "\xEE\x80\xB8", - 'f9' => "\xEE\x80\xB9", - 'f10' => "\xEE\x80\xBA", - 'f11' => "\xEE\x80\xBB", - 'f12' => "\xEE\x80\xBC", - 'command' => "\xEE\x80\xBD", - ); - - public function specialKey($name) - { - $normalizedName = strtolower($name); - - if (!isset($this->_keys[$normalizedName])) { - throw new PHPUnit_Extensions_Selenium2TestCase_Exception("There is no special key '$name' defined"); - } - - return $this->_keys[$normalizedName]; - } -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - */ - - -/** - * Provides access to /element and /elements commands - * - * @package PHPUnit_Selenium - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @version Release: 1.3.1 - * @link http://www.phpunit.de/ - */ -abstract class PHPUnit_Extensions_Selenium2TestCase_Element_Accessor - extends PHPUnit_Extensions_Selenium2TestCase_CommandsHolder -{ - - /** - * @param string $value e.g. 'container' - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function byClassName($value) - { - return $this->by('class name', $value); - } - - /** - * @param string $value e.g. 'div.container' - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function byCssSelector($value) - { - return $this->by('css selector', $value); - } - - /** - * @param string $value e.g. 'uniqueId' - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function byId($value) - { - return $this->by('id', $value); - } - - /** - * @param string $value e.g. 'Link text' - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function byLinkText($value) - { - return $this->by('link text', $value); - } - - /** - * @param string $value e.g. 'email_address' - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function byName($value) - { - return $this->by('name', $value); - } - - /** - * @param string $value e.g. 'body' - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function byTag($value) - { - return $this->by('tag name', $value); - } - - /** - * @param string $value e.g. '/div[@attribute="value"]' - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function byXPath($value) - { - return $this->by('xpath', $value); - } - - /** - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function element(PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria) - { - $value = $this->postCommand('element', $criteria); - return PHPUnit_Extensions_Selenium2TestCase_Element::fromResponseValue( - $value, $this->getSessionUrl()->descend('element'), $this->driver); - } - - /** - * @return array instances of PHPUnit_Extensions_Selenium2TestCase_Element - */ - public function elements(PHPUnit_Extensions_Selenium2TestCase_ElementCriteria $criteria) - { - $values = $this->postCommand('elements', $criteria); - $elements = array(); - foreach ($values as $value) { - $elements[] = - PHPUnit_Extensions_Selenium2TestCase_Element::fromResponseValue( - $value, $this->getSessionUrl()->descend('element'), $this->driver); - } - return $elements; - } - - /** - * @param string $strategy - * @return PHPUnit_Extensions_Selenium2TestCase_ElementCriteria - */ - public function using($strategy) - { - return new PHPUnit_Extensions_Selenium2TestCase_ElementCriteria($strategy); - } - - /** - * @return PHPUnit_Extensions_Selenium2TestCase_URL - */ - protected abstract function getSessionUrl(); - - /** - * @param string $strategy supported by JsonWireProtocol element/ command - * @param string $value - * @return PHPUnit_Extensions_Selenium2TestCase_Element - */ - private function by($strategy, $value) - { - return $this->element($this->using($strategy)->value($value)); - } - -} -. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * * Neither the name of Sebastian Bergmann nor the names of his - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - * @package PHPUnit_Selenium - * @author Giorgio Sironi - * @copyright 2010-2013 Sebastian Bergmann - * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License - * @link http://www.phpunit.de/ - * @since File available since Release 1.2.2 - */ - -/** - * Object representing a ",n=d.getElementsByTagName("*"),r=d.getElementsByTagName("a")[0],!n||!r||!n.length)return{};s=o.createElement("select"),l=s.appendChild(o.createElement("option")),a=d.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t={getSetAttribute:"t"!==d.className,leadingWhitespace:3===d.firstChild.nodeType,tbody:!d.getElementsByTagName("tbody").length,htmlSerialize:!!d.getElementsByTagName("link").length,style:/top/.test(r.getAttribute("style")),hrefNormalized:"/a"===r.getAttribute("href"),opacity:/^0.5/.test(r.style.opacity),cssFloat:!!r.style.cssFloat,checkOn:!!a.value,optSelected:l.selected,enctype:!!o.createElement("form").enctype,html5Clone:"<:nav>"!==o.createElement("nav").cloneNode(!0).outerHTML,boxModel:"CSS1Compat"===o.compatMode,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,boxSizingReliable:!0,pixelPosition:!1},a.checked=!0,t.noCloneChecked=a.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!l.disabled;try{delete d.test}catch(h){t.deleteExpando=!1}a=o.createElement("input"),a.setAttribute("value",""),t.input=""===a.getAttribute("value"),a.value="t",a.setAttribute("type","radio"),t.radioValue="t"===a.value,a.setAttribute("checked","t"),a.setAttribute("name","t"),u=o.createDocumentFragment(),u.appendChild(a),t.appendChecked=a.checked,t.checkClone=u.cloneNode(!0).cloneNode(!0).lastChild.checked,d.attachEvent&&(d.attachEvent("onclick",function(){t.noCloneEvent=!1}),d.cloneNode(!0).click());for(f in{submit:!0,change:!0,focusin:!0})d.setAttribute(c="on"+f,"t"),t[f+"Bubbles"]=c in e||d.attributes[c].expando===!1;return d.style.backgroundClip="content-box",d.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===d.style.backgroundClip,b(function(){var n,r,a,s="padding:0;margin:0;border:0;display:block;box-sizing:content-box;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;",u=o.getElementsByTagName("body")[0];u&&(n=o.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",u.appendChild(n).appendChild(d),d.innerHTML="
t
",a=d.getElementsByTagName("td"),a[0].style.cssText="padding:0;margin:0;border:0;display:none",p=0===a[0].offsetHeight,a[0].style.display="",a[1].style.display="none",t.reliableHiddenOffsets=p&&0===a[0].offsetHeight,d.innerHTML="",d.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",t.boxSizing=4===d.offsetWidth,t.doesNotIncludeMarginInBodyOffset=1!==u.offsetTop,e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(d,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(d,null)||{width:"4px"}).width,r=d.appendChild(o.createElement("div")),r.style.cssText=d.style.cssText=s,r.style.marginRight=r.style.width="0",d.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),typeof d.style.zoom!==i&&(d.innerHTML="",d.style.cssText=s+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=3===d.offsetWidth,d.style.display="block",d.innerHTML="
",d.firstChild.style.width="5px",t.shrinkWrapBlocks=3!==d.offsetWidth,t.inlineBlockNeedsLayout&&(u.style.zoom=1)),u.removeChild(n),n=d=a=r=null)}),n=s=u=l=r=a=null,t}();var O=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,B=/([A-Z])/g;function P(e,n,r,i){if(b.acceptData(e)){var o,a,s=b.expando,u="string"==typeof n,l=e.nodeType,p=l?b.cache:e,f=l?e[s]:e[s]&&s;if(f&&p[f]&&(i||p[f].data)||!u||r!==t)return f||(l?e[s]=f=c.pop()||b.guid++:f=s),p[f]||(p[f]={},l||(p[f].toJSON=b.noop)),("object"==typeof n||"function"==typeof n)&&(i?p[f]=b.extend(p[f],n):p[f].data=b.extend(p[f].data,n)),o=p[f],i||(o.data||(o.data={}),o=o.data),r!==t&&(o[b.camelCase(n)]=r),u?(a=o[n],null==a&&(a=o[b.camelCase(n)])):a=o,a}}function R(e,t,n){if(b.acceptData(e)){var r,i,o,a=e.nodeType,s=a?b.cache:e,u=a?e[b.expando]:b.expando;if(s[u]){if(t&&(o=n?s[u]:s[u].data)){b.isArray(t)?t=t.concat(b.map(t,b.camelCase)):t in o?t=[t]:(t=b.camelCase(t),t=t in o?[t]:t.split(" "));for(r=0,i=t.length;i>r;r++)delete o[t[r]];if(!(n?$:b.isEmptyObject)(o))return}(n||(delete s[u].data,$(s[u])))&&(a?b.cleanData([e],!0):b.support.deleteExpando||s!=s.window?delete s[u]:s[u]=null)}}}b.extend({cache:{},expando:"jQuery"+(p+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(e){return e=e.nodeType?b.cache[e[b.expando]]:e[b.expando],!!e&&!$(e)},data:function(e,t,n){return P(e,t,n)},removeData:function(e,t){return R(e,t)},_data:function(e,t,n){return P(e,t,n,!0)},_removeData:function(e,t){return R(e,t,!0)},acceptData:function(e){if(e.nodeType&&1!==e.nodeType&&9!==e.nodeType)return!1;var t=e.nodeName&&b.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),b.fn.extend({data:function(e,n){var r,i,o=this[0],a=0,s=null;if(e===t){if(this.length&&(s=b.data(o),1===o.nodeType&&!b._data(o,"parsedAttrs"))){for(r=o.attributes;r.length>a;a++)i=r[a].name,i.indexOf("data-")||(i=b.camelCase(i.slice(5)),W(o,i,s[i]));b._data(o,"parsedAttrs",!0)}return s}return"object"==typeof e?this.each(function(){b.data(this,e)}):b.access(this,function(n){return n===t?o?W(o,e,b.data(o,e)):null:(this.each(function(){b.data(this,e,n)}),t)},null,n,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){b.removeData(this,e)})}});function W(e,n,r){if(r===t&&1===e.nodeType){var i="data-"+n.replace(B,"-$1").toLowerCase();if(r=e.getAttribute(i),"string"==typeof r){try{r="true"===r?!0:"false"===r?!1:"null"===r?null:+r+""===r?+r:O.test(r)?b.parseJSON(r):r}catch(o){}b.data(e,n,r)}else r=t}return r}function $(e){var t;for(t in e)if(("data"!==t||!b.isEmptyObject(e[t]))&&"toJSON"!==t)return!1;return!0}b.extend({queue:function(e,n,r){var i;return e?(n=(n||"fx")+"queue",i=b._data(e,n),r&&(!i||b.isArray(r)?i=b._data(e,n,b.makeArray(r)):i.push(r)),i||[]):t},dequeue:function(e,t){t=t||"fx";var n=b.queue(e,t),r=n.length,i=n.shift(),o=b._queueHooks(e,t),a=function(){b.dequeue(e,t)};"inprogress"===i&&(i=n.shift(),r--),o.cur=i,i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,a,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return b._data(e,n)||b._data(e,n,{empty:b.Callbacks("once memory").add(function(){b._removeData(e,t+"queue"),b._removeData(e,n)})})}}),b.fn.extend({queue:function(e,n){var r=2;return"string"!=typeof e&&(n=e,e="fx",r--),r>arguments.length?b.queue(this[0],e):n===t?this:this.each(function(){var t=b.queue(this,e,n);b._queueHooks(this,e),"fx"===e&&"inprogress"!==t[0]&&b.dequeue(this,e)})},dequeue:function(e){return this.each(function(){b.dequeue(this,e)})},delay:function(e,t){return e=b.fx?b.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,o=b.Deferred(),a=this,s=this.length,u=function(){--i||o.resolveWith(a,[a])};"string"!=typeof e&&(n=e,e=t),e=e||"fx";while(s--)r=b._data(a[s],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(u));return u(),o.promise(n)}});var I,z,X=/[\t\r\n]/g,U=/\r/g,V=/^(?:input|select|textarea|button|object)$/i,Y=/^(?:a|area)$/i,J=/^(?:checked|selected|autofocus|autoplay|async|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped)$/i,G=/^(?:checked|selected)$/i,Q=b.support.getSetAttribute,K=b.support.input;b.fn.extend({attr:function(e,t){return b.access(this,b.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){b.removeAttr(this,e)})},prop:function(e,t){return b.access(this,b.prop,e,t,arguments.length>1)},removeProp:function(e){return e=b.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,o,a=0,s=this.length,u="string"==typeof e&&e;if(b.isFunction(e))return this.each(function(t){b(this).addClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(X," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=b.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,a=0,s=this.length,u=0===arguments.length||"string"==typeof e&&e;if(b.isFunction(e))return this.each(function(t){b(this).removeClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];s>a;a++)if(n=this[a],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(X," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?b.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e,r="boolean"==typeof t;return b.isFunction(e)?this.each(function(n){b(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var o,a=0,s=b(this),u=t,l=e.match(w)||[];while(o=l[a++])u=r?u:!s.hasClass(o),s[u?"addClass":"removeClass"](o)}else(n===i||"boolean"===n)&&(this.className&&b._data(this,"__className__",this.className),this.className=this.className||e===!1?"":b._data(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(X," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,o=this[0];{if(arguments.length)return i=b.isFunction(e),this.each(function(n){var o,a=b(this);1===this.nodeType&&(o=i?e.call(this,n,a.val()):e,null==o?o="":"number"==typeof o?o+="":b.isArray(o)&&(o=b.map(o,function(e){return null==e?"":e+""})),r=b.valHooks[this.type]||b.valHooks[this.nodeName.toLowerCase()],r&&"set"in r&&r.set(this,o,"value")!==t||(this.value=o))});if(o)return r=b.valHooks[o.type]||b.valHooks[o.nodeName.toLowerCase()],r&&"get"in r&&(n=r.get(o,"value"))!==t?n:(n=o.value,"string"==typeof n?n.replace(U,""):null==n?"":n)}}}),b.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,a=o?null:[],s=o?i+1:r.length,u=0>i?s:o?i:0;for(;s>u;u++)if(n=r[u],!(!n.selected&&u!==i||(b.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&b.nodeName(n.parentNode,"optgroup"))){if(t=b(n).val(),o)return t;a.push(t)}return a},set:function(e,t){var n=b.makeArray(t);return b(e).find("option").each(function(){this.selected=b.inArray(b(this).val(),n)>=0}),n.length||(e.selectedIndex=-1),n}}},attr:function(e,n,r){var o,a,s,u=e.nodeType;if(e&&3!==u&&8!==u&&2!==u)return typeof e.getAttribute===i?b.prop(e,n,r):(a=1!==u||!b.isXMLDoc(e),a&&(n=n.toLowerCase(),o=b.attrHooks[n]||(J.test(n)?z:I)),r===t?o&&a&&"get"in o&&null!==(s=o.get(e,n))?s:(typeof e.getAttribute!==i&&(s=e.getAttribute(n)),null==s?t:s):null!==r?o&&a&&"set"in o&&(s=o.set(e,r,n))!==t?s:(e.setAttribute(n,r+""),r):(b.removeAttr(e,n),t))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(w);if(o&&1===e.nodeType)while(n=o[i++])r=b.propFix[n]||n,J.test(n)?!Q&&G.test(n)?e[b.camelCase("default-"+n)]=e[r]=!1:e[r]=!1:b.attr(e,n,""),e.removeAttribute(Q?n:r)},attrHooks:{type:{set:function(e,t){if(!b.support.radioValue&&"radio"===t&&b.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(e,n,r){var i,o,a,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return a=1!==s||!b.isXMLDoc(e),a&&(n=b.propFix[n]||n,o=b.propHooks[n]),r!==t?o&&"set"in o&&(i=o.set(e,r,n))!==t?i:e[n]=r:o&&"get"in o&&null!==(i=o.get(e,n))?i:e[n]},propHooks:{tabIndex:{get:function(e){var n=e.getAttributeNode("tabindex");return n&&n.specified?parseInt(n.value,10):V.test(e.nodeName)||Y.test(e.nodeName)&&e.href?0:t}}}}),z={get:function(e,n){var r=b.prop(e,n),i="boolean"==typeof r&&e.getAttribute(n),o="boolean"==typeof r?K&&Q?null!=i:G.test(n)?e[b.camelCase("default-"+n)]:!!i:e.getAttributeNode(n);return o&&o.value!==!1?n.toLowerCase():t},set:function(e,t,n){return t===!1?b.removeAttr(e,n):K&&Q||!G.test(n)?e.setAttribute(!Q&&b.propFix[n]||n,n):e[b.camelCase("default-"+n)]=e[n]=!0,n}},K&&Q||(b.attrHooks.value={get:function(e,n){var r=e.getAttributeNode(n);return b.nodeName(e,"input")?e.defaultValue:r&&r.specified?r.value:t},set:function(e,n,r){return b.nodeName(e,"input")?(e.defaultValue=n,t):I&&I.set(e,n,r)}}),Q||(I=b.valHooks.button={get:function(e,n){var r=e.getAttributeNode(n);return r&&("id"===n||"name"===n||"coords"===n?""!==r.value:r.specified)?r.value:t},set:function(e,n,r){var i=e.getAttributeNode(r);return i||e.setAttributeNode(i=e.ownerDocument.createAttribute(r)),i.value=n+="","value"===r||n===e.getAttribute(r)?n:t}},b.attrHooks.contenteditable={get:I.get,set:function(e,t,n){I.set(e,""===t?!1:t,n)}},b.each(["width","height"],function(e,n){b.attrHooks[n]=b.extend(b.attrHooks[n],{set:function(e,r){return""===r?(e.setAttribute(n,"auto"),r):t}})})),b.support.hrefNormalized||(b.each(["href","src","width","height"],function(e,n){b.attrHooks[n]=b.extend(b.attrHooks[n],{get:function(e){var r=e.getAttribute(n,2);return null==r?t:r}})}),b.each(["href","src"],function(e,t){b.propHooks[t]={get:function(e){return e.getAttribute(t,4)}}})),b.support.style||(b.attrHooks.style={get:function(e){return e.style.cssText||t},set:function(e,t){return e.style.cssText=t+""}}),b.support.optSelected||(b.propHooks.selected=b.extend(b.propHooks.selected,{get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}})),b.support.enctype||(b.propFix.enctype="encoding"),b.support.checkOn||b.each(["radio","checkbox"],function(){b.valHooks[this]={get:function(e){return null===e.getAttribute("value")?"on":e.value}}}),b.each(["radio","checkbox"],function(){b.valHooks[this]=b.extend(b.valHooks[this],{set:function(e,n){return b.isArray(n)?e.checked=b.inArray(b(e).val(),n)>=0:t}})});var Z=/^(?:input|select|textarea)$/i,et=/^key/,tt=/^(?:mouse|contextmenu)|click/,nt=/^(?:focusinfocus|focusoutblur)$/,rt=/^([^.]*)(?:\.(.+)|)$/;function it(){return!0}function ot(){return!1}b.event={global:{},add:function(e,n,r,o,a){var s,u,l,c,p,f,d,h,g,m,y,v=b._data(e);if(v){r.handler&&(c=r,r=c.handler,a=c.selector),r.guid||(r.guid=b.guid++),(u=v.events)||(u=v.events={}),(f=v.handle)||(f=v.handle=function(e){return typeof b===i||e&&b.event.triggered===e.type?t:b.event.dispatch.apply(f.elem,arguments)},f.elem=e),n=(n||"").match(w)||[""],l=n.length;while(l--)s=rt.exec(n[l])||[],g=y=s[1],m=(s[2]||"").split(".").sort(),p=b.event.special[g]||{},g=(a?p.delegateType:p.bindType)||g,p=b.event.special[g]||{},d=b.extend({type:g,origType:y,data:o,handler:r,guid:r.guid,selector:a,needsContext:a&&b.expr.match.needsContext.test(a),namespace:m.join(".")},c),(h=u[g])||(h=u[g]=[],h.delegateCount=0,p.setup&&p.setup.call(e,o,m,f)!==!1||(e.addEventListener?e.addEventListener(g,f,!1):e.attachEvent&&e.attachEvent("on"+g,f))),p.add&&(p.add.call(e,d),d.handler.guid||(d.handler.guid=r.guid)),a?h.splice(h.delegateCount++,0,d):h.push(d),b.event.global[g]=!0;e=null}},remove:function(e,t,n,r,i){var o,a,s,u,l,c,p,f,d,h,g,m=b.hasData(e)&&b._data(e);if(m&&(c=m.events)){t=(t||"").match(w)||[""],l=t.length;while(l--)if(s=rt.exec(t[l])||[],d=g=s[1],h=(s[2]||"").split(".").sort(),d){p=b.event.special[d]||{},d=(r?p.delegateType:p.bindType)||d,f=c[d]||[],s=s[2]&&RegExp("(^|\\.)"+h.join("\\.(?:.*\\.|)")+"(\\.|$)"),u=o=f.length;while(o--)a=f[o],!i&&g!==a.origType||n&&n.guid!==a.guid||s&&!s.test(a.namespace)||r&&r!==a.selector&&("**"!==r||!a.selector)||(f.splice(o,1),a.selector&&f.delegateCount--,p.remove&&p.remove.call(e,a));u&&!f.length&&(p.teardown&&p.teardown.call(e,h,m.handle)!==!1||b.removeEvent(e,d,m.handle),delete c[d])}else for(d in c)b.event.remove(e,d+t[l],n,r,!0);b.isEmptyObject(c)&&(delete m.handle,b._removeData(e,"events"))}},trigger:function(n,r,i,a){var s,u,l,c,p,f,d,h=[i||o],g=y.call(n,"type")?n.type:n,m=y.call(n,"namespace")?n.namespace.split("."):[];if(l=f=i=i||o,3!==i.nodeType&&8!==i.nodeType&&!nt.test(g+b.event.triggered)&&(g.indexOf(".")>=0&&(m=g.split("."),g=m.shift(),m.sort()),u=0>g.indexOf(":")&&"on"+g,n=n[b.expando]?n:new b.Event(g,"object"==typeof n&&n),n.isTrigger=!0,n.namespace=m.join("."),n.namespace_re=n.namespace?RegExp("(^|\\.)"+m.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,n.result=t,n.target||(n.target=i),r=null==r?[n]:b.makeArray(r,[n]),p=b.event.special[g]||{},a||!p.trigger||p.trigger.apply(i,r)!==!1)){if(!a&&!p.noBubble&&!b.isWindow(i)){for(c=p.delegateType||g,nt.test(c+g)||(l=l.parentNode);l;l=l.parentNode)h.push(l),f=l;f===(i.ownerDocument||o)&&h.push(f.defaultView||f.parentWindow||e)}d=0;while((l=h[d++])&&!n.isPropagationStopped())n.type=d>1?c:p.bindType||g,s=(b._data(l,"events")||{})[n.type]&&b._data(l,"handle"),s&&s.apply(l,r),s=u&&l[u],s&&b.acceptData(l)&&s.apply&&s.apply(l,r)===!1&&n.preventDefault();if(n.type=g,!(a||n.isDefaultPrevented()||p._default&&p._default.apply(i.ownerDocument,r)!==!1||"click"===g&&b.nodeName(i,"a")||!b.acceptData(i)||!u||!i[g]||b.isWindow(i))){f=i[u],f&&(i[u]=null),b.event.triggered=g;try{i[g]()}catch(v){}b.event.triggered=t,f&&(i[u]=f)}return n.result}},dispatch:function(e){e=b.event.fix(e);var n,r,i,o,a,s=[],u=h.call(arguments),l=(b._data(this,"events")||{})[e.type]||[],c=b.event.special[e.type]||{};if(u[0]=e,e.delegateTarget=this,!c.preDispatch||c.preDispatch.call(this,e)!==!1){s=b.event.handlers.call(this,e,l),n=0;while((o=s[n++])&&!e.isPropagationStopped()){e.currentTarget=o.elem,a=0;while((i=o.handlers[a++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(i.namespace))&&(e.handleObj=i,e.data=i.data,r=((b.event.special[i.origType]||{}).handle||i.handler).apply(o.elem,u),r!==t&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return c.postDispatch&&c.postDispatch.call(this,e),e.result}},handlers:function(e,n){var r,i,o,a,s=[],u=n.delegateCount,l=e.target;if(u&&l.nodeType&&(!e.button||"click"!==e.type))for(;l!=this;l=l.parentNode||this)if(1===l.nodeType&&(l.disabled!==!0||"click"!==e.type)){for(o=[],a=0;u>a;a++)i=n[a],r=i.selector+" ",o[r]===t&&(o[r]=i.needsContext?b(r,this).index(l)>=0:b.find(r,this,null,[l]).length),o[r]&&o.push(i);o.length&&s.push({elem:l,handlers:o})}return n.length>u&&s.push({elem:this,handlers:n.slice(u)}),s},fix:function(e){if(e[b.expando])return e;var t,n,r,i=e.type,a=e,s=this.fixHooks[i];s||(this.fixHooks[i]=s=tt.test(i)?this.mouseHooks:et.test(i)?this.keyHooks:{}),r=s.props?this.props.concat(s.props):this.props,e=new b.Event(a),t=r.length;while(t--)n=r[t],e[n]=a[n];return e.target||(e.target=a.srcElement||o),3===e.target.nodeType&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,a):e},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,i,a,s=n.button,u=n.fromElement;return null==e.pageX&&null!=n.clientX&&(i=e.target.ownerDocument||o,a=i.documentElement,r=i.body,e.pageX=n.clientX+(a&&a.scrollLeft||r&&r.scrollLeft||0)-(a&&a.clientLeft||r&&r.clientLeft||0),e.pageY=n.clientY+(a&&a.scrollTop||r&&r.scrollTop||0)-(a&&a.clientTop||r&&r.clientTop||0)),!e.relatedTarget&&u&&(e.relatedTarget=u===e.target?n.toElement:u),e.which||s===t||(e.which=1&s?1:2&s?3:4&s?2:0),e}},special:{load:{noBubble:!0},click:{trigger:function(){return b.nodeName(this,"input")&&"checkbox"===this.type&&this.click?(this.click(),!1):t}},focus:{trigger:function(){if(this!==o.activeElement&&this.focus)try{return this.focus(),!1}catch(e){}},delegateType:"focusin"},blur:{trigger:function(){return this===o.activeElement&&this.blur?(this.blur(),!1):t},delegateType:"focusout"},beforeunload:{postDispatch:function(e){e.result!==t&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=b.extend(new b.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?b.event.trigger(i,null,t):b.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},b.removeEvent=o.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]===i&&(e[r]=null),e.detachEvent(r,n))},b.Event=function(e,n){return this instanceof b.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?it:ot):this.type=e,n&&b.extend(this,n),this.timeStamp=e&&e.timeStamp||b.now(),this[b.expando]=!0,t):new b.Event(e,n)},b.Event.prototype={isDefaultPrevented:ot,isPropagationStopped:ot,isImmediatePropagationStopped:ot,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=it,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=it,e&&(e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=it,this.stopPropagation()}},b.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){b.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj; -return(!i||i!==r&&!b.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),b.support.submitBubbles||(b.event.special.submit={setup:function(){return b.nodeName(this,"form")?!1:(b.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=b.nodeName(n,"input")||b.nodeName(n,"button")?n.form:t;r&&!b._data(r,"submitBubbles")&&(b.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),b._data(r,"submitBubbles",!0))}),t)},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&b.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){return b.nodeName(this,"form")?!1:(b.event.remove(this,"._submit"),t)}}),b.support.changeBubbles||(b.event.special.change={setup:function(){return Z.test(this.nodeName)?(("checkbox"===this.type||"radio"===this.type)&&(b.event.add(this,"propertychange._change",function(e){"checked"===e.originalEvent.propertyName&&(this._just_changed=!0)}),b.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),b.event.simulate("change",this,e,!0)})),!1):(b.event.add(this,"beforeactivate._change",function(e){var t=e.target;Z.test(t.nodeName)&&!b._data(t,"changeBubbles")&&(b.event.add(t,"change._change",function(e){!this.parentNode||e.isSimulated||e.isTrigger||b.event.simulate("change",this.parentNode,e,!0)}),b._data(t,"changeBubbles",!0))}),t)},handle:function(e){var n=e.target;return this!==n||e.isSimulated||e.isTrigger||"radio"!==n.type&&"checkbox"!==n.type?e.handleObj.handler.apply(this,arguments):t},teardown:function(){return b.event.remove(this,"._change"),!Z.test(this.nodeName)}}),b.support.focusinBubbles||b.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){b.event.simulate(t,e.target,b.event.fix(e),!0)};b.event.special[t]={setup:function(){0===n++&&o.addEventListener(e,r,!0)},teardown:function(){0===--n&&o.removeEventListener(e,r,!0)}}}),b.fn.extend({on:function(e,n,r,i,o){var a,s;if("object"==typeof e){"string"!=typeof n&&(r=r||n,n=t);for(a in e)this.on(a,n,r,e[a],o);return this}if(null==r&&null==i?(i=n,r=n=t):null==i&&("string"==typeof n?(i=r,r=t):(i=r,r=n,n=t)),i===!1)i=ot;else if(!i)return this;return 1===o&&(s=i,i=function(e){return b().off(e),s.apply(this,arguments)},i.guid=s.guid||(s.guid=b.guid++)),this.each(function(){b.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,o;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,b(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if("object"==typeof e){for(o in e)this.off(o,n,e[o]);return this}return(n===!1||"function"==typeof n)&&(r=n,n=t),r===!1&&(r=ot),this.each(function(){b.event.remove(this,e,r,n)})},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return 1===arguments.length?this.off(e,"**"):this.off(t,e||"**",n)},trigger:function(e,t){return this.each(function(){b.event.trigger(e,t,this)})},triggerHandler:function(e,n){var r=this[0];return r?b.event.trigger(e,n,r,!0):t}}),function(e,t){var n,r,i,o,a,s,u,l,c,p,f,d,h,g,m,y,v,x="sizzle"+-new Date,w=e.document,T={},N=0,C=0,k=it(),E=it(),S=it(),A=typeof t,j=1<<31,D=[],L=D.pop,H=D.push,q=D.slice,M=D.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},_="[\\x20\\t\\r\\n\\f]",F="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=F.replace("w","w#"),B="([*^$|!~]?=)",P="\\["+_+"*("+F+")"+_+"*(?:"+B+_+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+O+")|)|)"+_+"*\\]",R=":("+F+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+P.replace(3,8)+")*)|.*)\\)|)",W=RegExp("^"+_+"+|((?:^|[^\\\\])(?:\\\\.)*)"+_+"+$","g"),$=RegExp("^"+_+"*,"+_+"*"),I=RegExp("^"+_+"*([\\x20\\t\\r\\n\\f>+~])"+_+"*"),z=RegExp(R),X=RegExp("^"+O+"$"),U={ID:RegExp("^#("+F+")"),CLASS:RegExp("^\\.("+F+")"),NAME:RegExp("^\\[name=['\"]?("+F+")['\"]?\\]"),TAG:RegExp("^("+F.replace("w","w*")+")"),ATTR:RegExp("^"+P),PSEUDO:RegExp("^"+R),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+_+"*(even|odd|(([+-]|)(\\d*)n|)"+_+"*(?:([+-]|)"+_+"*(\\d+)|))"+_+"*\\)|)","i"),needsContext:RegExp("^"+_+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+_+"*((?:-\\d)?\\d*)"+_+"*\\)|)(?=[^-]|$)","i")},V=/[\x20\t\r\n\f]*[+~]/,Y=/^[^{]+\{\s*\[native code/,J=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,G=/^(?:input|select|textarea|button)$/i,Q=/^h\d$/i,K=/'|\\/g,Z=/\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g,et=/\\([\da-fA-F]{1,6}[\x20\t\r\n\f]?|.)/g,tt=function(e,t){var n="0x"+t-65536;return n!==n?t:0>n?String.fromCharCode(n+65536):String.fromCharCode(55296|n>>10,56320|1023&n)};try{q.call(w.documentElement.childNodes,0)[0].nodeType}catch(nt){q=function(e){var t,n=[];while(t=this[e++])n.push(t);return n}}function rt(e){return Y.test(e+"")}function it(){var e,t=[];return e=function(n,r){return t.push(n+=" ")>i.cacheLength&&delete e[t.shift()],e[n]=r}}function ot(e){return e[x]=!0,e}function at(e){var t=p.createElement("div");try{return e(t)}catch(n){return!1}finally{t=null}}function st(e,t,n,r){var i,o,a,s,u,l,f,g,m,v;if((t?t.ownerDocument||t:w)!==p&&c(t),t=t||p,n=n||[],!e||"string"!=typeof e)return n;if(1!==(s=t.nodeType)&&9!==s)return[];if(!d&&!r){if(i=J.exec(e))if(a=i[1]){if(9===s){if(o=t.getElementById(a),!o||!o.parentNode)return n;if(o.id===a)return n.push(o),n}else if(t.ownerDocument&&(o=t.ownerDocument.getElementById(a))&&y(t,o)&&o.id===a)return n.push(o),n}else{if(i[2])return H.apply(n,q.call(t.getElementsByTagName(e),0)),n;if((a=i[3])&&T.getByClassName&&t.getElementsByClassName)return H.apply(n,q.call(t.getElementsByClassName(a),0)),n}if(T.qsa&&!h.test(e)){if(f=!0,g=x,m=t,v=9===s&&e,1===s&&"object"!==t.nodeName.toLowerCase()){l=ft(e),(f=t.getAttribute("id"))?g=f.replace(K,"\\$&"):t.setAttribute("id",g),g="[id='"+g+"'] ",u=l.length;while(u--)l[u]=g+dt(l[u]);m=V.test(e)&&t.parentNode||t,v=l.join(",")}if(v)try{return H.apply(n,q.call(m.querySelectorAll(v),0)),n}catch(b){}finally{f||t.removeAttribute("id")}}}return wt(e.replace(W,"$1"),t,n,r)}a=st.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},c=st.setDocument=function(e){var n=e?e.ownerDocument||e:w;return n!==p&&9===n.nodeType&&n.documentElement?(p=n,f=n.documentElement,d=a(n),T.tagNameNoComments=at(function(e){return e.appendChild(n.createComment("")),!e.getElementsByTagName("*").length}),T.attributes=at(function(e){e.innerHTML="";var t=typeof e.lastChild.getAttribute("multiple");return"boolean"!==t&&"string"!==t}),T.getByClassName=at(function(e){return e.innerHTML="",e.getElementsByClassName&&e.getElementsByClassName("e").length?(e.lastChild.className="e",2===e.getElementsByClassName("e").length):!1}),T.getByName=at(function(e){e.id=x+0,e.innerHTML="
",f.insertBefore(e,f.firstChild);var t=n.getElementsByName&&n.getElementsByName(x).length===2+n.getElementsByName(x+0).length;return T.getIdNotName=!n.getElementById(x),f.removeChild(e),t}),i.attrHandle=at(function(e){return e.innerHTML="",e.firstChild&&typeof e.firstChild.getAttribute!==A&&"#"===e.firstChild.getAttribute("href")})?{}:{href:function(e){return e.getAttribute("href",2)},type:function(e){return e.getAttribute("type")}},T.getIdNotName?(i.find.ID=function(e,t){if(typeof t.getElementById!==A&&!d){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},i.filter.ID=function(e){var t=e.replace(et,tt);return function(e){return e.getAttribute("id")===t}}):(i.find.ID=function(e,n){if(typeof n.getElementById!==A&&!d){var r=n.getElementById(e);return r?r.id===e||typeof r.getAttributeNode!==A&&r.getAttributeNode("id").value===e?[r]:t:[]}},i.filter.ID=function(e){var t=e.replace(et,tt);return function(e){var n=typeof e.getAttributeNode!==A&&e.getAttributeNode("id");return n&&n.value===t}}),i.find.TAG=T.tagNameNoComments?function(e,n){return typeof n.getElementsByTagName!==A?n.getElementsByTagName(e):t}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},i.find.NAME=T.getByName&&function(e,n){return typeof n.getElementsByName!==A?n.getElementsByName(name):t},i.find.CLASS=T.getByClassName&&function(e,n){return typeof n.getElementsByClassName===A||d?t:n.getElementsByClassName(e)},g=[],h=[":focus"],(T.qsa=rt(n.querySelectorAll))&&(at(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||h.push("\\["+_+"*(?:checked|disabled|ismap|multiple|readonly|selected|value)"),e.querySelectorAll(":checked").length||h.push(":checked")}),at(function(e){e.innerHTML="",e.querySelectorAll("[i^='']").length&&h.push("[*^$]="+_+"*(?:\"\"|'')"),e.querySelectorAll(":enabled").length||h.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),h.push(",.*:")})),(T.matchesSelector=rt(m=f.matchesSelector||f.mozMatchesSelector||f.webkitMatchesSelector||f.oMatchesSelector||f.msMatchesSelector))&&at(function(e){T.disconnectedMatch=m.call(e,"div"),m.call(e,"[s!='']:x"),g.push("!=",R)}),h=RegExp(h.join("|")),g=RegExp(g.join("|")),y=rt(f.contains)||f.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},v=f.compareDocumentPosition?function(e,t){var r;return e===t?(u=!0,0):(r=t.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(t))?1&r||e.parentNode&&11===e.parentNode.nodeType?e===n||y(w,e)?-1:t===n||y(w,t)?1:0:4&r?-1:1:e.compareDocumentPosition?-1:1}:function(e,t){var r,i=0,o=e.parentNode,a=t.parentNode,s=[e],l=[t];if(e===t)return u=!0,0;if(!o||!a)return e===n?-1:t===n?1:o?-1:a?1:0;if(o===a)return ut(e,t);r=e;while(r=r.parentNode)s.unshift(r);r=t;while(r=r.parentNode)l.unshift(r);while(s[i]===l[i])i++;return i?ut(s[i],l[i]):s[i]===w?-1:l[i]===w?1:0},u=!1,[0,0].sort(v),T.detectDuplicates=u,p):p},st.matches=function(e,t){return st(e,null,null,t)},st.matchesSelector=function(e,t){if((e.ownerDocument||e)!==p&&c(e),t=t.replace(Z,"='$1']"),!(!T.matchesSelector||d||g&&g.test(t)||h.test(t)))try{var n=m.call(e,t);if(n||T.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(r){}return st(t,p,null,[e]).length>0},st.contains=function(e,t){return(e.ownerDocument||e)!==p&&c(e),y(e,t)},st.attr=function(e,t){var n;return(e.ownerDocument||e)!==p&&c(e),d||(t=t.toLowerCase()),(n=i.attrHandle[t])?n(e):d||T.attributes?e.getAttribute(t):((n=e.getAttributeNode(t))||e.getAttribute(t))&&e[t]===!0?t:n&&n.specified?n.value:null},st.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},st.uniqueSort=function(e){var t,n=[],r=1,i=0;if(u=!T.detectDuplicates,e.sort(v),u){for(;t=e[r];r++)t===e[r-1]&&(i=n.push(r));while(i--)e.splice(n[i],1)}return e};function ut(e,t){var n=t&&e,r=n&&(~t.sourceIndex||j)-(~e.sourceIndex||j);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function lt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function ct(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function pt(e){return ot(function(t){return t=+t,ot(function(n,r){var i,o=e([],n.length,t),a=o.length;while(a--)n[i=o[a]]&&(n[i]=!(r[i]=n[i]))})})}o=st.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=o(t);return n},i=st.selectors={cacheLength:50,createPseudo:ot,match:U,find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(et,tt),e[3]=(e[4]||e[5]||"").replace(et,tt),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||st.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&st.error(e[0]),e},PSEUDO:function(e){var t,n=!e[5]&&e[2];return U.CHILD.test(e[0])?null:(e[4]?e[2]=e[4]:n&&z.test(n)&&(t=ft(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){return"*"===e?function(){return!0}:(e=e.replace(et,tt).toLowerCase(),function(t){return t.nodeName&&t.nodeName.toLowerCase()===e})},CLASS:function(e){var t=k[e+" "];return t||(t=RegExp("(^|"+_+")"+e+"("+_+"|$)"))&&k(e,function(e){return t.test(e.className||typeof e.getAttribute!==A&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=st.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),a="last"!==e.slice(-4),s="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,p,f,d,h,g=o!==a?"nextSibling":"previousSibling",m=t.parentNode,y=s&&t.nodeName.toLowerCase(),v=!u&&!s;if(m){if(o){while(g){p=t;while(p=p[g])if(s?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;h=g="only"===e&&!h&&"nextSibling"}return!0}if(h=[a?m.firstChild:m.lastChild],a&&v){c=m[x]||(m[x]={}),l=c[e]||[],d=l[0]===N&&l[1],f=l[0]===N&&l[2],p=d&&m.childNodes[d];while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[N,d,f];break}}else if(v&&(l=(t[x]||(t[x]={}))[e])&&l[0]===N)f=l[1];else while(p=++d&&p&&p[g]||(f=d=0)||h.pop())if((s?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(v&&((p[x]||(p[x]={}))[e]=[N,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||st.error("unsupported pseudo: "+e);return r[x]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?ot(function(e,n){var i,o=r(e,t),a=o.length;while(a--)i=M.call(e,o[a]),e[i]=!(n[i]=o[a])}):function(e){return r(e,0,n)}):r}},pseudos:{not:ot(function(e){var t=[],n=[],r=s(e.replace(W,"$1"));return r[x]?ot(function(e,t,n,i){var o,a=r(e,null,i,[]),s=e.length;while(s--)(o=a[s])&&(e[s]=!(t[s]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:ot(function(e){return function(t){return st(e,t).length>0}}),contains:ot(function(e){return function(t){return(t.textContent||t.innerText||o(t)).indexOf(e)>-1}}),lang:ot(function(e){return X.test(e||"")||st.error("unsupported lang: "+e),e=e.replace(et,tt).toLowerCase(),function(t){var n;do if(n=d?t.getAttribute("xml:lang")||t.getAttribute("lang"):t.lang)return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===f},focus:function(e){return e===p.activeElement&&(!p.hasFocus||p.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!i.pseudos.empty(e)},header:function(e){return Q.test(e.nodeName)},input:function(e){return G.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:pt(function(){return[0]}),last:pt(function(e,t){return[t-1]}),eq:pt(function(e,t,n){return[0>n?n+t:n]}),even:pt(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:pt(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:pt(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:pt(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}};for(n in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})i.pseudos[n]=lt(n);for(n in{submit:!0,reset:!0})i.pseudos[n]=ct(n);function ft(e,t){var n,r,o,a,s,u,l,c=E[e+" "];if(c)return t?0:c.slice(0);s=e,u=[],l=i.preFilter;while(s){(!n||(r=$.exec(s)))&&(r&&(s=s.slice(r[0].length)||s),u.push(o=[])),n=!1,(r=I.exec(s))&&(n=r.shift(),o.push({value:n,type:r[0].replace(W," ")}),s=s.slice(n.length));for(a in i.filter)!(r=U[a].exec(s))||l[a]&&!(r=l[a](r))||(n=r.shift(),o.push({value:n,type:a,matches:r}),s=s.slice(n.length));if(!n)break}return t?s.length:s?st.error(e):E(e,u).slice(0)}function dt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function ht(e,t,n){var i=t.dir,o=n&&"parentNode"===i,a=C++;return t.first?function(t,n,r){while(t=t[i])if(1===t.nodeType||o)return e(t,n,r)}:function(t,n,s){var u,l,c,p=N+" "+a;if(s){while(t=t[i])if((1===t.nodeType||o)&&e(t,n,s))return!0}else while(t=t[i])if(1===t.nodeType||o)if(c=t[x]||(t[x]={}),(l=c[i])&&l[0]===p){if((u=l[1])===!0||u===r)return u===!0}else if(l=c[i]=[p],l[1]=e(t,n,s)||r,l[1]===!0)return!0}}function gt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function mt(e,t,n,r,i){var o,a=[],s=0,u=e.length,l=null!=t;for(;u>s;s++)(o=e[s])&&(!n||n(o,r,i))&&(a.push(o),l&&t.push(s));return a}function yt(e,t,n,r,i,o){return r&&!r[x]&&(r=yt(r)),i&&!i[x]&&(i=yt(i,o)),ot(function(o,a,s,u){var l,c,p,f=[],d=[],h=a.length,g=o||xt(t||"*",s.nodeType?[s]:s,[]),m=!e||!o&&t?g:mt(g,f,e,s,u),y=n?i||(o?e:h||r)?[]:a:m;if(n&&n(m,y,s,u),r){l=mt(y,d),r(l,[],s,u),c=l.length;while(c--)(p=l[c])&&(y[d[c]]=!(m[d[c]]=p))}if(o){if(i||e){if(i){l=[],c=y.length;while(c--)(p=y[c])&&l.push(m[c]=p);i(null,y=[],l,u)}c=y.length;while(c--)(p=y[c])&&(l=i?M.call(o,p):f[c])>-1&&(o[l]=!(a[l]=p))}}else y=mt(y===a?y.splice(h,y.length):y),i?i(null,a,y,u):H.apply(a,y)})}function vt(e){var t,n,r,o=e.length,a=i.relative[e[0].type],s=a||i.relative[" "],u=a?1:0,c=ht(function(e){return e===t},s,!0),p=ht(function(e){return M.call(t,e)>-1},s,!0),f=[function(e,n,r){return!a&&(r||n!==l)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;o>u;u++)if(n=i.relative[e[u].type])f=[ht(gt(f),n)];else{if(n=i.filter[e[u].type].apply(null,e[u].matches),n[x]){for(r=++u;o>r;r++)if(i.relative[e[r].type])break;return yt(u>1&>(f),u>1&&dt(e.slice(0,u-1)).replace(W,"$1"),n,r>u&&vt(e.slice(u,r)),o>r&&vt(e=e.slice(r)),o>r&&dt(e))}f.push(n)}return gt(f)}function bt(e,t){var n=0,o=t.length>0,a=e.length>0,s=function(s,u,c,f,d){var h,g,m,y=[],v=0,b="0",x=s&&[],w=null!=d,T=l,C=s||a&&i.find.TAG("*",d&&u.parentNode||u),k=N+=null==T?1:Math.random()||.1;for(w&&(l=u!==p&&u,r=n);null!=(h=C[b]);b++){if(a&&h){g=0;while(m=e[g++])if(m(h,u,c)){f.push(h);break}w&&(N=k,r=++n)}o&&((h=!m&&h)&&v--,s&&x.push(h))}if(v+=b,o&&b!==v){g=0;while(m=t[g++])m(x,y,u,c);if(s){if(v>0)while(b--)x[b]||y[b]||(y[b]=L.call(f));y=mt(y)}H.apply(f,y),w&&!s&&y.length>0&&v+t.length>1&&st.uniqueSort(f)}return w&&(N=k,l=T),x};return o?ot(s):s}s=st.compile=function(e,t){var n,r=[],i=[],o=S[e+" "];if(!o){t||(t=ft(e)),n=t.length;while(n--)o=vt(t[n]),o[x]?r.push(o):i.push(o);o=S(e,bt(i,r))}return o};function xt(e,t,n){var r=0,i=t.length;for(;i>r;r++)st(e,t[r],n);return n}function wt(e,t,n,r){var o,a,u,l,c,p=ft(e);if(!r&&1===p.length){if(a=p[0]=p[0].slice(0),a.length>2&&"ID"===(u=a[0]).type&&9===t.nodeType&&!d&&i.relative[a[1].type]){if(t=i.find.ID(u.matches[0].replace(et,tt),t)[0],!t)return n;e=e.slice(a.shift().value.length)}o=U.needsContext.test(e)?0:a.length;while(o--){if(u=a[o],i.relative[l=u.type])break;if((c=i.find[l])&&(r=c(u.matches[0].replace(et,tt),V.test(a[0].type)&&t.parentNode||t))){if(a.splice(o,1),e=r.length&&dt(a),!e)return H.apply(n,q.call(r,0)),n;break}}}return s(e,p)(r,t,d,n,V.test(e)),n}i.pseudos.nth=i.pseudos.eq;function Tt(){}i.filters=Tt.prototype=i.pseudos,i.setFilters=new Tt,c(),st.attr=b.attr,b.find=st,b.expr=st.selectors,b.expr[":"]=b.expr.pseudos,b.unique=st.uniqueSort,b.text=st.getText,b.isXMLDoc=st.isXML,b.contains=st.contains}(e);var at=/Until$/,st=/^(?:parents|prev(?:Until|All))/,ut=/^.[^:#\[\.,]*$/,lt=b.expr.match.needsContext,ct={children:!0,contents:!0,next:!0,prev:!0};b.fn.extend({find:function(e){var t,n,r,i=this.length;if("string"!=typeof e)return r=this,this.pushStack(b(e).filter(function(){for(t=0;i>t;t++)if(b.contains(r[t],this))return!0}));for(n=[],t=0;i>t;t++)b.find(e,this[t],n);return n=this.pushStack(i>1?b.unique(n):n),n.selector=(this.selector?this.selector+" ":"")+e,n},has:function(e){var t,n=b(e,this),r=n.length;return this.filter(function(){for(t=0;r>t;t++)if(b.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e,!1))},filter:function(e){return this.pushStack(ft(this,e,!0))},is:function(e){return!!e&&("string"==typeof e?lt.test(e)?b(e,this.context).index(this[0])>=0:b.filter(e,this).length>0:this.filter(e).length>0)},closest:function(e,t){var n,r=0,i=this.length,o=[],a=lt.test(e)||"string"!=typeof e?b(e,t||this.context):0;for(;i>r;r++){n=this[r];while(n&&n.ownerDocument&&n!==t&&11!==n.nodeType){if(a?a.index(n)>-1:b.find.matchesSelector(n,e)){o.push(n);break}n=n.parentNode}}return this.pushStack(o.length>1?b.unique(o):o)},index:function(e){return e?"string"==typeof e?b.inArray(this[0],b(e)):b.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?b(e,t):b.makeArray(e&&e.nodeType?[e]:e),r=b.merge(this.get(),n);return this.pushStack(b.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}}),b.fn.andSelf=b.fn.addBack;function pt(e,t){do e=e[t];while(e&&1!==e.nodeType);return e}b.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return b.dir(e,"parentNode")},parentsUntil:function(e,t,n){return b.dir(e,"parentNode",n)},next:function(e){return pt(e,"nextSibling")},prev:function(e){return pt(e,"previousSibling")},nextAll:function(e){return b.dir(e,"nextSibling")},prevAll:function(e){return b.dir(e,"previousSibling")},nextUntil:function(e,t,n){return b.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return b.dir(e,"previousSibling",n)},siblings:function(e){return b.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return b.sibling(e.firstChild)},contents:function(e){return b.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:b.merge([],e.childNodes)}},function(e,t){b.fn[e]=function(n,r){var i=b.map(this,t,n);return at.test(e)||(r=n),r&&"string"==typeof r&&(i=b.filter(r,i)),i=this.length>1&&!ct[e]?b.unique(i):i,this.length>1&&st.test(e)&&(i=i.reverse()),this.pushStack(i)}}),b.extend({filter:function(e,t,n){return n&&(e=":not("+e+")"),1===t.length?b.find.matchesSelector(t[0],e)?[t[0]]:[]:b.find.matches(e,t)},dir:function(e,n,r){var i=[],o=e[n];while(o&&9!==o.nodeType&&(r===t||1!==o.nodeType||!b(o).is(r)))1===o.nodeType&&i.push(o),o=o[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function ft(e,t,n){if(t=t||0,b.isFunction(t))return b.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return b.grep(e,function(e){return e===t===n});if("string"==typeof t){var r=b.grep(e,function(e){return 1===e.nodeType});if(ut.test(t))return b.filter(t,r,!n);t=b.filter(t,r)}return b.grep(e,function(e){return b.inArray(e,t)>=0===n})}function dt(e){var t=ht.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}var ht="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",gt=/ jQuery\d+="(?:null|\d+)"/g,mt=RegExp("<(?:"+ht+")[\\s/>]","i"),yt=/^\s+/,vt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,bt=/<([\w:]+)/,xt=/\s*$/g,At={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:b.support.htmlSerialize?[0,"",""]:[1,"X
","
"]},jt=dt(o),Dt=jt.appendChild(o.createElement("div"));At.optgroup=At.option,At.tbody=At.tfoot=At.colgroup=At.caption=At.thead,At.th=At.td,b.fn.extend({text:function(e){return b.access(this,function(e){return e===t?b.text(this):this.empty().append((this[0]&&this[0].ownerDocument||o).createTextNode(e))},null,e,arguments.length)},wrapAll:function(e){if(b.isFunction(e))return this.each(function(t){b(this).wrapAll(e.call(this,t))});if(this[0]){var t=b(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&1===e.firstChild.nodeType)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return b.isFunction(e)?this.each(function(t){b(this).wrapInner(e.call(this,t))}):this.each(function(){var t=b(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=b.isFunction(e);return this.each(function(n){b(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){b.nodeName(this,"body")||b(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(e){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&this.appendChild(e)})},prepend:function(){return this.domManip(arguments,!0,function(e){(1===this.nodeType||11===this.nodeType||9===this.nodeType)&&this.insertBefore(e,this.firstChild)})},before:function(){return this.domManip(arguments,!1,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,!1,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=0;for(;null!=(n=this[r]);r++)(!e||b.filter(e,[n]).length>0)&&(t||1!==n.nodeType||b.cleanData(Ot(n)),n.parentNode&&(t&&b.contains(n.ownerDocument,n)&&Mt(Ot(n,"script")),n.parentNode.removeChild(n)));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++){1===e.nodeType&&b.cleanData(Ot(e,!1));while(e.firstChild)e.removeChild(e.firstChild);e.options&&b.nodeName(e,"select")&&(e.options.length=0)}return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return b.clone(this,e,t)})},html:function(e){return b.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return 1===n.nodeType?n.innerHTML.replace(gt,""):t;if(!("string"!=typeof e||Tt.test(e)||!b.support.htmlSerialize&&mt.test(e)||!b.support.leadingWhitespace&&yt.test(e)||At[(bt.exec(e)||["",""])[1].toLowerCase()])){e=e.replace(vt,"<$1>");try{for(;i>r;r++)n=this[r]||{},1===n.nodeType&&(b.cleanData(Ot(n,!1)),n.innerHTML=e);n=0}catch(o){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(e){var t=b.isFunction(e);return t||"string"==typeof e||(e=b(e).not(this).detach()),this.domManip([e],!0,function(e){var t=this.nextSibling,n=this.parentNode;n&&(b(this).remove(),n.insertBefore(e,t))})},detach:function(e){return this.remove(e,!0)},domManip:function(e,n,r){e=f.apply([],e);var i,o,a,s,u,l,c=0,p=this.length,d=this,h=p-1,g=e[0],m=b.isFunction(g);if(m||!(1>=p||"string"!=typeof g||b.support.checkClone)&&Ct.test(g))return this.each(function(i){var o=d.eq(i);m&&(e[0]=g.call(this,i,n?o.html():t)),o.domManip(e,n,r)});if(p&&(l=b.buildFragment(e,this[0].ownerDocument,!1,this),i=l.firstChild,1===l.childNodes.length&&(l=i),i)){for(n=n&&b.nodeName(i,"tr"),s=b.map(Ot(l,"script"),Ht),a=s.length;p>c;c++)o=l,c!==h&&(o=b.clone(o,!0,!0),a&&b.merge(s,Ot(o,"script"))),r.call(n&&b.nodeName(this[c],"table")?Lt(this[c],"tbody"):this[c],o,c);if(a)for(u=s[s.length-1].ownerDocument,b.map(s,qt),c=0;a>c;c++)o=s[c],kt.test(o.type||"")&&!b._data(o,"globalEval")&&b.contains(u,o)&&(o.src?b.ajax({url:o.src,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0}):b.globalEval((o.text||o.textContent||o.innerHTML||"").replace(St,"")));l=i=null}return this}});function Lt(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function Ht(e){var t=e.getAttributeNode("type");return e.type=(t&&t.specified)+"/"+e.type,e}function qt(e){var t=Et.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function Mt(e,t){var n,r=0;for(;null!=(n=e[r]);r++)b._data(n,"globalEval",!t||b._data(t[r],"globalEval"))}function _t(e,t){if(1===t.nodeType&&b.hasData(e)){var n,r,i,o=b._data(e),a=b._data(t,o),s=o.events;if(s){delete a.handle,a.events={};for(n in s)for(r=0,i=s[n].length;i>r;r++)b.event.add(t,n,s[n][r])}a.data&&(a.data=b.extend({},a.data))}}function Ft(e,t){var n,r,i;if(1===t.nodeType){if(n=t.nodeName.toLowerCase(),!b.support.noCloneEvent&&t[b.expando]){i=b._data(t);for(r in i.events)b.removeEvent(t,r,i.handle);t.removeAttribute(b.expando)}"script"===n&&t.text!==e.text?(Ht(t).text=e.text,qt(t)):"object"===n?(t.parentNode&&(t.outerHTML=e.outerHTML),b.support.html5Clone&&e.innerHTML&&!b.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):"input"===n&&Nt.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):"option"===n?t.defaultSelected=t.selected=e.defaultSelected:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}}b.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){b.fn[e]=function(e){var n,r=0,i=[],o=b(e),a=o.length-1;for(;a>=r;r++)n=r===a?this:this.clone(!0),b(o[r])[t](n),d.apply(i,n.get());return this.pushStack(i)}});function Ot(e,n){var r,o,a=0,s=typeof e.getElementsByTagName!==i?e.getElementsByTagName(n||"*"):typeof e.querySelectorAll!==i?e.querySelectorAll(n||"*"):t;if(!s)for(s=[],r=e.childNodes||e;null!=(o=r[a]);a++)!n||b.nodeName(o,n)?s.push(o):b.merge(s,Ot(o,n));return n===t||n&&b.nodeName(e,n)?b.merge([e],s):s}function Bt(e){Nt.test(e.type)&&(e.defaultChecked=e.checked)}b.extend({clone:function(e,t,n){var r,i,o,a,s,u=b.contains(e.ownerDocument,e);if(b.support.html5Clone||b.isXMLDoc(e)||!mt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(Dt.innerHTML=e.outerHTML,Dt.removeChild(o=Dt.firstChild)),!(b.support.noCloneEvent&&b.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||b.isXMLDoc(e)))for(r=Ot(o),s=Ot(e),a=0;null!=(i=s[a]);++a)r[a]&&Ft(i,r[a]);if(t)if(n)for(s=s||Ot(e),r=r||Ot(o),a=0;null!=(i=s[a]);a++)_t(i,r[a]);else _t(e,o);return r=Ot(o,"script"),r.length>0&&Mt(r,!u&&Ot(e,"script")),r=s=i=null,o},buildFragment:function(e,t,n,r){var i,o,a,s,u,l,c,p=e.length,f=dt(t),d=[],h=0;for(;p>h;h++)if(o=e[h],o||0===o)if("object"===b.type(o))b.merge(d,o.nodeType?[o]:o);else if(wt.test(o)){s=s||f.appendChild(t.createElement("div")),u=(bt.exec(o)||["",""])[1].toLowerCase(),c=At[u]||At._default,s.innerHTML=c[1]+o.replace(vt,"<$1>")+c[2],i=c[0];while(i--)s=s.lastChild;if(!b.support.leadingWhitespace&&yt.test(o)&&d.push(t.createTextNode(yt.exec(o)[0])),!b.support.tbody){o="table"!==u||xt.test(o)?""!==c[1]||xt.test(o)?0:s:s.firstChild,i=o&&o.childNodes.length;while(i--)b.nodeName(l=o.childNodes[i],"tbody")&&!l.childNodes.length&&o.removeChild(l) -}b.merge(d,s.childNodes),s.textContent="";while(s.firstChild)s.removeChild(s.firstChild);s=f.lastChild}else d.push(t.createTextNode(o));s&&f.removeChild(s),b.support.appendChecked||b.grep(Ot(d,"input"),Bt),h=0;while(o=d[h++])if((!r||-1===b.inArray(o,r))&&(a=b.contains(o.ownerDocument,o),s=Ot(f.appendChild(o),"script"),a&&Mt(s),n)){i=0;while(o=s[i++])kt.test(o.type||"")&&n.push(o)}return s=null,f},cleanData:function(e,t){var n,r,o,a,s=0,u=b.expando,l=b.cache,p=b.support.deleteExpando,f=b.event.special;for(;null!=(n=e[s]);s++)if((t||b.acceptData(n))&&(o=n[u],a=o&&l[o])){if(a.events)for(r in a.events)f[r]?b.event.remove(n,r):b.removeEvent(n,r,a.handle);l[o]&&(delete l[o],p?delete n[u]:typeof n.removeAttribute!==i?n.removeAttribute(u):n[u]=null,c.push(o))}}});var Pt,Rt,Wt,$t=/alpha\([^)]*\)/i,It=/opacity\s*=\s*([^)]*)/,zt=/^(top|right|bottom|left)$/,Xt=/^(none|table(?!-c[ea]).+)/,Ut=/^margin/,Vt=RegExp("^("+x+")(.*)$","i"),Yt=RegExp("^("+x+")(?!px)[a-z%]+$","i"),Jt=RegExp("^([+-])=("+x+")","i"),Gt={BODY:"block"},Qt={position:"absolute",visibility:"hidden",display:"block"},Kt={letterSpacing:0,fontWeight:400},Zt=["Top","Right","Bottom","Left"],en=["Webkit","O","Moz","ms"];function tn(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=en.length;while(i--)if(t=en[i]+n,t in e)return t;return r}function nn(e,t){return e=t||e,"none"===b.css(e,"display")||!b.contains(e.ownerDocument,e)}function rn(e,t){var n,r,i,o=[],a=0,s=e.length;for(;s>a;a++)r=e[a],r.style&&(o[a]=b._data(r,"olddisplay"),n=r.style.display,t?(o[a]||"none"!==n||(r.style.display=""),""===r.style.display&&nn(r)&&(o[a]=b._data(r,"olddisplay",un(r.nodeName)))):o[a]||(i=nn(r),(n&&"none"!==n||!i)&&b._data(r,"olddisplay",i?n:b.css(r,"display"))));for(a=0;s>a;a++)r=e[a],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[a]||"":"none"));return e}b.fn.extend({css:function(e,n){return b.access(this,function(e,n,r){var i,o,a={},s=0;if(b.isArray(n)){for(o=Rt(e),i=n.length;i>s;s++)a[n[s]]=b.css(e,n[s],!1,o);return a}return r!==t?b.style(e,n,r):b.css(e,n)},e,n,arguments.length>1)},show:function(){return rn(this,!0)},hide:function(){return rn(this)},toggle:function(e){var t="boolean"==typeof e;return this.each(function(){(t?e:nn(this))?b(this).show():b(this).hide()})}}),b.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Wt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":b.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var o,a,s,u=b.camelCase(n),l=e.style;if(n=b.cssProps[u]||(b.cssProps[u]=tn(l,u)),s=b.cssHooks[n]||b.cssHooks[u],r===t)return s&&"get"in s&&(o=s.get(e,!1,i))!==t?o:l[n];if(a=typeof r,"string"===a&&(o=Jt.exec(r))&&(r=(o[1]+1)*o[2]+parseFloat(b.css(e,n)),a="number"),!(null==r||"number"===a&&isNaN(r)||("number"!==a||b.cssNumber[u]||(r+="px"),b.support.clearCloneStyle||""!==r||0!==n.indexOf("background")||(l[n]="inherit"),s&&"set"in s&&(r=s.set(e,r,i))===t)))try{l[n]=r}catch(c){}}},css:function(e,n,r,i){var o,a,s,u=b.camelCase(n);return n=b.cssProps[u]||(b.cssProps[u]=tn(e.style,u)),s=b.cssHooks[n]||b.cssHooks[u],s&&"get"in s&&(a=s.get(e,!0,r)),a===t&&(a=Wt(e,n,i)),"normal"===a&&n in Kt&&(a=Kt[n]),""===r||r?(o=parseFloat(a),r===!0||b.isNumeric(o)?o||0:a):a},swap:function(e,t,n,r){var i,o,a={};for(o in t)a[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=a[o];return i}}),e.getComputedStyle?(Rt=function(t){return e.getComputedStyle(t,null)},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),u=s?s.getPropertyValue(n)||s[n]:t,l=e.style;return s&&(""!==u||b.contains(e.ownerDocument,e)||(u=b.style(e,n)),Yt.test(u)&&Ut.test(n)&&(i=l.width,o=l.minWidth,a=l.maxWidth,l.minWidth=l.maxWidth=l.width=u,u=s.width,l.width=i,l.minWidth=o,l.maxWidth=a)),u}):o.documentElement.currentStyle&&(Rt=function(e){return e.currentStyle},Wt=function(e,n,r){var i,o,a,s=r||Rt(e),u=s?s[n]:t,l=e.style;return null==u&&l&&l[n]&&(u=l[n]),Yt.test(u)&&!zt.test(n)&&(i=l.left,o=e.runtimeStyle,a=o&&o.left,a&&(o.left=e.currentStyle.left),l.left="fontSize"===n?"1em":u,u=l.pixelLeft+"px",l.left=i,a&&(o.left=a)),""===u?"auto":u});function on(e,t,n){var r=Vt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function an(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,a=0;for(;4>o;o+=2)"margin"===n&&(a+=b.css(e,n+Zt[o],!0,i)),r?("content"===n&&(a-=b.css(e,"padding"+Zt[o],!0,i)),"margin"!==n&&(a-=b.css(e,"border"+Zt[o]+"Width",!0,i))):(a+=b.css(e,"padding"+Zt[o],!0,i),"padding"!==n&&(a+=b.css(e,"border"+Zt[o]+"Width",!0,i)));return a}function sn(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=Rt(e),a=b.support.boxSizing&&"border-box"===b.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=Wt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Yt.test(i))return i;r=a&&(b.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+an(e,t,n||(a?"border":"content"),r,o)+"px"}function un(e){var t=o,n=Gt[e];return n||(n=ln(e,t),"none"!==n&&n||(Pt=(Pt||b("