Esempio n. 1
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());
 }
Esempio n. 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());
 }
Esempio n. 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);
 }
Esempio n. 4
0
 /**
  * @return mixed
  */
 public function removeResourceAccesses()
 {
     foreach (AclResourceAccess::find() as $resourceAccess) {
         $resourceAccess->delete();
     }
 }