Skip to content

Commit

Permalink
Migrating AclComponent test to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
José Lorenzo Rodríguez Urdaneta authored and José Lorenzo Rodríguez Urdaneta committed Jun 11, 2010
1 parent 42e02bf commit 754376c
Showing 1 changed file with 57 additions and 24 deletions.
81 changes: 57 additions & 24 deletions cake/tests/cases/libs/controller/components/acl.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ function __construct() {
}
}

Mock::generate('AclInterface', 'MockAclImplementation');

/**
* Short description for class.
*
Expand All @@ -196,7 +194,10 @@ class AclComponentTest extends CakeTestCase {
* @access public
* @return void
*/
function startTest() {
function setUp() {
if (!class_exists('MockAclImplementation', false)) {
$this->getMock('AclInterface', array(), array(), 'MockAclImplementation');
}
Configure::write('Acl.classname', 'MockAclImplementation');
$this->Acl = new AclComponent();
}
Expand Down Expand Up @@ -230,7 +231,7 @@ function testConstrutorException() {
*/
function testAdapter() {
$implementation = new MockAclImplementation();
$implementation->expectOnce('initialize', array($this->Acl));
$implementation->expects($this->once())->method('initialize')->with($this->Acl);
$this->assertNull($this->Acl->adapter($implementation));

$this->assertEqual($this->Acl->adapter(), $implementation, 'Returned object is different %s');
Expand Down Expand Up @@ -386,24 +387,24 @@ function endTest() {
*/
function testCreate() {
$this->Acl->Aro->create(array('alias' => 'Chotchkey'));
$this->assertTrue($this->Acl->Aro->save());
$this->assertTrue((bool)$this->Acl->Aro->save());

$parent = $this->Acl->Aro->id;

$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Joanna'));
$this->assertTrue($this->Acl->Aro->save());
$this->assertTrue((bool)$this->Acl->Aro->save());

$this->Acl->Aro->create(array('parent_id' => $parent, 'alias' => 'Stapler'));
$this->assertTrue($this->Acl->Aro->save());
$this->assertTrue((bool)$this->Acl->Aro->save());

$root = $this->Acl->Aco->node('ROOT');
$parent = $root[0]['AcoTwoTest']['id'];

$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'Drinks'));
$this->assertTrue($this->Acl->Aco->save());
$this->assertTrue((bool)$this->Acl->Aco->save());

$this->Acl->Aco->create(array('parent_id' => $parent, 'alias' => 'PiecesOfFlair'));
$this->assertTrue($this->Acl->Aco->save());
$this->assertTrue((bool)$this->Acl->Aco->save());
}

/**
Expand Down Expand Up @@ -460,11 +461,19 @@ function testAllow() {
// Samir should still have his tpsReports/view permissions, but does not
$this->assertTrue($this->Acl->check('root/users/Samir', 'ROOT/tpsReports/view', 'update'));

$this->expectError('DbAcl::allow() - Invalid node');
$this->expectError();
$this->assertFalse($this->Acl->allow('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
}

$this->expectError('DbAcl::allow() - Invalid node');
$this->assertFalse($this->Acl->allow('Homer', 'tpsReports', 'create'));
/**
* testAllowInvalidNode method
*
* @access public
* @return void
*/
public function testAllowInvalidNode() {
$this->expectError();
$this->Acl->allow('Homer', 'tpsReports', 'create');
}

/**
Expand All @@ -479,15 +488,6 @@ function testCheck() {
$this->assertFalse($this->Acl->check('Milton', 'smash', 'read'));
$this->assertFalse($this->Acl->check('Milton', 'current', 'update'));

$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: WRONG\nAco: tpsReports");
$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));

$this->expectError("ACO permissions key foobar does not exist in DbAcl::check()");
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));

$this->expectError("DbAcl::check() - Failed ARO/ACO node lookup in permissions check. Node references:\nAro: users\nAco: NonExistant");
$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));

$this->assertFalse($this->Acl->check(null, 'printers', 'create'));
$this->assertFalse($this->Acl->check('managers', null, 'read'));

Expand All @@ -497,6 +497,39 @@ function testCheck() {
$this->assertFalse($this->Acl->check('root/users/Milton', 'smash', 'delete'));
}

/**
* testCheckInvalidNode method
*
* @access public
* @return void
*/
public function testCheckInvalidNode() {
$this->expectError();
$this->assertFalse($this->Acl->check('WRONG', 'tpsReports', 'read'));
}

/**
* testCheckInvalidPermission method
*
* @access public
* @return void
*/
public function testCheckInvalidPermission() {
$this->expectError();
$this->assertFalse($this->Acl->check('Lumbergh', 'smash', 'foobar'));
}

/**
* testCheckMissingPermission method
*
* @access public
* @return void
*/
public function testCheckMissingPermission() {
$this->expectError();
$this->assertFalse($this->Acl->check('users', 'NonExistant', 'read'));
}

/**
* testDbAclCascadingDeny function
*
Expand Down Expand Up @@ -541,7 +574,7 @@ function testDeny() {
$expected = '-1';
$this->assertEqual($result[0]['PermissionTwoTest']['_delete'], $expected);

$this->expectError('DbAcl::allow() - Invalid node');
$this->expectError();
$this->assertFalse($this->Acl->deny('Lumbergh', 'ROOT/tpsReports/DoesNotExist', 'create'));
}

Expand Down Expand Up @@ -606,7 +639,7 @@ function testGrant() {
$this->assertTrue($this->Acl->check('Micheal', 'view', 'update'));
$this->assertFalse($this->Acl->check('Micheal', 'view', 'delete'));

$this->expectError('DbAcl::allow() - Invalid node');
$this->expectError();
$this->assertFalse($this->Acl->allow('Peter', 'ROOT/tpsReports/DoesNotExist', 'create'));
}

Expand All @@ -627,7 +660,7 @@ function testRevoke() {
$this->assertFalse($this->Acl->check('Samir', 'printers', 'read'));
$this->assertFalse($this->Acl->check('Peter', 'printers', 'read'));

$this->expectError('DbAcl::allow() - Invalid node');
$this->expectError();
$this->assertFalse($this->Acl->deny('Bobs', 'ROOT/printers/DoesNotExist', 'create'));
}
/**
Expand Down

0 comments on commit 754376c

Please sign in to comment.