public function testToString() { $roleName = 'toStringAclRoleTest'; $roleModel = new AclRole(); $roleModel->initialize(); $result = $roleModel->create(['name' => $roleName, 'description' => '', 'removable' => 1]); $this->assertTrue($result); $this->assertEquals(AclResource::DIRTY_STATE_PERSISTENT, $roleModel->getDirtyState()); $this->assertSame((string) $roleModel, $roleName); }
/** * @depends testCreateResource */ public function testCreateRelatedModels() { // $this->markTestSkipped('Db table field types has to be resolved with model field types'); $resourceModel = AclResource::findFirstByName('CreatedResource'); $roleModel = new AclRole(); $roleModel->create(['name' => 'guest', 'description' => '', 'removable' => 1]); $this->assertEquals(AclRole::DIRTY_STATE_PERSISTENT, $roleModel->getDirtyState()); $accessModel = new AclResourceAccess(); $accessModel->create(['acl_resource_id' => $resourceModel->id, 'name' => 'index', 'description' => '', 'inherit' => '']); $this->assertEquals(AclResourceAccess::DIRTY_STATE_PERSISTENT, $accessModel->getDirtyState()); $aclModel = new AclAccessList(); $aclModel->create(['acl_role_id' => $roleModel->id, 'acl_resource_id' => $resourceModel->id, 'acl_resource_access_id' => $accessModel->id, 'allowed' => Acl::ALLOW]); $this->assertEquals(AclAccessList::DIRTY_STATE_PERSISTENT, $aclModel->getDirtyState()); }
public function testToAccessArray() { $resourceModel = new AclResource(); $result = $resourceModel->save(['name' => 'toAccessArrayResource', 'description' => 'foo bar baz', 'scope' => '']); $this->assertTrue($result); $roleModel = new AclRole(); $roleModel->create(['name' => 'toAccessArrayRole', 'description' => '', 'removable' => true]); $accessModel = new AclResourceAccess(); $accessModel->create(['acl_resource_id' => $resourceModel->id, 'name' => 'index', 'description' => '', 'inherit' => null]); $aclModel = new AclAccessList(); $aclModel->create(['acl_role_id' => $roleModel->id, 'acl_resource_id' => $resourceModel->id, 'acl_resource_access_id' => $accessModel->id, 'allowed' => false]); $accessArray = ['access_name' => (string) $accessModel, 'resources_name' => (string) $resourceModel, 'allowed' => false]; $toAccessArray = $aclModel->toAccessArray(); $this->assertSame($toAccessArray, $accessArray); }
/** * Clear all ACL settings before starting tests. */ public static function setUpBeforeClass() { foreach (AclResource::find() as $resource) { $resource->delete(); } foreach (AclRole::find() as $role) { $role->delete(); } $resource = new AclResource(); $resource->create(['name' => Resource::WILDCARD, 'description' => 'All in all (built-in)']); (new AclResourceAccess())->create(['name' => Resource::ACCESS_WILDCARD, 'description' => 'All in all (built-in)', 'acl_resource_id' => $resource->id]); }
public function testGetAccessLists() { $resourceModel = new AclResource(); $result = $resourceModel->save(['name' => 'getAccessListsResource', 'description' => 'sna fu bar', 'scope' => '']); $this->assertTrue($result); $this->assertEquals(AclResource::DIRTY_STATE_PERSISTENT, $resourceModel->getDirtyState()); $accessModel = new AclResourceAccess(); $accessModel->initialize(); $result = $accessModel->create(['acl_resource_id' => $resourceModel->id, 'name' => 'index', 'description' => '', 'inherit' => '']); $this->assertTrue($result); $this->assertEquals(AclResourceAccess::DIRTY_STATE_PERSISTENT, $accessModel->getDirtyState()); $roleModel = new AclRole(); $status = $roleModel->create(['name' => 'getAccessListsRole', 'description' => '', 'removable' => 1]); $this->assertTrue($result); $this->assertEquals(AclRole::DIRTY_STATE_PERSISTENT, $roleModel->getDirtyState()); $aclModel = new AclAccessList(); $result = $aclModel->create(['acl_role_id' => $roleModel->id, 'acl_resource_id' => $resourceModel->id, 'acl_resource_access_id' => $accessModel->id, 'allowed' => Acl::ALLOW]); $this->assertTrue($result); $this->assertEquals(AclAccessList::DIRTY_STATE_PERSISTENT, $aclModel->getDirtyState()); $list = $accessModel->getAccessLists(); $this->assertCount(1, $list); $this->assertArrayHasKey(0, $list); $this->assertSame($list[0]->id, $aclModel->id); }
/** * {@inheritdoc} * * @param string $roleName * @return boolean */ public function isRole($roleName) { return AclRole::countByName($this->filterResourceName($roleName)) > 0; }