示例#1
0
 /**
  * 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]);
 }
示例#2
0
 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());
 }
示例#3
0
 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);
 }
示例#4
0
 /**
  * @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);
     }
 }
示例#5
0
文件: Mysql.php 项目: vegas-cmf/acl
 /**
  * @return mixed
  */
 public function removeResources()
 {
     foreach (AclResource::find() as $resource) {
         $resource->delete();
     }
 }