Example #1
0
 public function testRulesWithFields()
 {
     ItemCategoryQuery::create()->deleteAll();
     ItemQuery::create()->deleteAll();
     TestQuery::create()->deleteAll();
     $this->getACL()->setCaching(false);
     $this->getACL()->removeObjectRules('test/item');
     $user = new User();
     $user->setUsername('TestUser');
     $user->save();
     $group = new Group();
     $group->setName('ACL Test group');
     $group->addUser($user);
     $group->save();
     $cat1 = new ItemCategory();
     $cat1->setName('Nein');
     $item1 = new Item();
     $item1->setTitle('Item 1');
     $item1->addItemCategory($cat1);
     $item1->save();
     $cat2 = new ItemCategory();
     $cat2->setName('Hiiiii');
     $item2 = new Item();
     $item2->setTitle('Item 2');
     $item2->addItemCategory($cat2);
     $item2->save();
     $this->getACL()->removeObjectRules('test/item');
     $fields = array('oneCategory' => array(array('access' => false, 'condition' => array(array('id', '>', $cat1->getId())))));
     $this->getACL()->setObjectUpdate('test/item', \Jarves\ACL::TARGET_TYPE_USER, $user->getId(), true, $fields);
     $testItemRequest = ACLRequest::create('test/item')->targetUser($user->getId())->onlyUpdateMode();
     $this->assertFalse($this->getACL()->check($testItemRequest->setField(['oneCategory' => $cat2->getId()])));
     $this->assertTrue($this->getACL()->check($testItemRequest->setField(['oneCategory' => $cat1->getId()])));
     $this->getACL()->removeObjectRules('test/item');
     $fields = array('oneCategory' => array(array('access' => false, 'condition' => array(array('name', '=', 'Nein')))));
     $this->getACL()->setObjectUpdate('test/item', \Jarves\ACL::TARGET_TYPE_USER, $user->getId(), true, $fields);
     $this->assertTrue($this->getACL()->check($testItemRequest->setField(['oneCategory' => $cat2->getId()])));
     $this->assertFalse($this->getACL()->check($testItemRequest->setField(['oneCategory' => $cat1->getId()])));
     $this->getACL()->removeObjectRules('test/item');
     $fields = array('title' => array(array('access' => false, 'condition' => array(array('title', 'LIKE', 'peter %')))));
     $this->getACL()->setObjectUpdate('test/item', \Jarves\ACL::TARGET_TYPE_USER, $user->getId(), true, $fields);
     $this->assertTrue($this->getACL()->check($testItemRequest->setField(['title' => 'Heidenau'])));
     $this->assertTrue($this->getACL()->check($testItemRequest->setField(['title' => 'peter'])));
     $this->assertFalse($this->getACL()->check($testItemRequest->setField(['title' => 'peter 2'])));
     $this->assertFalse($this->getACL()->check($testItemRequest->setField(['title' => 'peter asdad'])));
     $this->getACL()->removeObjectRules('test/item');
     $fields = array('title' => array(array('access' => false, 'condition' => array(array('title', '=', 'peter')))));
     $this->getACL()->setObjectUpdate('test/item', \Jarves\ACL::TARGET_TYPE_USER, $user->getId(), true, $fields);
     $this->assertTrue($this->getACL()->check($testItemRequest->setField(['title' => 'Heidenau'])));
     $this->assertFalse($this->getACL()->check($testItemRequest->setField(['title' => 'peter'])));
     $this->assertTrue($this->getACL()->check($testItemRequest->setField(['title' => 'peter2'])));
     $this->getACL()->setCaching(true);
     $this->getACL()->removeObjectRules('test/item');
 }