Exemple #1
0
 public function testUser_get_sponsorWithOneSponsor()
 {
     $user = new \BeeHub_User('/system/users/jane');
     // There can not be a default sponsor; Jane does not have any sponsors at all
     $this->assertNull($user->user_prop_sponsor());
     // Give Jane a sponsor, and this should automatically be her default sponsor
     $this->setCurrentUser('/system/users/john');
     $sponsor = new \BeeHub_Sponsor('/system/sponsors/sponsor_a');
     $sponsor->change_memberships(array('jane'), \BeeHub_Sponsor::ADMIN_ACCEPT);
     $userWithSponsor = \DAV::$REGISTRY->resource('/system/users/jane');
     $this->assertSame('/system/sponsors/sponsor_a', $userWithSponsor->user_prop_sponsor());
     // Remove the only sponsor Jane has and she should have no default sponsor either
     $sponsor->change_memberships(array('jane'), \BeeHub_Sponsor::DELETE_MEMBER);
     $userWithoutSponsor = \DAV::$REGISTRY->resource('/system/users/jane');
     $this->assertNull($userWithoutSponsor->user_prop_sponsor());
 }
$usersCollection = $db->createCollection('users');
$usersCollection->ensureIndex(array('name' => 1), array('unique' => 1));
$usersCollection->insert(array('name' => $username, 'displayname' => 'Administrator', 'email' => $userEmail, 'password' => \crypt($_SERVER['PHP_AUTH_PW'], '$6$rounds=5000$' . md5(time() . rand(0, 99999)) . '$'), 'default_sponsor' => DEFAULT_SPONSOR_NAME));
// Create groups collection
$groupsCollection = $db->createCollection('groups');
$groupsCollection->ensureIndex(array('name' => 1), array('unique' => 1));
$groupsCollection->insert(array('name' => \basename($config['namespace']['admin_group']), 'displayname' => ADMIN_GROUP_DISPLAYNAME, 'description' => ADMIN_GROUP_DESCRIPTION));
$group = new \BeeHub_Group($config['namespace']['admin_group']);
$group->change_memberships(array($username), \BeeHub_Group::USER_ACCEPT);
$group->change_memberships(array($username), \BeeHub_Group::ADMIN_ACCEPT);
$group->change_memberships(array($username), \BeeHub_Group::SET_ADMIN);
// Create sponsors collection
$sponsorsCollection = $db->createCollection('sponsors');
$sponsorsCollection->ensureIndex(array('name' => 1), array('unique' => 1));
$sponsorsCollection->insert(array('name' => DEFAULT_SPONSOR_NAME, 'displayname' => DEFAULT_SPONSOR_DISPLAYNAME, 'description' => DEFAULT_SPONSOR_DESCRIPTION));
$sponsor = new \BeeHub_Sponsor(\BeeHub::SPONSORS_PATH . DEFAULT_SPONSOR_NAME);
$sponsor->change_memberships(array($username), \BeeHub_Sponsor::ADMIN_ACCEPT);
$sponsor->change_memberships(array($username), \BeeHub_Sponsor::SET_ADMIN);
// Create the beehub_system collection
$systemCollection = $db->createCollection('beehub_system');
$systemCollection->insert(array('name' => 'etag', 'counter' => 0));
// Create the files collection
$filesCollection = $db->createCollection('files');
$filesCollection->ensureIndex(array('props.http://beehub%2Enl/ sponsor' => 1));
$filesCollection->ensureIndex(array('props.DAV: owner' => 1));
$filesCollection->ensureIndex(array('path' => 1), array('unique' => 1));
$filesCollection->ensureIndex(array('depth' => 1, 'path' => 1));
$locksCollection = $db->createCollection('locks');
$locksCollection->ensureIndex(array('path' => 1), array('unique' => 1));
// Done creating the database structure
print "ok\n";
 public function testMethod_POST()
 {
     $this->setCurrentUser('/system/users/john');
     $_POST['displayname'] = 'Some test sponsor of John';
     $_POST['description'] = "This is the description of John's test sponsor";
     $_POST['sponsor_name'] = 'johnsponsor';
     $headers = array();
     $this->expectOutputRegex('/https 303 See Other/');
     $this->obj->method_POST($headers);
     $sponsor = new \BeeHub_Sponsor('/system/sponsors/johnsponsor');
     $this->assertSame($_POST['displayname'], $sponsor->user_prop(\DAV::PROP_DISPLAYNAME));
     $this->assertSame($_POST['description'], $sponsor->user_prop(\BeeHub::PROP_DESCRIPTION));
 }
 public function testMethod_MKCOL()
 {
     $sponsorB = new \BeeHub_Sponsor('/system/sponsors/sponsor_b');
     $sponsorB->change_memberships(array('jane'), \BeeHub_Sponsor::ADMIN_ACCEPT);
     $sponsorB->change_memberships(array('jane'), \BeeHub_Sponsor::SET_ADMIN);
     $jane = new \BeeHub_User('/system/users/jane');
     $jane->user_set_sponsor('/system/sponsors/sponsor_b');
     $jane->storeProperties();
     $this->setCurrentUser('/system/users/jane');
     $this->obj->method_MKCOL('subdirectory');
     $subdirectory = \DAV::$REGISTRY->resource($this->obj->path . 'subdirectory');
     $this->assertSame('/system/sponsors/sponsor_a', $subdirectory->user_prop_sponsor());
     $this->assertSame('/system/users/jane', $subdirectory->user_prop_owner());
     $this->assertNull($subdirectory->user_prop(\DAV::PROP_GETETAG));
     // And now it already exists, we should not be able to create it again
     $this->setExpectedException('DAV_Status', null, \DAV::HTTP_FORBIDDEN);
     $this->obj->method_MKCOL('subdirectory');
 }
 public function testUser_propname()
 {
     $sponsor = new \BeeHub_Sponsor('/system/sponsors/sponsor_a');
     $this->assertSame(\BeeHub::$SPONSOR_PROPS, $sponsor->user_propname());
 }
 public function testChangeSponsor()
 {
     $sponsor = new \BeeHub_Sponsor('/system/sponsors/sponsor_b');
     $sponsor->change_memberships(array('jane'), \BeeHub_Sponsor::ADMIN_ACCEPT);
     $sponsor->change_memberships(array('jane'), \BeeHub_Sponsor::SET_ADMIN);
     $this->obj->user_set(\DAV::PROP_OWNER, '/system/users/jane');
     $this->setCurrentUser('/system/users/jane');
     $this->obj->method_PROPPATCH(\BeeHub::PROP_SPONSOR, '<D:href>/system/sponsors/sponsor_b</D:href>');
     $this->assertSame('/system/sponsors/sponsor_b', $this->obj->user_prop_sponsor());
 }
Exemple #7
0
 public function testMethod_COPY()
 {
     $sponsorB = new \BeeHub_Sponsor('/system/sponsors/sponsor_b');
     $sponsorB->change_memberships(array('jane'), \BeeHub_Sponsor::ADMIN_ACCEPT);
     $sponsorB->change_memberships(array('jane'), \BeeHub_Sponsor::SET_ADMIN);
     $this->setCurrentUser('/system/users/john');
     $bar = new \BeeHub_Directory('/bar');
     $bar->user_set_acl(array(new \DAVACL_Element_ace('/system/users/jane', false, array(\DAVACL::PRIV_WRITE), false)));
     $this->setCurrentUser('/system/users/jane');
     $this->obj->method_COPY('/bar/file.txt');
     $copiedFile = \DAV::$REGISTRY->resource('/bar/file.txt');
     $this->assertSame(array(), $copiedFile->user_prop_acl_internal());
     $this->assertNotSame($this->obj->user_prop_getetag(), $copiedFile->user_prop_getetag());
     $this->assertSame('/system/users/jane', $copiedFile->user_prop_owner());
     $this->assertSame('/system/sponsors/sponsor_b', $copiedFile->user_prop_sponsor());
 }