Exemplo n.º 1
0
 public function testGroupTagAddItemChange()
 {
     $key = 'AAAAAAAA';
     $groupID = self::$config['ownedPrivateGroupID'];
     $libraryID = self::$config['ownedPrivateGroupLibraryID'];
     $sessionID2 = Sync::login(array('username' => self::$config['username2'], 'password' => self::$config['password2']));
     $xml = Sync::updated($sessionID2);
     $updateKey = (string) $xml['updateKey'];
     // Create item via sync
     $data = '<data version="9"><items><item libraryID="' . $libraryID . '" ' . 'itemType="book" ' . 'dateAdded="2009-03-07 04:53:20" ' . 'dateModified="2009-03-07 04:54:09" ' . 'key="' . $key . '"/></items></data>';
     $response = Sync::upload($sessionID2, $updateKey, $data);
     Sync::waitForUpload($sessionID2, $response, $this);
     // Get item version via API
     $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=json");
     $xml = API::getXMLFromResponse($response);
     $data = API::parseDataFromAtomEntry($xml);
     $version = $data['version'];
     // Verify createdByUserID and lastModifiedByUserID
     $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=none");
     $xml = API::getXMLFromResponse($response);
     $xml->registerXPathNamespace('zxfer', 'http://zotero.org/ns/transfer');
     $createdByUser = (string) array_shift($xml->xpath('//atom:entry/atom:author/atom:name'));
     $lastModifiedByUser = (string) array_shift($xml->xpath('//atom:entry/zapi:lastModifiedByUser'));
     $this->assertEquals(self::$config['username2'], $createdByUser);
     $this->assertEquals(self::$config['username2'], $lastModifiedByUser);
     // Get item via sync
     $xml = Sync::updated(self::$sessionID);
     $updateKey = (string) $xml['updateKey'];
     $this->assertEquals(1, sizeOf($xml->updated->items->item));
     // Add tag to item via sync
     $data = '<data version="9"><tags><tag libraryID="' . $libraryID . '" ' . 'name="Test" ' . 'dateAdded="2009-03-07 04:54:56" ' . 'dateModified="2009-03-07 04:54:56" ' . 'key="BBBBBBBB">' . '<items>' . $key . '</items>' . '</tag></tags></data>';
     $response = Sync::upload(self::$sessionID, $updateKey, $data);
     Sync::waitForUpload(self::$sessionID, $response, $this);
     // Get item via API
     $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=json");
     $xml = API::getXMLFromResponse($response);
     $data = API::parseDataFromAtomEntry($xml);
     $json = json_decode($data['content']);
     $this->assertCount(1, $json->tags);
     $this->assertTrue(isset($json->tags[0]->tag));
     $this->assertEquals("Test", $json->tags[0]->tag);
     $this->assertGreaterThan($version, $data['version']);
     // Verify createdByUserID and lastModifiedByUserID
     $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=none");
     $xml = API::getXMLFromResponse($response);
     $xml->registerXPathNamespace('zxfer', 'http://zotero.org/ns/transfer');
     $createdByUser = (string) array_shift($xml->xpath('//atom:entry/atom:author/atom:name'));
     $lastModifiedByUser = (string) array_shift($xml->xpath('//atom:entry/zapi:lastModifiedByUser'));
     $this->assertEquals(self::$config['username2'], $createdByUser);
     $this->assertEquals(self::$config['username'], $lastModifiedByUser);
 }
Exemplo n.º 2
0
 /**
  * Changing a group's metadata should change its ETag
  */
 public function testUpdateMetadata()
 {
     $response = API::userGet(self::$config['userID'], "groups?content=json&key=" . self::$config['apiKey']);
     $this->assert200($response);
     // Get group API URI and ETag
     $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);
     $etag = (string) array_shift($xml->xpath("//atom:entry/atom:content/@etag"));
     // Make sure format=etags returns the same ETag
     $response = API::userGet(self::$config['userID'], "groups?format=etags&key=" . self::$config['apiKey']);
     $this->assert200($response);
     $json = json_decode($response->getBody());
     $this->assertEquals($etag, $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=etags&key=" . self::$config['apiKey']);
     $this->assert200($response);
     $json = json_decode($response->getBody());
     $newETag = $json->{$groupID};
     $this->assertNotEquals($etag, $newETag);
     // Check ETag header on individual group request
     $response = API::groupGet($groupID, "?content=json&key=" . self::$config['apiKey']);
     $this->assert200($response);
     $this->assertEquals($newETag, $response->getHeader('ETag'));
     $json = json_decode(API::getContentFromResponse($response));
     $this->assertEquals($name, $json->name);
     $this->assertEquals($description, $json->description);
     $this->assertEquals($urlField, $json->url);
 }
Exemplo n.º 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?key=" . self::$config['apiKey'], json_encode($json), array("Content-Type: application/json"));
     $this->assert204($response);
     // Multi-object GET
     $response = API::groupGet($groupID, "settings?key=" . self::$config['apiKey']);
     $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}?key=" . self::$config['apiKey']);
     $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']);
 }