예제 #1
0
 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);
 }
예제 #2
0
 /**
  * @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());
 }
예제 #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
파일: MysqlTest.php 프로젝트: vegas-cmf/acl
 /**
  * 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]);
 }
예제 #5
0
 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);
 }
예제 #6
0
파일: Mysql.php 프로젝트: vegas-cmf/acl
 /**
  * {@inheritdoc}
  *
  * @param  string  $roleName
  * @return boolean
  */
 public function isRole($roleName)
 {
     return AclRole::countByName($this->filterResourceName($roleName)) > 0;
 }