Esempio n. 1
0
 /**
  * Test KTAPI_RoleAllocation getAllocation(), add(), remove(), save()
  *
  * @TODO finish
  *
  */
 function testRoleAllocation()
 {
     $root = $this->ktapi->get_root_folder();
     $folder = $this->ktapi->get_folder_by_name('test123');
     if (!$folder instanceof KTAPI_Folder) {
         $folder = $root->add_folder('test123');
     }
     $allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $folder);
     $membership = $allocation->getMembership();
     $this->assertTrue(empty($membership));
     $role2 = KTAPI_Role::getByName('Reviewer');
     $role = KTAPI_Role::getByName('Publisher');
     $user = KTAPI_User::getByUsername('admin');
     $user2 = KTAPI_User::getByUsername('anonymous');
     $group = KTAPI_Group::getByName('System Administrators');
     $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
     $this->assertFalse($allocation->doesRoleHaveMember($role2, $user));
     // Add Admin user to Reviewer role
     $allocation->add($role2, $user);
     // Add Admin user to Publisher role
     $allocation->add($role, $user);
     // Add Sys admin group to Publisher role
     $allocation->add($role, $group);
     // Add Anonymous to Publisher role - duplicate to test
     $allocation->add($role, $user2);
     $allocation->add($role, $user2);
     $allocation->save();
     // Test membership function
     $membership = $allocation->getMembership();
     $this->assertFalse(empty($membership));
     $this->assertIsA($membership, 'array', 'getMembership should return an array');
     $this->assertTrue($membership['Reviewer']['user'][1] == 'Administrator');
     $this->assertTrue($membership['Publisher']['group'][1] == 'System Administrators');
     $membership = $allocation->getMembership('Rev');
     $this->assertFalse(empty($membership));
     $this->assertTrue($membership['Reviewer']['user'][1] == 'Administrator');
     $this->assertFalse(isset($membership['Publisher']));
     $this->assertTrue($allocation->doesRoleHaveMember($role, $user));
     $this->assertTrue($allocation->doesRoleHaveMember($role, $group));
     // Test role removal
     $allocation->remove($role, $user);
     $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
     $allocation->remove($role, $user2);
     $this->assertFalse($allocation->doesRoleHaveMember($role, $user2));
     $allocation->save();
     // now, just overwrite the allocation variable, and check that the assertions still hold.
     $allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $root);
     $this->assertFalse($allocation->doesRoleHaveMember($role, $user));
     $this->assertFalse($allocation->doesRoleHaveMember($role, $user2));
     $folder->delete('Testing role allocation');
 }
 /**
  * Get the role allocation for the document
  *
  * @return KTAPI_RoleAllocation Instance of the role allocation object
  */
 public function getRoleAllocation()
 {
     $allocation = KTAPI_RoleAllocation::getAllocation($this->ktapi, $this);
     return $allocation;
 }