Пример #1
0
 /**
  * https://github.com/Elgg/Elgg/pull/6393
  * Hook handlers for 'access:collections:write','all' hook should respect
  * group's content access mode and container write permissions
  */
 public function testWriteAccessArray()
 {
     $membersonly = ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY;
     $unrestricted = ElggGroup::CONTENT_ACCESS_MODE_UNRESTRICTED;
     $original_page_owner = elgg_get_page_owner_entity();
     elgg_set_page_owner_guid($this->group->guid);
     $ia = elgg_set_ignore_access(false);
     // User is not a member of the group
     // Member-only group
     $this->group->setContentAccessMode($membersonly);
     $write_access = get_write_access_array($this->user->guid, true);
     $this->assertFalse(array_key_exists($this->group->group_acl, $write_access));
     // Unrestricted group
     $this->group->setContentAccessMode($unrestricted);
     $write_access = get_write_access_array($this->user->guid, true);
     $this->assertFalse(array_key_exists($this->group->group_acl, $write_access));
     // User is a member (can write to container)
     $this->group->join($this->user);
     // Member-only group
     $this->group->setContentAccessMode($membersonly);
     $write_access = get_write_access_array($this->user->guid, true);
     $this->assertTrue(array_key_exists($this->group->group_acl, $write_access));
     // Unrestricted group
     $this->group->setContentAccessMode($unrestricted);
     $write_access = get_write_access_array($this->user->guid, true);
     $this->assertTrue(array_key_exists($this->group->group_acl, $write_access));
     elgg_set_ignore_access($ia);
     $this->group->leave($this->user);
     $original_page_owner_guid = elgg_instanceof($original_page_owner) ? $original_page_owner->guid : 0;
     elgg_set_page_owner_guid($original_page_owner_guid);
 }
Пример #2
0
 public function testJoinLeaveGroupACL()
 {
     if (!elgg_is_active_plugin('groups')) {
         return;
     }
     $group = new ElggGroup();
     $group->name = 'Test group';
     $group->save();
     $result = $group->join($this->user);
     $this->assertTrue($result);
     // disable security since we run as admin
     $ia = elgg_set_ignore_access(false);
     // need to set the page owner to emulate being in a group context.
     // this is kinda hacky.
     elgg_set_page_owner_guid($group->getGUID());
     if ($result) {
         $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
         $this->assertTrue($can_edit);
     }
     $result = $group->leave($this->user);
     $this->assertTrue($result);
     if ($result) {
         $can_edit = can_edit_access_collection($group->group_acl, $this->user->guid);
         $this->assertFalse($can_edit);
     }
     elgg_set_ignore_access($ia);
     $group->delete();
 }