/** * Tests function in Acl Allow Method * * @issue 11235 * * @author Wojciech Slawski <*****@*****.**> * @since 2015-12-16 */ public function testAclAllowFunction() { $this->specify('The function in allow should be called and isAllowed should return correct values when using function in allow method', function () { $acl = new PhTAclMem(); $acl->setDefaultAction(PhAcl::DENY); $acl->addRole('Guests'); $acl->addRole('Members', 'Guests'); $acl->addRole('Admins', 'Members'); $acl->addResource('Post', array('update')); $guest = new TestRoleable(1, 'Guests'); $member = new TestRoleable(2, 'Members'); $anotherMember = new TestRoleable(3, 'Members'); $admin = new TestRoleable(4, 'Admins'); $model = new TestResourceable(2, 'Post'); $acl->deny('Guests', 'Post', 'update'); $acl->allow('Members', 'Post', 'update', function (TestRoleable $user, TestResourceable $model) { return $user->getId() == $model->getUser(); }); $acl->allow('Admins', 'Post', 'update'); $actual = (bool) $acl->isAllowed($guest, $model, 'update'); expect($actual)->false(); $actual = (bool) $acl->isAllowed($member, $model, 'update'); expect($actual)->true(); $actual = (bool) $acl->isAllowed($anotherMember, $model, 'update'); expect($actual)->false(); $actual = (bool) $acl->isAllowed($admin, $model, 'update'); expect($actual)->true(); }); }
/** * Tests ACL Resources with numeric values * * @issue 1513 * * @author Nikolaos Dimopoulos <*****@*****.**> * @since 2014-10-04 */ public function testAclResourcesWithNumericValues() { $this->specify('ACL Resources with numeric values are not set properly', function () { $acl = new PhTAclMem(); $acl->setDefaultAction(PhAcl::DENY); $acl->addRole(new PhTAclRole('11')); $acl->addResource(new PhTAclResource('11'), ['index']); $actual = $acl->isResource('11'); expect($actual)->true(); }); }