public function testWebTranslationSingle() { $response = API::userPost(self::$config['userID'], "items?key=" . self::$config['apiKey'], json_encode(["url" => "http://www.amazon.com/Zotero-Guide-Librarians-Researchers-Educators/dp/0838985890/"]), array("Content-Type: application/json")); $this->assert201($response); $xml = API::getXMLFromResponse($response); $json = json_decode(API::parseDataFromAtomEntry($xml)['content']); $this->assertEquals('Zotero: A Guide for Librarians, Researchers and Educators', $json->title); }
public function testInvalidCharacters() { $data = array('title' => "A" . chr(0) . "A", 'creators' => array(array('creatorType' => "author", 'name' => "B" . chr(1) . "B")), 'tags' => array(array('tag' => "C" . chr(2) . "C"))); $xml = API::createItem("book", $data, $this, 'atom'); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $this->assertEquals("AA", $json->title); $this->assertEquals("BB", $json->creators[0]->name); $this->assertEquals("CC", $json->tags[0]->tag); }
public function testCreatorSummary() { $xml = API::createItem("book", array("creators" => array(array("creatorType" => "author", "name" => "Test"))), $this); $data = API::parseDataFromAtomEntry($xml); $itemKey = $data['key']; $json = json_decode($data['content'], true); $creatorSummary = (string) array_shift($xml->xpath('//atom:entry/zapi:creatorSummary')); $this->assertEquals("Test", $creatorSummary); $json['creators'][] = array("creatorType" => "author", "firstName" => "Alice", "lastName" => "Foo"); $response = API::userPut(self::$config['userID'], "items/{$itemKey}?key=" . self::$config['apiKey'], json_encode($json)); $this->assert204($response); $xml = API::getItemXML($itemKey); $creatorSummary = (string) array_shift($xml->xpath('//atom:entry/zapi:creatorSummary')); $this->assertEquals("Test and Foo", $creatorSummary); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $json['creators'][] = array("creatorType" => "author", "firstName" => "Bob", "lastName" => "Bar"); $response = API::userPut(self::$config['userID'], "items/{$itemKey}?key=" . self::$config['apiKey'], json_encode($json)); $this->assert204($response); $xml = API::getItemXML($itemKey); $creatorSummary = (string) array_shift($xml->xpath('//atom:entry/zapi:creatorSummary')); $this->assertEquals("Test et al.", $creatorSummary); }
/** * @depends testNewSearch */ public function testModifySearch($newSearchData) { $key = $newSearchData['key']; $version = $newSearchData['version']; $json = json_decode($newSearchData['content'], true); // Remove one search condition array_shift($json['conditions']); $name = $json['name']; $conditions = $json['conditions']; $response = API::userPut(self::$config['userID'], "searches/{$key}?key=" . self::$config['apiKey'], json_encode($json), array("Content-Type: application/json", "If-Unmodified-Since-Version: {$version}")); $this->assert204($response); $xml = API::getSearchXML($key); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $this->assertEquals($name, (string) $json->name); $this->assertInternalType('array', $json->conditions); $this->assertCount(sizeOf($conditions), $json->conditions); foreach ($conditions as $i => $condition) { foreach ($condition as $key => $val) { $this->assertEquals($val, $json->conditions[$i]->{$key}); } } }
public function testCollectionItemUpdate() { $collectionKey = Sync::createCollection(self::$sessionID, self::$config['libraryID'], "Test", null, $this); $itemKey = Sync::createItem(self::$sessionID, self::$config['libraryID'], "book", null, $this); $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; // Get the item version $itemXML = API::getItemXML($itemKey); $data = API::parseDataFromAtomEntry($itemXML); $json = json_decode($data['content'], true); $itemVersion = $json['itemVersion']; $this->assertNotNull($itemVersion); // Add via sync $collectionXML = $xml->updated[0]->collections[0]->collection[0]; $collectionXML['libraryID'] = self::$config['libraryID']; $collectionXML->addChild("items", $itemKey); $data = '<data version="9"><collections>' . $collectionXML->asXML() . '</collections>' . '</data>'; $response = Sync::upload(self::$sessionID, $updateKey, $data, true); Sync::waitForUpload(self::$sessionID, $response, $this); // Make sure item was updated $itemXML = API::getItemXML($itemKey); $data = API::parseDataFromAtomEntry($itemXML); $json = json_decode($data['content'], true); $this->assertGreaterThan($itemVersion, $json['itemVersion']); $itemVersion = $json['itemVersion']; $this->assertCount(1, $json['collections']); $this->assertContains($collectionKey, $json['collections']); // Remove via sync $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; $collectionXML = $xml->updated[0]->collections[0]->collection[0]; $collectionXML['libraryID'] = self::$config['libraryID']; unset($collectionXML->items); $data = '<data version="9"><collections>' . $collectionXML->asXML() . '</collections>' . '</data>'; $response = Sync::upload(self::$sessionID, $updateKey, $data, true); Sync::waitForUpload(self::$sessionID, $response, $this); // Make sure item was removed $itemXML = API::getItemXML($itemKey); $data = API::parseDataFromAtomEntry($itemXML); $json = json_decode($data['content'], true); $this->assertGreaterThan($itemVersion, $json['itemVersion']); $this->assertCount(0, $json['collections']); }
public function testUnicodeTitle() { $title = "Tést"; $xml = API::createItem("book", array("title" => $title), $this); $data = API::parseDataFromAtomEntry($xml); $key = $data['key']; // Test entry $response = API::userGet(self::$config['userID'], "items/{$key}?key=" . self::$config['apiKey'] . "&content=json"); $this->assertContains('"title": "Tést"', $response->getBody()); // Test feed $response = API::userGet(self::$config['userID'], "items?key=" . self::$config['apiKey'] . "&content=json"); $this->assertContains('"title": "Tést"', $response->getBody()); }
private function _testObjectKeyParameter($objectType) { $objectTypePlural = API::getPluralObjectType($objectType); $xmlArray = array(); switch ($objectType) { case 'collection': $xmlArray[] = API::createCollection("Name", false, $this); $xmlArray[] = API::createCollection("Name", false, $this); break; case 'item': $xmlArray[] = API::createItem("book", false, $this); $xmlArray[] = API::createItem("book", false, $this); break; case 'search': $xmlArray[] = API::createSearch("Name", array(array("condition" => "title", "operator" => "contains", "value" => "test")), $this); $xmlArray[] = API::createSearch("Name", array(array("condition" => "title", "operator" => "contains", "value" => "test")), $this); break; } $keys = array(); foreach ($xmlArray as $xml) { $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; } $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'] . "&content=json&{$objectType}Key={$keys[0]}"); $this->assert200($response); $this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $this->assertEquals($keys[0], $data['key']); $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'] . "&content=json&{$objectType}Key={$keys[0]},{$keys[1]}&order={$objectType}KeyList"); $this->assert200($response); $this->assertNumResults(2, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $key = (string) array_shift($xpath); $this->assertEquals($keys[0], $key); $key = (string) array_shift($xpath); $this->assertEquals($keys[1], $key); }
private function _testUploadUnmodified($objectType) { $objectTypePlural = API::getPluralObjectType($objectType); switch ($objectType) { case 'collection': $xml = API::createCollection("Name", false, $this); break; case 'item': $xml = API::createItem("book", array("title" => "Title"), $this); break; case 'search': $xml = API::createSearch("Name", 'default', $this); break; } $version = (int) array_shift($xml->xpath('//atom:entry/zapi:version')); $this->assertNotEquals(0, $version); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $response = API::userPut(self::$config['userID'], "{$objectTypePlural}/{$data['key']}?key=" . self::$config['apiKey'], json_encode($json)); $this->assert204($response); $this->assertEquals($version, $response->getHeader("Last-Modified-Version")); switch ($objectType) { case 'collection': $xml = API::getCollectionXML($data['key']); break; case 'item': $xml = API::getItemXML($data['key']); break; case 'search': $xml = API::getSearchXML($data['key']); break; } $data = API::parseDataFromAtomEntry($xml); $this->assertEquals($version, $data['version']); }
public function testCollectionItems() { $collectionKey = API::createCollection('Test', false, $this, 'key'); $xml = API::createItem("book", array('collections' => array($collectionKey)), $this); $data = API::parseDataFromAtomEntry($xml); $itemKey1 = $data['key']; $itemVersion1 = $data['version']; $json = json_decode($data['content']); $this->assertEquals(array($collectionKey), $json->collections); $xml = API::createItem("journalArticle", array('collections' => array($collectionKey)), $this); $data = API::parseDataFromAtomEntry($xml); $itemKey2 = $data['key']; $itemVersion2 = $data['version']; $json = json_decode($data['content']); $this->assertEquals(array($collectionKey), $json->collections); $childItemKey1 = API::createAttachmentItem("linked_url", [], $itemKey1, $this, 'key'); $childItemKey2 = API::createAttachmentItem("linked_url", [], $itemKey2, $this, 'key'); $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items?key=" . self::$config['apiKey'] . "&format=keys"); $this->assert200($response); $keys = explode("\n", trim($response->getBody())); $this->assertCount(4, $keys); $this->assertContains($itemKey1, $keys); $this->assertContains($itemKey2, $keys); $this->assertContains($childItemKey1, $keys); $this->assertContains($childItemKey2, $keys); $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&format=keys"); $this->assert200($response); $keys = explode("\n", trim($response->getBody())); $this->assertCount(2, $keys); $this->assertContains($itemKey1, $keys); $this->assertContains($itemKey2, $keys); }
public function testCreatorItemChangeViaAPI() { $key = 'AAAAAAAA'; $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; // Create item via sync $data = '<data version="9"><items><item libraryID="' . self::$config['libraryID'] . '" itemType="book" ' . 'dateAdded="2009-03-07 04:53:20" ' . 'dateModified="2009-03-07 04:54:09" ' . 'key="' . $key . '">' . '<creator key="BBBBBBBB" creatorType="author" index="0">' . '<creator libraryID="' . self::$config['libraryID'] . '" ' . 'key="BBBBBBBB" dateAdded="2009-03-07 04:53:20" dateModified="2009-03-07 04:54:09">' . '<firstName>First</firstName>' . '<lastName>Last</lastName>' . '<fieldMode>0</fieldMode>' . '</creator></creator></item></items></data>'; $response = Sync::upload(self::$sessionID, $updateKey, $data); Sync::waitForUpload(self::$sessionID, $response, $this); // Get item version via API and check creatorSummary API::useAPIVersion(1); $response = API::userGet(self::$config['userID'], "items/{$key}?key=" . self::$config['apiKey'] . "&content=json"); $xml = API::getXMLFromResponse($response); $creatorSummary = (string) array_shift($xml->xpath('//atom:entry/zapi:creatorSummary')); $this->assertEquals("Last", $creatorSummary); $data = API::parseDataFromAtomEntry($xml); $etag = (string) array_shift($xml->xpath('//atom:entry/atom:content/@zapi:etag')); $this->assertNotEquals("", $etag); // Modify creator $json = json_decode($data['content'], true); $json['creators'][0] = array("name" => "First Last", "creatorType" => "author"); // Modify via API $response = API::userPut(self::$config['userID'], "items/{$key}?key=" . self::$config['apiKey'], json_encode($json), array("If-Match: {$etag}")); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $creatorSummary = (string) array_shift($xml->xpath('//atom:entry/zapi:creatorSummary')); $this->assertEquals("First Last", $creatorSummary); $this->assertTrue(isset($json->creators[0]->name)); $this->assertEquals("First Last", $json->creators[0]->name); $newETag = (string) array_shift($xml->xpath('//atom:entry/zapi:etag')); $this->assertNotEquals($etag, $newETag); // Get item again via API $response = API::userGet(self::$config['userID'], "items/{$key}?key=" . self::$config['apiKey'] . "&content=json"); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $creatorSummary = (string) array_shift($xml->xpath('//atom:entry/zapi:creatorSummary')); $this->assertEquals("First Last", $creatorSummary); $this->assertTrue(isset($json->creators[0]->name)); $this->assertEquals("First Last", $json->creators[0]->name); $newETag = (string) array_shift($xml->xpath('//atom:entry/zapi:etag')); $this->assertNotEquals($etag, $newETag); }
public function testDeleteItemContent() { $key = API::createItem("book", false, $this, 'key'); $xml = API::createAttachmentItem("imported_file", [], $key, $this, 'atom'); $data = API::parseDataFromAtomEntry($xml); $content = "Ыюм мютат дэбетиз конвынёры эю, ку мэль жкрипта трактатоз.\nПро ут чтэт эрепюят граэкйж, дуо нэ выро рыкючабо пырикюлёз."; // Store content $response = API::userPut(self::$config['userID'], "items/{$data['key']}/fulltext?key=" . self::$config['apiKey'], json_encode(["content" => $content, "indexedPages" => 50]), array("Content-Type: application/json")); $this->assert204($response); $contentVersion = $response->getHeader("Last-Modified-Version"); // Retrieve it $response = API::userGet(self::$config['userID'], "items/{$data['key']}/fulltext?key=" . self::$config['apiKey']); $this->assert200($response); $json = json_decode($response->getBody(), true); $this->assertEquals($content, $json['content']); $this->assertEquals(50, $json['indexedPages']); // Set to empty string $response = API::userPut(self::$config['userID'], "items/{$data['key']}/fulltext?key=" . self::$config['apiKey'], json_encode(["content" => ""]), array("Content-Type: application/json")); $this->assert204($response); $this->assertGreaterThan($contentVersion, $response->getHeader("Last-Modified-Version")); // Make sure it's gone $response = API::userGet(self::$config['userID'], "items/{$data['key']}/fulltext?key=" . self::$config['apiKey']); $this->assert200($response); $json = json_decode($response->getBody(), true); $this->assertEquals("", $json['content']); $this->assertArrayNotHasKey("indexedPages", $json); }
public function testTagDeleteUnmodifiedItemChange() { $key = 'AAAAAAAA'; $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; // Create item via sync $data = '<data version="9"><items><item libraryID="' . self::$config['libraryID'] . '" itemType="book" ' . 'dateAdded="2009-03-07 04:53:20" ' . 'dateModified="2009-03-07 04:54:09" ' . 'key="' . $key . '"/></items>' . '<tags><tag libraryID="' . self::$config['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::userGet(self::$config['userID'], "items/{$key}?key=" . self::$config['apiKey'] . "&content=json"); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $originalVersion = $data['version']; $this->assertCount(1, $json->tags); $this->assertTrue(isset($json->tags[0]->tag)); $this->assertEquals("Test", $json->tags[0]->tag); // Get item via sync $xml = Sync::updated(self::$sessionID); $this->assertEquals(1, sizeOf($xml->updated->items->item)); $this->assertEquals(1, sizeOf($xml->updated->tags->tag)); $this->assertEquals(1, sizeOf($xml->updated->tags->tag[0]->items)); $lastsync = (int) $xml['timestamp']; usleep(1500000); // Increment the library version, since we're testing the // version below API::createItem('newspaperArticle', false, false, 'key'); $libraryVersion = API::getLibraryVersion(); $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; // Delete tag via sync, with unmodified item $data = '<data version="9"><items><item libraryID="' . self::$config['libraryID'] . '" itemType="book" ' . 'dateAdded="2009-03-07 04:53:20" ' . 'dateModified="2009-03-07 04:54:09" ' . 'key="' . $key . '"/></items>' . '<deleted><tags><tag libraryID="' . self::$config['libraryID'] . '" key="BBBBBBBB"/>' . '</tags></deleted></data>'; $response = Sync::upload(self::$sessionID, $updateKey, $data); Sync::waitForUpload(self::$sessionID, $response, $this); // Get item via sync $xml = Sync::updated(self::$sessionID); $this->assertEquals(1, sizeOf(isset($xml->updated->tags->tag))); $this->assertFalse(isset($xml->updated->tags->tag[0]->items)); // Get item version via API $response = API::userGet(self::$config['userID'], "items/{$key}?key=" . self::$config['apiKey'] . "&content=json"); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $this->assertEquals(0, (int) array_shift($xml->xpath('/atom:entry/zapi:numTags'))); $this->assertCount(0, $json->tags); // New item version should be greater than before $this->assertGreaterThan($originalVersion, $data['version']); // And should be one more than previous version $this->assertEquals($libraryVersion + 1, $data['version']); // Only the newspaperArticle should be updated $xml = Sync::updated(self::$sessionID, $lastsync); $this->assertEquals(1, $xml->updated[0]->items[0]->count()); }
public function testEditSingleCollection() { API::useAPIVersion(2); $xml = API::createCollection("Test", false, $this); $data = API::parseDataFromAtomEntry($xml); $key = $data['key']; $version = $data['version']; API::useAPIVersion(1); $xml = API::getCollectionXML($data['key']); $etag = (string) array_shift($xml->xpath('//atom:entry/atom:content/@etag')); $this->assertNotNull($etag); $newName = "Test 2"; $json = array("name" => $newName, "parent" => false); $response = API::userPut(self::$config['userID'], "collections/{$key}?key=" . self::$config['apiKey'], json_encode($json), array("Content-Type: application/json", "If-Match: {$etag}")); $this->assert200($response); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $this->assertEquals($newName, (string) $json->name); }
public function testComputerProgram() { $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; $itemKey = 'AAAAAAAA'; // Create item via sync $data = '<data version="9"><items><item libraryID="' . self::$config['libraryID'] . '" itemType="computerProgram" ' . 'dateAdded="2009-03-07 04:53:20" ' . 'dateModified="2009-03-07 04:54:09" ' . 'key="' . $itemKey . '">' . '<field name="version">1.0</field>' . '</item></items></data>'; $response = Sync::upload(self::$sessionID, $updateKey, $data); Sync::waitForUpload(self::$sessionID, $response, $this); // Get item version via API $response = API::userGet(self::$config['userID'], "items/{$itemKey}?key=" . self::$config['apiKey'] . "&content=json"); $this->assertEquals(200, $response->getStatus()); $xml = API::getItemXML($itemKey); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $this->assertEquals('1.0', $json['version']); $json['version'] = '1.1'; $response = API::userPut(self::$config['userID'], "items/{$itemKey}?key=" . self::$config['apiKey'], json_encode($json)); $this->assertEquals(204, $response->getStatus()); $xml = Sync::updated(self::$sessionID); $this->assertEquals('version', (string) $xml->updated[0]->items[0]->item[0]->field[0]['name']); }
public function testAddFileLinkedAttachment() { $xml = API::createAttachmentItem("linked_file", [], false, $this); $data = API::parseDataFromAtomEntry($xml); $file = "work/file"; $fileContents = self::getRandomUnicodeString(); file_put_contents($file, $fileContents); $hash = md5_file($file); $filename = "test_" . $fileContents; $mtime = filemtime($file) * 1000; $size = filesize($file); $contentType = "text/plain"; $charset = "utf-8"; // Get upload authorization $response = API::userPost(self::$config['userID'], "items/{$data['key']}/file?key=" . self::$config['apiKey'], $this->implodeParams(array("md5" => $hash, "filename" => $filename, "filesize" => $size, "mtime" => $mtime, "contentType" => $contentType, "charset" => $charset)), array("Content-Type: application/x-www-form-urlencoded", "If-None-Match: *")); $this->assert400($response); }
public function testDeleteCollectionRelation() { $relations = array("owl:sameAs" => "http://zotero.org/groups/1/collections/AAAAAAAA"); $data = API::createCollection("Test", array("relations" => $relations), $this, 'data'); $json = json_decode($data['content'], true); // Remove all relations $json['relations'] = new \stdClass(); unset($relations['owl:sameAs']); $response = API::userPut(self::$config['userID'], "collections/{$data['key']}?key=" . self::$config['apiKey'], json_encode($json)); $this->assert204($response); // Make sure it's gone $xml = API::getCollectionXML($data['key']); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $this->assertCount(sizeOf($relations), $json['relations']); foreach ($relations as $predicate => $object) { $this->assertEquals($object, $json['relations'][$predicate]); } }
/** * When modifying a tag on an item, only the item itself should have its * version updated, not other items that had (and still have) the same tag */ public function testTagAddItemVersionChange() { $data1 = API::createItem("book", array("tags" => array(array("tag" => "a"), array("tag" => "b"))), $this, 'data'); $json1 = json_decode($data1['content'], true); $version1 = $data1['version']; $data2 = API::createItem("book", array("tags" => array(array("tag" => "a"), array("tag" => "c"))), $this, 'data'); $json2 = json_decode($data2['content'], true); $version2 = $data2['version']; // Remove tag 'a' from item 1 $json1['tags'] = array(array("tag" => "d"), array("tag" => "c")); $response = API::postItem($json1); $this->assert200($response); // Item 1 version should be one greater than last update $xml1 = API::getItemXML($json1['itemKey']); $data1 = API::parseDataFromAtomEntry($xml1); $this->assertEquals($version2 + 1, $data1['version']); // Item 2 version shouldn't have changed $xml2 = API::getItemXML($json2['itemKey']); $data2 = API::parseDataFromAtomEntry($xml2); $this->assertEquals($version2, $data2['version']); }
public function testKeyNoteAccess() { API::userClear(self::$config['userID']); API::setKeyOption(self::$config['userID'], self::$config['apiKey'], 'libraryNotes', 1); $keys = array(); $topLevelKeys = array(); $bookKeys = array(); $xml = API::createItem('book', array("title" => "A"), $this); $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; $topKeys[] = $data['key']; $bookKeys[] = $data['key']; $xml = API::createNoteItem("B", false, $this); $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; $topKeys[] = $data['key']; $xml = API::createNoteItem("C", false, $this); $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; $topKeys[] = $data['key']; $xml = API::createNoteItem("D", false, $this); $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; $topKeys[] = $data['key']; $xml = API::createNoteItem("E", false, $this); $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; $topKeys[] = $data['key']; $xml = API::createItem('book', array("title" => "F"), $this); $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; $topKeys[] = $data['key']; $bookKeys[] = $data['key']; $xml = API::createNoteItem("G", $data['key'], $this); $data = API::parseDataFromAtomEntry($xml); $keys[] = $data['key']; // Create collection and add items to it $response = API::userPost(self::$config['userID'], "collections?key=" . self::$config['apiKey'], json_encode(array("collections" => array(array("name" => "Test", "parentCollection" => false)))), array("Content-Type: application/json")); $this->assert200ForObject($response); $collectionKey = API::getFirstSuccessKeyFromResponse($response); $response = API::userPost(self::$config['userID'], "collections/{$collectionKey}/items?key=" . self::$config['apiKey'], implode(" ", $topKeys)); $this->assert204($response); // // format=atom // // Root $response = API::userGet(self::$config['userID'], "items?key=" . self::$config['apiKey']); $this->assertNumResults(sizeOf($keys), $response); $this->assertTotalResults(sizeOf($keys), $response); // Top $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey']); $this->assertNumResults(sizeOf($topKeys), $response); $this->assertTotalResults(sizeOf($topKeys), $response); // Collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey']); $this->assertNumResults(sizeOf($topKeys), $response); $this->assertTotalResults(sizeOf($topKeys), $response); // // format=keys // // Root $response = API::userGet(self::$config['userID'], "items?key=" . self::$config['apiKey'] . "&format=keys"); $this->assert200($response); $this->assertCount(sizeOf($keys), explode("\n", trim($response->getBody()))); // Top $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&format=keys"); $this->assert200($response); $this->assertCount(sizeOf($topKeys), explode("\n", trim($response->getBody()))); // Collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&format=keys"); $this->assert200($response); $this->assertCount(sizeOf($topKeys), explode("\n", trim($response->getBody()))); // Remove notes privilege from key API::setKeyOption(self::$config['userID'], self::$config['apiKey'], 'libraryNotes', 0); // // format=atom // // totalResults with limit $response = API::userGet(self::$config['userID'], "items?key=" . self::$config['apiKey'] . "&limit=1"); $this->assertNumResults(1, $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // And without limit $response = API::userGet(self::$config['userID'], "items?key=" . self::$config['apiKey']); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // Top $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey']); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // Collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items?key=" . self::$config['apiKey']); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // // format=keys // $response = API::userGet(self::$config['userID'], "items?key=" . self::$config['apiKey'] . "&format=keys"); $keys = explode("\n", trim($response->getBody())); sort($keys); $this->assertEmpty(array_merge(array_diff($bookKeys, $keys), array_diff($keys, $bookKeys))); }
private function _testSingleObjectDelete($objectType) { $objectTypePlural = API::getPluralObjectType($objectType); switch ($objectType) { case 'collection': $xml = API::createCollection("Name", false, $this); break; case 'item': $xml = API::createItem("book", array("title" => "Title"), $this); break; case 'search': $xml = API::createSearch("Name", 'default', $this); break; } $data = API::parseDataFromAtomEntry($xml); $objectKey = $data['key']; $objectVersion = $data['version']; $response = API::userDelete(self::$config['userID'], "{$objectTypePlural}/{$objectKey}?key=" . self::$config['apiKey'], array("If-Unmodified-Since-Version: " . $objectVersion)); $this->assert204($response); $response = API::userGet(self::$config['userID'], "{$objectTypePlural}/{$objectKey}?key=" . self::$config['apiKey']); $this->assert404($response); }