/** * 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 testIsWildcard() { $resourceModel = new AclResource(); $result = $resourceModel->save(['name' => 'IsWildcardResource', 'description' => 'foo bar bazz 1 2', 'scope' => '']); $this->assertTrue($result); $this->assertEquals(AclResource::DIRTY_STATE_PERSISTENT, $resourceModel->getDirtyState()); $accessModel = new AclResourceAccess(); $result = $accessModel->create(['acl_resource_id' => $resourceModel->id, 'name' => '*', 'description' => '', 'inherit' => null]); $this->assertTrue($result); $this->assertEquals(AclResource::DIRTY_STATE_PERSISTENT, $resourceModel->getDirtyState()); $this->assertTrue($accessModel->isWildcard()); $accessModel->name = 'not wildcard test foo'; $this->assertFalse($accessModel->isWildcard()); }
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); }
/** * @depends testCreateRelatedModels */ public function testGetResourceAccessesArray() { $resource = AclResource::findFirstByName('CreatedResource'); $this->assertInstanceOf('\\Vegas\\Security\\Acl\\Adapter\\Mysql\\Model\\AclResource', $resource); $this->assertInternalType('array', $resource->getAccessesAsArray()); foreach ($resource->getAccessesAsArray() as $access) { $this->assertArrayHasKey('access_name', $access); $this->assertArrayHasKey('access_description', $access); } }
/** * @return mixed */ public function removeResources() { foreach (AclResource::find() as $resource) { $resource->delete(); } }