Upgrade CakePHP from 2.2.5 to 2.9.5

This commit is contained in:
Brm Ko 2017-02-26 15:29:44 +01:00
parent 5a580df460
commit 235a541597
793 changed files with 60746 additions and 23753 deletions

View file

@ -2,19 +2,18 @@
/**
* DbAclTest file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Acl
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('ComponentCollection', 'Controller');
@ -34,14 +33,14 @@ class AclNodeTwoTestBase extends AclNode {
/**
* useDbConfig property
*
* @var string 'test'
* @var string
*/
public $useDbConfig = 'test';
/**
* cacheSources property
*
* @var bool false
* @var bool
*/
public $cacheSources = false;
}
@ -56,14 +55,14 @@ class AroTwoTest extends AclNodeTwoTestBase {
/**
* name property
*
* @var string 'AroTwoTest'
* @var string
*/
public $name = 'AroTwoTest';
/**
* useTable property
*
* @var string 'aro_twos'
* @var string
*/
public $useTable = 'aro_twos';
@ -85,14 +84,14 @@ class AcoTwoTest extends AclNodeTwoTestBase {
/**
* name property
*
* @var string 'AcoTwoTest'
* @var string
*/
public $name = 'AcoTwoTest';
/**
* useTable property
*
* @var string 'aco_twos'
* @var string
*/
public $useTable = 'aco_twos';
@ -114,21 +113,21 @@ class PermissionTwoTest extends Permission {
/**
* name property
*
* @var string 'PermissionTwoTest'
* @var string
*/
public $name = 'PermissionTwoTest';
/**
* useTable property
*
* @var string 'aros_aco_twos'
* @var string
*/
public $useTable = 'aros_aco_twos';
/**
* cacheQueries property
*
* @var bool false
* @var bool
*/
public $cacheQueries = false;
@ -142,7 +141,7 @@ class PermissionTwoTest extends Permission {
/**
* actsAs property
*
* @var mixed null
* @var mixed
*/
public $actsAs = null;
}
@ -156,8 +155,6 @@ class DbAclTwoTest extends DbAcl {
/**
* construct method
*
* @return void
*/
public function __construct() {
$this->Aro = new AroTwoTest();
@ -258,7 +255,6 @@ class DbAclTest extends CakeTestCase {
/**
* testDbAclAllow method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testAllow() {
@ -282,7 +278,7 @@ class DbAclTest extends CakeTestCase {
$this->assertTrue($this->Acl->check('Samir', 'view', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update','*'));
$this->assertFalse($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', '*'));
$this->assertTrue($this->Acl->allow('root/users/Samir', 'ROOT/tpsReports/update', '*'));
$this->assertTrue($this->Acl->check('Samir', 'update', 'read'));
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/update', 'update'));
@ -292,14 +288,23 @@ class DbAclTest extends CakeTestCase {
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
}
/**
* Test that allow() with an invalid permission name triggers an error.
*
* @expectedException CakeException
* @return void
*/
public function testAllowInvalidPermission() {
$this->assertFalse($this->Acl->allow('Micheal', 'tpsReports', 'derp'));
}
/**
* testAllowInvalidNode method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testAllowInvalidNode() {
$this->Acl->allow('Homer', 'tpsReports', 'create');
$this->assertFalse($this->Acl->allow('Homer', 'tpsReports', 'create'));
}
/**
@ -325,7 +330,6 @@ class DbAclTest extends CakeTestCase {
/**
* testCheckInvalidNode method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testCheckInvalidNode() {
@ -335,21 +339,19 @@ class DbAclTest extends CakeTestCase {
/**
* testCheckInvalidPermission method
*
* @expectedException PHPUnit_Framework_Error_Notice
* @return void
*/
public function testCheckInvalidPermission() {
$this->Acl->check('Lumbergh', 'smash', 'foobar');
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
}
/**
* testCheckMissingPermission method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testCheckMissingPermission() {
$this->Acl->check('users', 'NonExistent', 'read');
$this->assertFalse($this->Acl->check('users', 'NonExistent', 'read'));
}
/**
@ -372,7 +374,6 @@ class DbAclTest extends CakeTestCase {
/**
* testDbAclDeny method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testDeny() {
@ -428,21 +429,63 @@ class DbAclTest extends CakeTestCase {
* @return void
*/
public function testInherit() {
//parent doesn't have access inherit should still deny
// parent doesn't have access inherit should still deny
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
$this->Acl->inherit('Milton', 'smash', 'delete');
$this->assertFalse($this->Acl->check('Milton', 'smash', 'delete'));
//inherit parent
// inherit parent
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
$this->Acl->inherit('Milton', 'smash', 'read');
$this->assertTrue($this->Acl->check('Milton', 'smash', 'read'));
}
/**
* test inherit from deny method
*
* @return void
*/
public function testInheritParentDeny() {
$this->Acl->Aco->create(array('parent_id' => null, 'alias' => 'world'));
$this->Acl->Aco->save();
$this->Acl->Aco->create(array('parent_id' => $this->Acl->Aco->id, 'alias' => 'town'));
$this->Acl->Aco->save();
$this->Acl->Aco->create(array('parent_id' => null, 'alias' => 'bizzaro_world'));
$this->Acl->Aco->save();
$this->Acl->Aco->create(array('parent_id' => $this->Acl->Aco->id, 'alias' => 'bizzaro_town'));
$this->Acl->Aco->save();
$this->Acl->Aro->create(array('parent_id' => null, 'alias' => 'Jane'));
$this->Acl->Aro->save();
// Setup deny on create for parent
$this->Acl->allow('Jane', 'world', '*');
$this->Acl->deny('Jane', 'world', 'create');
// Setup inherit and specify allow for create on child.
$this->Acl->inherit('Jane', 'town', '*');
$this->Acl->allow('Jane', 'town', 'create');
// Setup deny on create for parent
$this->Acl->deny('Jane', 'bizzaro_world', '*');
$this->Acl->allow('Jane', 'bizzaro_world', 'create');
// Setup inherit.
$this->Acl->inherit('Jane', 'bizzaro_town', '*');
$this->assertTrue($this->Acl->check('Jane', 'town', 'create'), 'Should have access due to override');
$this->assertTrue($this->Acl->check('Jane', 'town', '*'), 'Should have access due to inherit');
$this->assertTrue($this->Acl->check('Jane', 'bizzaro_town', 'create'), 'Should have access due explicit allow');
$this->assertFalse($this->Acl->check('Jane', 'bizzaro_town', '*'), 'Should not have access due to inherit');
}
/**
* testDbGrant method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testGrant() {
@ -463,7 +506,6 @@ class DbAclTest extends CakeTestCase {
/**
* testDbRevoke method
*
* @expectedException PHPUnit_Framework_Error_Warning
* @return void
*/
public function testRevoke() {
@ -503,12 +545,12 @@ class DbAclTest extends CakeTestCase {
$perms = '';
foreach ($rights as $right) {
if ($this->Acl->check($aro, $aco, $right)) {
if ($right == '*') {
if ($right === '*') {
$perms .= '****';
break;
}
$perms .= $right[0];
} elseif ($right != '*') {
} elseif ($right !== '*') {
$perms .= ' ';
}
}
@ -519,9 +561,9 @@ class DbAclTest extends CakeTestCase {
foreach ($permissions as $key => $values) {
array_unshift($values, $key);
$values = array_map(array(&$this, '_pad'), $values);
$permissions[$key] = implode (' ', $values);
$permissions[$key] = implode(' ', $values);
}
$permisssions = array_map(array(&$this, '_pad'), $permissions);
$permissions = array_map(array(&$this, '_pad'), $permissions);
array_unshift($permissions, 'Current Permissions :');
if ($printTreesToo) {
debug(array('aros' => $this->Acl->Aro->generateTreeList(), 'acos' => $this->Acl->Aco->generateTreeList()));
@ -534,7 +576,7 @@ class DbAclTest extends CakeTestCase {
* Used by debug to format strings used in the data dump
*
* @param string $string
* @param integer $len
* @param int $len
* @return void
*/
protected function _pad($string = '', $len = 14) {

View file

@ -2,20 +2,20 @@
/**
* IniAclTest file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Acl
* @since CakePHP(tm) v 2.0
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('IniAcl', 'Controller/Component/Acl');
/**
@ -66,4 +66,3 @@ class IniAclTest extends CakeTestCase {
$this->assertTrue($Ini->check($user, 'posts'));
}
}

View file

@ -2,19 +2,18 @@
/**
* PhpAclTest file.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package Cake.Test.Case.Controller.Component.Acl
* @since CakePHP(tm) v 2.1
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
App::uses('AclComponent', 'Controller/Component');
@ -28,6 +27,11 @@ class_exists('AclComponent');
*/
class PhpAclTest extends CakeTestCase {
/**
* Setup
*
* @return void
*/
public function setUp() {
parent::setUp();
Configure::write('Acl.classname', 'PhpAcl');
@ -40,6 +44,11 @@ class PhpAclTest extends CakeTestCase {
));
}
/**
* Test role inheritance
*
* @return void
*/
public function testRoleInheritance() {
$roles = $this->Acl->Aro->roles('User/peter');
$this->assertEquals(array('Role/accounting'), $roles[0]);
@ -52,14 +61,23 @@ class PhpAclTest extends CakeTestCase {
$this->assertEquals(array('User/hardy'), $roles[3]);
}
/**
* Test adding a role
*
* @return void
*/
public function testAddRole() {
$this->assertEquals(array(array(PhpAro::DEFAULT_ROLE)), $this->Acl->Aro->roles('foobar'));
$this->Acl->Aro->addRole(array('User/foobar' => 'Role/accounting'));
$this->assertEquals(array(array('Role/accounting'), array('User/foobar')), $this->Acl->Aro->roles('foobar'));
}
/**
* Test resolving ARO
*
* @return void
*/
public function testAroResolve() {
$map = $this->Acl->Aro->map;
$this->Acl->Aro->map = array(
'User' => 'FooModel/nickname',
'Role' => 'FooModel/role',
@ -82,6 +100,8 @@ class PhpAclTest extends CakeTestCase {
/**
* test correct resolution of defined aliases
*
* @return void
*/
public function testAroAliases() {
$this->Acl->Aro->map = array(
@ -118,7 +138,7 @@ class PhpAclTest extends CakeTestCase {
$this->Acl->Aro->addAlias(array('Role/25' => 'Role/IT'));
$this->Acl->allow('Role/IT', '/rules/debugging/*');
$this->assertEquals(array(array('Role/IT', )), $this->Acl->Aro->roles($user));
$this->assertEquals(array(array('Role/IT')), $this->Acl->Aro->roles($user));
$this->assertTrue($this->Acl->check($user, '/rules/debugging/stats/pageload'));
$this->assertTrue($this->Acl->check($user, '/rules/debugging/sql/queries'));
// Role/default is allowed users dashboard, but not Role/IT
@ -183,6 +203,8 @@ class PhpAclTest extends CakeTestCase {
/**
* lhs of defined rules are case insensitive
*
* @return void
*/
public function testCheckIsCaseInsensitive() {
$this->assertTrue($this->Acl->check('hardy', 'controllers/forms/new'));
@ -193,6 +215,8 @@ class PhpAclTest extends CakeTestCase {
/**
* allow should work in-memory
*
* @return void
*/
public function testAllow() {
$this->assertFalse($this->Acl->check('jeff', 'foo/bar'));
@ -213,6 +237,8 @@ class PhpAclTest extends CakeTestCase {
/**
* deny should work in-memory
*
* @return void
*/
public function testDeny() {
$this->assertTrue($this->Acl->check('stan', 'controllers/baz/manager_foo'));
@ -227,6 +253,8 @@ class PhpAclTest extends CakeTestCase {
/**
* test that a deny rule wins over an equally specific allow rule
*
* @return void
*/
public function testDenyRuleIsStrongerThanAllowRule() {
$this->assertFalse($this->Acl->check('peter', 'baz/bam'));
@ -251,6 +279,8 @@ class PhpAclTest extends CakeTestCase {
/**
* test that an invalid configuration throws exception
*
* @return void
*/
public function testInvalidConfigWithAroMissing() {
$this->setExpectedException(
@ -276,6 +306,8 @@ class PhpAclTest extends CakeTestCase {
/**
* test resolving of ACOs
*
* @return void
*/
public function testAcoResolve() {
$this->assertEquals(array('foo', 'bar'), $this->Acl->Aco->resolve('foo/bar'));
@ -295,6 +327,8 @@ class PhpAclTest extends CakeTestCase {
/**
* test that declaring cyclic dependencies should give an error when building the tree
*
* @return void
*/
public function testAroDeclarationContainsCycles() {
$config = array(
@ -318,6 +352,8 @@ class PhpAclTest extends CakeTestCase {
/**
* test that with policy allow, only denies count
*
* @return void
*/
public function testPolicy() {
// allow by default
@ -334,4 +370,5 @@ class PhpAclTest extends CakeTestCase {
$this->assertFalse($this->Acl->check('Role/sales', 'controllers/bar/delete'));
$this->assertFalse($this->Acl->check('Role/sales', 'controllers/bar', 'delete'));
}
}