/** * Tests storing a rules table. * * @covers empire\framework\authorization\rolebased\JsonRulesStorage::storeTable */ public function testStoreTable() { $rulesTable = new RulesTable(); $rulesTable->addRule('*', '*', 'read'); $rulesTable->addRule('editor', '*', array('read', 'write')); $rulesTable->addRule('merchant', 'shop', array('addItem', 'deleteItem')); $this->instance->storeTable($rulesTable); $res = $this->instance->loadTable($rulesTable); $this->assertEquals($rulesTable, $res); }
protected function setUp() { $this->roleStorage = new JsonRoleStorage(__DIR__ . DIRECTORY_SEPARATOR . 'roles.json'); $this->rulesStorage = new JsonRulesStorage(__DIR__ . DIRECTORY_SEPARATOR . 'rules.json'); $this->roleStorage->addRole('fritzchen', 'editor'); $this->roleStorage->addRole('fritzchen', 'admin'); $this->roleStorage->addRole('hänschen', 'guest'); $this->roleStorage->addRole('mäxchen', 'merchant'); $rulesTable = new RulesTable(); $rulesTable->addRule('*', '*', 'read'); $rulesTable->addRule('editor', 'blog', 'write'); $rulesTable->addRule('merchant', 'shop', array('addItem', 'deleteItem', 'editItem')); $this->rulesStorage->storeTable($rulesTable); $this->instance = new RoleBasedAuthorization($this->roleStorage, $this->rulesStorage); }
/** * Tests deleting a rule (deleting an empty role). * * @covers empire\framework\authorization\rolebased\RulesTable::deleteRule */ public function testDeleteRuleEmptyRole() { $this->instance->addRule('editor', '*', '*'); $this->instance->addRule('*', 'blog', array('write', 'read')); $this->instance->deleteRule('*', 'blog'); $expected = array('editor' => array('*' => '*')); $this->assertEquals($expected, $this->instance->getTable()); }
public function storeTable(RulesTable $table) { $this->storeAll($table->getTable()); }