Beispiel #1
0
 public function testGroupLibraryReading()
 {
     $groupID = self::$config['ownedPublicNoAnonymousGroupID'];
     API::groupClear($groupID);
     $json = API::groupCreateItem($groupID, 'book', ['title' => "Test"], $this);
     try {
         API::useAPIKey(self::$config['apiKey']);
         $response = API::groupGet($groupID, "items");
         $this->assert200($response);
         $this->assertNumResults(1, $response);
         // An anonymous request should fail, because libraryReading is members
         API::useAPIKey(false);
         $response = API::groupGet($groupID, "items");
         $this->assert403($response);
     } finally {
         API::groupClear($groupID);
     }
 }
Beispiel #2
0
 /**
  * Changing a group's metadata should change its ETag
  */
 public function testUpdateMetadataAtom()
 {
     $response = API::userGet(self::$config['userID'], "groups?content=json&key=" . self::$config['apiKey']);
     $this->assert200($response);
     // Get group API URI and version
     $xml = API::getXMLFromResponse($response);
     $xml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
     $xml->registerXPathNamespace('zapi', 'http://zotero.org/ns/api');
     $groupID = (string) array_shift($xml->xpath("//atom:entry/zapi:groupID"));
     $url = (string) array_shift($xml->xpath("//atom:entry/atom:link[@rel='self']/@href"));
     $url = str_replace(self::$config['apiURLPrefix'], '', $url);
     $version = json_decode(API::parseDataFromAtomEntry($xml)['content'], true)['version'];
     // Make sure format=versions returns the same ETag
     $response = API::userGet(self::$config['userID'], "groups?format=versions&key=" . self::$config['apiKey']);
     $this->assert200($response);
     $json = json_decode($response->getBody());
     $this->assertEquals($version, $json->{$groupID});
     // Update group metadata
     $json = json_decode(array_shift($xml->xpath("//atom:entry/atom:content")));
     $xml = new SimpleXMLElement("<group/>");
     foreach ($json as $key => $val) {
         switch ($key) {
             case 'id':
             case 'members':
                 continue;
             case 'name':
                 $name = "My Test Group " . uniqid();
                 $xml['name'] = $name;
                 break;
             case 'description':
                 $description = "This is a test description " . uniqid();
                 $xml->{$key} = $description;
                 break;
             case 'url':
                 $urlField = "http://example.com/" . uniqid();
                 $xml->{$key} = $urlField;
                 break;
             default:
                 $xml[$key] = $val;
         }
     }
     $xml = trim(preg_replace('/^<\\?xml.+\\n/', "", $xml->asXML()));
     $response = API::put($url, $xml, array("Content-Type: text/xml"), array("username" => self::$config['rootUsername'], "password" => self::$config['rootPassword']));
     $this->assert200($response);
     $xml = API::getXMLFromResponse($response);
     $xml->registerXPathNamespace('zxfer', 'http://zotero.org/ns/transfer');
     $group = $xml->xpath('//atom:entry/atom:content/zxfer:group');
     $this->assertCount(1, $group);
     $this->assertEquals($name, $group[0]['name']);
     $response = API::userGet(self::$config['userID'], "groups?format=versions&key=" . self::$config['apiKey']);
     $this->assert200($response);
     $json = json_decode($response->getBody());
     $newVersion = $json->{$groupID};
     $this->assertNotEquals($version, $newVersion);
     // Check ETag header on individual group request
     $response = API::groupGet($groupID, "?content=json&key=" . self::$config['apiKey']);
     $this->assert200($response);
     $this->assertEquals($newVersion, $response->getHeader('Last-Modified-Version'));
     $json = json_decode(API::getContentFromResponse($response));
     $this->assertEquals($name, $json->name);
     $this->assertEquals($description, $json->description);
     $this->assertEquals($urlField, $json->url);
 }
Beispiel #3
0
 public function testAddGroupSettingMultiple()
 {
     $settingKey = "tagColors";
     $value = array(array("name" => "_READ", "color" => "#990000"));
     // TODO: multiple, once more settings are supported
     $groupID = self::$config['ownedPrivateGroupID'];
     $libraryVersion = API::getGroupLibraryVersion($groupID);
     $json = array($settingKey => array("value" => $value));
     $response = API::groupPost($groupID, "settings", json_encode($json), array("Content-Type: application/json"));
     $this->assert204($response);
     // Multi-object GET
     $response = API::groupGet($groupID, "settings");
     $this->assert200($response);
     $this->assertContentType("application/json", $response);
     $json = json_decode($response->getBody(), true);
     $this->assertNotNull($json);
     $this->assertArrayHasKey($settingKey, $json);
     $this->assertEquals($value, $json[$settingKey]['value']);
     $this->assertEquals($libraryVersion + 1, $json[$settingKey]['version']);
     // Single-object GET
     $response = API::groupGet($groupID, "settings/{$settingKey}");
     $this->assert200($response);
     $this->assertContentType("application/json", $response);
     $json = json_decode($response->getBody(), true);
     $this->assertNotNull($json);
     $this->assertEquals($value, $json['value']);
     $this->assertEquals($libraryVersion + 1, $json['version']);
 }