Skip to content

Commit

Permalink
Fix coding standards in Test/Case/Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Mar 12, 2012
1 parent 75f1a84 commit edb5829
Show file tree
Hide file tree
Showing 20 changed files with 111 additions and 127 deletions.
2 changes: 2 additions & 0 deletions lib/Cake/Test/Case/Controller/Component/Acl/DbAclTest.php
Expand Up @@ -163,6 +163,7 @@ public function __construct() {
$this->Aco = new AcoTwoTest();
$this->Aro->Permission = new PermissionTwoTest();
}

}

/**
Expand All @@ -171,6 +172,7 @@ public function __construct() {
* @package Cake.Test.Case.Controller.Component.Acl
*/
class DbAclTest extends CakeTestCase {

/**
* fixtures property
*
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Controller/Component/Acl/IniAclTest.php
Expand Up @@ -31,7 +31,7 @@ class IniAclTest extends CakeTestCase {
* @return void
*/
public function testCheck() {
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS . 'acl.ini.php';
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'acl.ini.php';

$Ini = new IniAcl();
$Ini->config = $Ini->readConfigFile($iniFile);
Expand All @@ -54,7 +54,7 @@ public function testCheck() {
* @return void
*/
public function testCheckArray() {
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS . 'acl.ini.php';
$iniFile = CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'acl.ini.php';

$Ini = new IniAcl();
$Ini->config = $Ini->readConfigFile($iniFile);
Expand Down
27 changes: 8 additions & 19 deletions lib/Cake/Test/Case/Controller/Component/Acl/PhpAclTest.php
Expand Up @@ -34,12 +34,11 @@ public function setUp() {
$this->PhpAcl = new PhpAcl();
$this->Acl = new AclComponent($Collection, array(
'adapter' => array(
'config' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config'. DS . 'acl.php',
'config' => CAKE . 'Test' . DS . 'test_app' . DS . 'Config' . DS . 'acl.php',
),
));
}


public function testRoleInheritance() {
$roles = $this->Acl->Aro->roles('User/peter');
$this->assertEquals(array('Role/accounting'), $roles[0]);
Expand All @@ -52,14 +51,12 @@ public function testRoleInheritance() {
$this->assertEquals(array('User/hardy'), $roles[3]);
}


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'));
}


public function testAroResolve() {
$map = $this->Acl->Aro->map;
$this->Acl->Aro->map = array(
Expand All @@ -73,7 +70,7 @@ public function testAroResolve() {
$this->assertEquals('User/hardy', $this->Acl->Aro->resolve(array('FooModel' => array('nickname' => 'hardy'))));
$this->assertEquals('Role/admin', $this->Acl->Aro->resolve(array('FooModel' => array('role' => 'admin'))));
$this->assertEquals('Role/admin', $this->Acl->Aro->resolve('Role/admin'));

$this->assertEquals('Role/admin', $this->Acl->Aro->resolve('admin'));
$this->assertEquals('Role/admin', $this->Acl->Aro->resolve('FooModel/admin'));
$this->assertEquals('Role/accounting', $this->Acl->Aro->resolve('accounting'));
Expand All @@ -93,7 +90,7 @@ public function testAroAliases() {

$this->Acl->Aro->aliases = array(
'Role/1' => 'Role/admin',
'Role/24' => 'Role/accounting',
'Role/24' => 'Role/accounting',
);

$user = array(
Expand Down Expand Up @@ -127,12 +124,11 @@ public function testAroAliases() {
$this->assertFalse($this->Acl->check($user, '/controllers/users/dashboard'));

$this->assertFalse($this->Acl->check($user, '/controllers/invoices/send'));
// wee add an more specific entry for user foo to also inherit from Role/accounting
// wee add an more specific entry for user foo to also inherit from Role/accounting
$this->Acl->Aro->addRole(array('User/foo' => 'Role/IT, Role/accounting'));
$this->assertTrue($this->Acl->check($user, '/controllers/invoices/send'));
}


/**
* test check method
*
Expand All @@ -146,7 +142,7 @@ public function testCheck() {
$this->assertTrue($this->Acl->check('jan', 'foo/bar'));
$this->assertTrue($this->Acl->check('user/jan', 'foo/bar'));
$this->assertTrue($this->Acl->check('Role/admin', 'controllers/bar'));
$this->assertTrue($this->Acl->check(array('User' => array('username' =>'jan')), '/controllers/bar/bll'));
$this->assertTrue($this->Acl->check(array('User' => array('username' => 'jan')), '/controllers/bar/bll'));
$this->assertTrue($this->Acl->check('Role/database_manager', 'controllers/db/create'));
$this->assertTrue($this->Acl->check('User/db_manager_2', 'controllers/db/create'));
$this->assertFalse($this->Acl->check('db_manager_2', '/controllers/users/Dashboard'));
Expand Down Expand Up @@ -184,7 +180,6 @@ public function testCheck() {
$this->assertFalse($this->Acl->check('role/accounting', 'controllers/articles/publish'));
}


/**
* lhs of defined rules are case insensitive
*/
Expand All @@ -195,7 +190,6 @@ public function testCheckIsCaseInsensitive() {
$this->assertTrue($this->Acl->check('Role/data_acquirer', 'controllers/FORMS/NEW'));
}


/**
* allow should work in-memory
*/
Expand All @@ -216,7 +210,6 @@ public function testAllow() {
$this->assertFalse($this->Acl->check('Role/reports', 'foo/bar'));
}


/**
* deny should work in-memory
*/
Expand All @@ -231,11 +224,10 @@ public function testDeny() {
$this->assertTrue($this->Acl->check('stan', 'controllers/baz/manager_foooooo'));
}


/**
* test that a deny rule wins over an equally specific allow rule
*/
public function testDenyRuleIsStrongerThanAllowRule() {
public function testDenyRuleIsStrongerThanAllowRule() {
$this->assertFalse($this->Acl->check('peter', 'baz/bam'));
$this->Acl->allow('peter', 'baz/bam');
$this->assertTrue($this->Acl->check('peter', 'baz/bam'));
Expand All @@ -256,7 +248,6 @@ public function testDenyRuleIsStrongerThanAllowRule() {
$this->assertFalse($this->Acl->check('stan', 'controllers/reports/delete'));
}


/**
* test that an invalid configuration throws exception
*/
Expand All @@ -269,7 +260,6 @@ public function testInvalidConfigWithAroMissing() {
$this->PhpAcl->build($config);
}


public function testInvalidConfigWithAcosMissing() {
$this->setExpectedException(
'AclException',
Expand All @@ -291,7 +281,7 @@ public function testAcoResolve() {
$this->assertEquals(array('foo', 'bar'), $this->Acl->Aco->resolve('foo/bar'));
$this->assertEquals(array('foo', 'bar', 'baz'), $this->Acl->Aco->resolve('foo/bar/baz'));
$this->assertEquals(array('foo', '*-bar', '?-baz'), $this->Acl->Aco->resolve('foo/*-bar/?-baz'));

$this->assertEquals(array('foo', 'bar', '[a-f0-9]{24}', '*_bla', 'bla'), $this->Acl->Aco->resolve('foo/bar/[a-f0-9]{24}/*_bla/bla'));

// multiple slashes will be squashed to a single, trimmed and then exploded
Expand All @@ -318,14 +308,13 @@ public function testAroDeclarationContainsCycles() {
'allow' => array(
'*' => 'Role/a',
),
),
),
);

$this->expectError('PHPUnit_Framework_Error', 'cycle detected' /* ... */);
$this->PhpAcl->build($config);
}


/**
* test that with policy allow, only denies count
*/
Expand Down
Expand Up @@ -25,6 +25,7 @@ class_exists('AclComponent');
* @package Cake.Test.Case.Controller.Component
*/
class AclComponentTest extends CakeTestCase {

/**
* setUp method
*
Expand Down
Expand Up @@ -24,7 +24,7 @@
App::uses('CakeResponse', 'Network');


require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';

/**
* Test case for BasicAuthentication
Expand Down
Expand Up @@ -114,7 +114,6 @@ public function testAuthorizeCheckFailure() {
$this->assertFalse($this->auth->authorize($user['User'], $request));
}


/**
* test getting actionMap
*
Expand Down
Expand Up @@ -22,7 +22,7 @@
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');

require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';

/**
* Test case for DigestAuthentication
Expand Down
Expand Up @@ -23,7 +23,7 @@
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');

require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';
require_once CAKE . 'Test' . DS . 'Case' . DS . 'Model' . DS . 'models.php';

/**
* Test case for FormAuthentication
Expand Down
47 changes: 23 additions & 24 deletions lib/Cake/Test/Case/Controller/Component/AuthComponentTest.php
Expand Up @@ -23,11 +23,11 @@
App::uses('FormAuthenticate', 'Controller/Component/Auth');

/**
* TestAuthComponent class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
* TestAuthComponent class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class TestAuthComponent extends AuthComponent {

/**
Expand All @@ -53,11 +53,11 @@ public static function clearUser() {
}

/**
* AuthUser class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
* AuthUser class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class AuthUser extends CakeTestModel {

/**
Expand All @@ -77,11 +77,11 @@ class AuthUser extends CakeTestModel {
}

/**
* AuthTestController class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
* AuthTestController class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class AuthTestController extends Controller {

/**
Expand Down Expand Up @@ -155,7 +155,6 @@ public function admin_add() {
* @return void
*/
public function logout() {

}

/**
Expand Down Expand Up @@ -195,7 +194,6 @@ public function redirect($url, $status = null, $exit = true) {
* @return void
*/
public function isAuthorized() {

}

}
Expand Down Expand Up @@ -269,14 +267,15 @@ public function redirect($url, $status = null, $exit = true) {
$this->testUrl = Router::url($url);
return false;
}

}

/**
* AuthComponentTest class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
* AuthComponentTest class
*
* @package Cake.Test.Case.Controller.Component
* @package Cake.Test.Case.Controller.Component
*/
class AuthComponentTest extends CakeTestCase {

/**
Expand Down Expand Up @@ -951,7 +950,7 @@ public function testAdminRoute() {
*/
public function testAjaxLogin() {
App::build(array(
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View'. DS)
'View' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'View' . DS)
));
$_SERVER['HTTP_X_REQUESTED_WITH'] = "XMLHttpRequest";

Expand Down Expand Up @@ -1225,6 +1224,6 @@ public function testPassword() {
$result = $this->Auth->password('password');
$expected = Security::hash('password', null, true);
$this->assertEquals($expected, $result);

}

}
10 changes: 5 additions & 5 deletions lib/Cake/Test/Case/Controller/Component/CookieComponentTest.php
Expand Up @@ -49,6 +49,7 @@ public function beforeFilter() {
$this->Cookie->secure = false;
$this->Cookie->key = 'somerandomhaskey';
}

}

/**
Expand Down Expand Up @@ -191,7 +192,7 @@ public function testWriteHttpOnly() {
$this->Cookie->secure = false;
$this->Cookie->write('Testing', 'value', false);
$expected = array(
'name' => $this->Cookie->name.'[Testing]',
'name' => $this->Cookie->name . '[Testing]',
'value' => 'value',
'expire' => time() + 10,
'path' => '/',
Expand All @@ -212,7 +213,7 @@ public function testDeleteHttpOnly() {
$this->Cookie->secure = false;
$this->Cookie->delete('Testing', false);
$expected = array(
'name' => $this->Cookie->name.'[Testing]',
'name' => $this->Cookie->name . '[Testing]',
'value' => '',
'expire' => time() - 42000,
'path' => '/',
Expand Down Expand Up @@ -249,14 +250,14 @@ public function testWriteArrayValues() {
$this->Cookie->secure = false;
$this->Cookie->write('Testing', array(1, 2, 3), false);
$expected = array(
'name' => $this->Cookie->name.'[Testing]',
'name' => $this->Cookie->name . '[Testing]',
'value' => '[1,2,3]',
'expire' => time() + 10,
'path' => '/',
'domain' => '',
'secure' => false,
'httpOnly' => false);
$result = $this->Controller->response->cookie($this->Cookie->name.'[Testing]');
$result = $this->Controller->response->cookie($this->Cookie->name . '[Testing]');
$this->assertEquals($result, $expected);
}

Expand Down Expand Up @@ -516,7 +517,6 @@ public function testNoErrorOnNonArrayData() {
$this->assertNull($this->Cookie->read('value'));
}


/**
* test that deleting a top level keys kills the child elements too.
*
Expand Down

0 comments on commit edb5829

Please sign in to comment.