removeRuleById() public method

Removes rule by its id.
public removeRuleById ( mixed $ruleId )
$ruleId mixed
示例#1
0
 public function testRemoveRuleById()
 {
     $acl = new Acl();
     $user = new Role('User');
     $page = new Resource('Page');
     $rule1 = new Rule('View');
     $rule2 = new Rule('View');
     $rule3 = new Rule('View');
     $acl->addRule($user, $page, $rule1, true);
     $acl->addRule($user, $page, $rule2, true);
     $acl->addRule($user, $page, $rule3, true);
     $acl->removeRuleById('bad_id_test');
     $this->assertAttributeCount(3, 'rules', $acl);
     $acl->removeRuleById($rule1->getId());
     $this->assertAttributeCount(2, 'rules', $acl);
     $acl->removeRuleById($rule2->getId());
     $acl->removeRuleById($rule3->getId());
     $this->assertAttributeCount(0, 'rules', $acl);
 }
示例#2
0
 public function testRuleWide()
 {
     $acl = new Acl();
     $rule = new RuleWide('RuleWide');
     $u = new Role('U');
     $r = new Resource('R');
     $acl->addRule($u, $r, $rule, true);
     $this->assertTrue($acl->isAllowed('U', 'R', 'View'));
     $this->assertTrue($acl->isAllowed('U', 'R', null));
     $this->assertFalse($acl->isAllowed('NotExist', 'R', null));
     $this->assertFalse($acl->isAllowed('U', 'NotExist', null));
     // null role and resource
     $acl = new Acl();
     $acl->addRule(null, null, $rule, true);
     $this->assertTrue($acl->isAllowed('U', 'R', 'View'));
     $this->assertTrue($acl->isAllowed('U', 'R', null));
     $this->assertTrue($acl->isAllowed(null, null, null));
     $acl->removeRuleById($rule->getId());
     $this->assertFalse($acl->isAllowed(null, null, null));
     // null resource
     $acl = new Acl();
     $u = new Role('U');
     $acl->addRule($u, null, $rule, true);
     $this->assertTrue($acl->isAllowed('U', 'R', 'View'));
     $this->assertTrue($acl->isAllowed('U', 'R', null));
     $this->assertTrue($acl->isAllowed('U', null, 'View'));
     $this->assertFalse($acl->isAllowed('NotExist', 'R', 'View'));
     $this->assertFalse($acl->isAllowed(null, 'R', 'View'));
     // null role
     $acl = new Acl();
     $r = new Resource('R');
     $acl->addRule(null, $r, $rule, true);
     $this->assertTrue($acl->isAllowed('U', 'R', 'View'));
     $this->assertTrue($acl->isAllowed('U', 'R', null));
     $this->assertTrue($acl->isAllowed(null, 'R', 'View'));
     $this->assertFalse($acl->isAllowed('U', 'NotExist', 'View'));
     $this->assertFalse($acl->isAllowed('U', null, 'View'));
 }