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"))); $json = API::createItem("book", $data, $this, 'jsonData'); $this->assertEquals("AA", $json['title']); $this->assertEquals("BB", $json['creators'][0]['name']); $this->assertEquals("CC", $json['tags'][0]['tag']); }
public function testExportFormatMultiple() { foreach (self::$formats as $format) { $response = API::userGet(self::$config['userID'], "items?format={$format}"); $this->assert200($response); $this->assertContentType(self::$multiResponses[$format]['contentType'], $response); $this->assertEquals(self::$multiResponses[$format]['content'], $response->getBody()); } }
public function testUnlimited() { $quota = 'unlimited'; $expiration = time() + 86400 * 365; $response = API::post('users/' . self::$config['userID'] . '/storageadmin', "quota={$quota}&expiration={$expiration}", [], ["username" => self::$config['rootUsername'], "password" => self::$config['rootPassword']]); $this->assert200($response); $xml = API::getXMLFromResponse($response); $this->assertEquals($quota, (string) $xml->quota); $this->assertEquals($expiration, (int) $xml->expiration); }
/** * An object type's primary data cache for a library has to be created before * */ public function testCacheCreatorPrimaryData() { $data = array("title" => "Title", "creators" => array(array("creatorType" => "author", "firstName" => "First", "lastName" => "Last"), array("creatorType" => "editor", "firstName" => "Ed", "lastName" => "McEditor"))); $key = API::createItem("book", $data, $this, 'key'); $response = API::userGet(self::$config['userID'], "items/{$key}?content=csljson"); $json = json_decode(API::getContentFromResponse($response)); $this->assertEquals("First", $json->author[0]->given); $this->assertEquals("Last", $json->author[0]->family); $this->assertEquals("Ed", $json->editor[0]->given); $this->assertEquals("McEditor", $json->editor[0]->family); }
public function testComputerProgramVersion() { $response = API::get("items/new?itemType=computerProgram"); $this->assert200($response); $json = json_decode($response->getBody()); $this->assertObjectHasAttribute('versionNumber', $json); $this->assertObjectNotHasAttribute('version', $json); $response = API::get("itemTypeFields?itemType=computerProgram"); $this->assert200($response); $json = json_decode($response->getBody()); $fields = array_map(function ($val) { return $val->field; }, $json); $this->assertContains('versionNumber', $fields); $this->assertNotContains('version', $fields); }
public function testLastStorageSyncNoAuthorization() { API::useAPIKey(false); $response = API::userGet( self::$config['userID'], "laststoragesync" ); $this->assert401($response); }
public function testWebTranslationInvalidToken() { $response = API::userPost(self::$config['userID'], "items?key=" . self::$config['apiKey'], json_encode(["url" => "http://www.amazon.com/s/field-keywords=zotero+guide+librarians", "token" => md5(uniqid())]), ["Content-Type: application/json"]); $this->assert400($response, "'token' is valid only for item selection requests"); }
public function testDeleteCollectionRelation() { $relations = array("owl:sameAs" => "http://zotero.org/groups/1/collections/AAAAAAAA"); $data = API::createCollection("Test", array("relations" => $relations), $this, 'jsonData'); // Remove all relations $data['relations'] = new \stdClass(); unset($relations['owl:sameAs']); $response = API::userPut(self::$config['userID'], "collections/{$data['key']}", json_encode($data)); $this->assert204($response); // Make sure it's gone $data = API::getCollection($data['key'], $this, 'json')['data']; $this->assertCount(sizeOf($relations), $data['relations']); foreach ($relations as $predicate => $object) { $this->assertEquals($object, $data['relations'][$predicate]); } }
public function testLinkedFileAttachment() { $msg = "Linked-file attachments cannot be added to publications libraries"; // Create top-level item API::useAPIKey(self::$config['apiKey']); $json = API::getItemTemplate("book"); $response = API::userPost(self::$config['userID'], "publications/items", json_encode([$json])); $this->assert200($response); $json = API::getJSONFromResponse($response); $itemKey = $json['success'][0]; $json = API::getItemTemplate("attachment&linkMode=linked_file"); $json->parentItem = $itemKey; API::useAPIKey(self::$config['apiKey']); $response = API::userPost(self::$config['userID'], "publications/items", json_encode([$json]), array("Content-Type: application/json")); $this->assert400ForObject($response, $msg, 0); }
public function testTagDeletePermissions() { API::userClear(self::$config['userID']); API::createItem('book', array("tags" => array(array("tag" => "A"))), $this); $libraryVersion = API::getLibraryVersion(); API::setKeyOption(self::$config['userID'], self::$config['apiKey'], 'libraryWrite', 0); $response = API::userDelete(self::$config['userID'], "tags?tag=A&key=" . self::$config['apiKey']); $this->assert403($response); API::setKeyOption(self::$config['userID'], self::$config['apiKey'], 'libraryWrite', 1); $response = API::userDelete(self::$config['userID'], "tags?tag=A&key=" . self::$config['apiKey'], array("If-Unmodified-Since-Version: {$libraryVersion}")); $this->assert204($response); }
public function testPatchItems() { // Create top-level item API::useAPIKey(self::$config['apiKey']); $json = API::getItemTemplate("book"); $response = API::userPost(self::$config['userID'], "publications/items", json_encode([$json])); $this->assert200($response); $key = API::getJSONFromResponse($response)['successful'][0]['key']; $version = $response->getHeader("Last-Modified-Version"); $json = ["key" => $key, "version" => $version, "title" => "Test"]; $response = API::userPost(self::$config['userID'], "publications/items", json_encode([$json]), ["Content-Type: application/json"]); $this->assert200ForObject($response); }
public function testCollectionItemMissingCollection() { $response = API::createItem("book", ['collections' => ["AAAAAAAA"]], $this, 'response'); $this->assert400ForObject($response, "Collection with key 'AAAAAAAA' not found"); }
protected function assertNoResults($response) { $this->assertTotalResults(0, $response); $contentType = $response->getHeader('Content-Type'); if ($contentType == 'application/json') { $json = API::getJSONFromResponse($response); $this->assertEquals(0, count($json)); } else { if ($contentType == 'application/atom+xml') { $xml = new SimpleXMLElement($response->getBody()); $zapiNodes = $xml->children(self::$nsZAPI); $this->assertEquals(0, count($xml->entry)); } else { throw new Exception("Unknown content type '{$contentType}'"); } } }
public function testKeyCreateAndDelete() { API::useAPIKey(""); $name = "Test " . uniqid(); // Can't create as user $response = API::userPost(self::$config['userID'], 'keys', json_encode(['name' => $name, 'access' => ['user' => ['library' => true]]])); $this->assert403($response); // Create as root $response = API::userPost(self::$config['userID'], 'keys', json_encode(['name' => $name, 'access' => ['user' => ['library' => true]]]), [], ["username" => self::$config['rootUsername'], "password" => self::$config['rootPassword']]); $this->assert201($response); $json = API::getJSONFromResponse($response); $key = $json['key']; $this->assertEquals($json['name'], $name); $this->assertEquals(['user' => ['library' => true, 'files' => true]], $json['access']); // Delete anonymously (with embedded key) $response = API::userDelete(self::$config['userID'], "keys/{$key}"); $this->assert204($response); $response = API::userGet(self::$config['userID'], "keys/{$key}"); $this->assert404($response); }
/** * 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); }
public function testItemQuickSearchOrderByDate() { $title1 = "Test Title"; $title2 = "Another Title"; $keys = []; $keys[] = API::createItem("book", ['title' => $title1, 'date' => "February 12, 2013"], $this, 'key'); $keys[] = API::createItem("journalArticle", ['title' => $title2, 'date' => "November 25, 2012"], $this, 'key'); // Search for one by title $response = API::userGet(self::$config['userID'], "items?q=" . urlencode($title1)); $this->assert200($response); $this->assertNumResults(1, $response); $json = API::getJSONFromResponse($response); $this->assertEquals($keys[0], $json[0]['key']); // Search by both by title, date asc $response = API::userGet(self::$config['userID'], "items?q=title&sort=date&direction=asc"); $this->assert200($response); $this->assertNumResults(2, $response); $json = API::getJSONFromResponse($response); $this->assertEquals($keys[1], $json[0]['key']); $this->assertEquals($keys[0], $json[1]['key']); // Search by both by title, date asc, with old-style parameters $response = API::userGet(self::$config['userID'], "items?q=title&order=date&sort=asc"); $this->assert200($response); $this->assertNumResults(2, $response); $json = API::getJSONFromResponse($response); $this->assertEquals($keys[1], $json[0]['key']); $this->assertEquals($keys[0], $json[1]['key']); // Search by both by title, date desc $response = API::userGet(self::$config['userID'], "items?q=title&sort=date&direction=desc"); $this->assert200($response); $this->assertNumResults(2, $response); $json = API::getJSONFromResponse($response); $this->assertEquals($keys[0], $json[0]['key']); $this->assertEquals($keys[1], $json[1]['key']); // Search by both by title, date desc, with old-style parameters $response = API::userGet(self::$config['userID'], "items?q=title&order=date&sort=desc"); $this->assert200($response); $this->assertNumResults(2, $response); $json = API::getJSONFromResponse($response); $this->assertEquals($keys[0], $json[0]['key']); $this->assertEquals($keys[1], $json[1]['key']); }
public function testAddFileLinkedAttachment() { $key = API::createAttachmentItem("linked_file", [], false, $this, 'key'); $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/{$key}/file", $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 testFormatBibMultiple() { foreach (self::$styles as $style) { $response = API::userGet(self::$config['userID'], "items?format=bib" . ($style == "default" ? "" : "&style=" . urlencode($style))); $this->assert200($response); $this->assertXmlStringEqualsXmlString(self::$multiResponses[$style], $response->getBody()); } }
public function testTagDiacritics() { $data = API::createItem("book", ["tags" => [["tag" => "ëtest"]]], $this, 'jsonData'); $version = $data['version']; // Add 'etest', without accent $data['tags'] = [["tag" => "ëtest"], ["tag" => "etest"]]; $response = API::postItem($data); $this->assert200($response); $this->assert200ForObject($response); // Item version should be one greater than last update $data = API::getItem($data['key'], $this, 'json')['data']; $this->assertEquals($version + 1, $data['version']); $this->assertCount(2, $data['tags']); $this->assertContains(["tag" => "ëtest"], $data['tags']); $this->assertContains(["tag" => "etest"], $data['tags']); }
public function testOverlongSetting() { $settingKey = "tagColors"; $value = array(array("name" => $this->content = str_repeat("abcdefghij", 1001), "color" => "#990000")); $json = array("value" => $value, "version" => 0); $response = API::userPut(self::$config['userID'], "settings/{$settingKey}", json_encode($json), array("Content-Type: application/json")); $this->assert400($response, "'value' cannot be longer than 1000 characters"); }
public function testSaveUnchangedSanitizedNote() { $json = API::createNoteItem("<span >Foo</span>", false, $this, 'json'); $response = API::postItem($json['data']); $json = API::getJSONFromResponse($response); $this->assertArrayHasKey(0, $json['unchanged']); }
public function testUnicodeTitle() { $title = "Tést"; $key = API::createItem("book", array("title" => $title), $this, 'key'); // Test entry (JSON) $response = API::userGet( self::$config['userID'], "items/$key" ); $this->assertContains('"title": "Tést"', $response->getBody()); // Test feed (JSON) $response = API::userGet( self::$config['userID'], "items" ); $this->assertContains('"title": "Tést"', $response->getBody()); // Test entry (Atom) $response = API::userGet( self::$config['userID'], "items/$key?content=json" ); $this->assertContains('"title": "Tést"', $response->getBody()); // Test feed (Atom) $response = API::userGet( self::$config['userID'], "items?content=json" ); $this->assertContains('"title": "Tést"', $response->getBody()); }
if ($type == 'Private') { continue; } if (!$config['ownedPublicGroupID'] && $type == 'PublicOpen' && $owner == $config['userID'] && $libraryReading == 'all') { $config['ownedPublicGroupID'] = $id; } else { if (!$config['ownedPublicNoAnonymousGroupID'] && $type == 'PublicClosed' && $owner == $config['userID'] && $libraryReading == 'members') { $config['ownedPublicNoAnonymousGroupID'] = $id; } else { $toDelete[] = $id; } } } if (!$config['ownedPublicGroupID']) { $config['ownedPublicGroupID'] = API3::createGroup(['owner' => $config['userID'], 'type' => 'PublicOpen', 'libraryReading' => 'all']); } if (!$config['ownedPublicNoAnonymousGroupID']) { $config['ownedPublicNoAnonymousGroupID'] = API3::createGroup(['owner' => $config['userID'], 'type' => 'PublicClosed', 'libraryReading' => 'members']); } foreach ($toDelete as $groupID) { API3::deleteGroup($groupID); } $config['numOwnedGroups'] = 3; $config['numPublicGroups'] = 2; foreach ($groups as $group) { API3::groupClear($group['id']); } \Zotero\Tests\Config::update($config); unset($response); unset($groups); unset($toDelete);
public function testSortDirection() { API::userClear(self::$config['userID']); // Setup $dataArray = []; $dataArray[] = API::createItem("book", ['title' => "B", 'creators' => [["creatorType" => "author", "name" => "B"]], 'dateAdded' => '2014-02-05T00:00:00Z', 'dateModified' => '2014-04-05T01:00:00Z'], $this, 'jsonData'); $dataArray[] = API::createItem("journalArticle", ['title' => "A", 'creators' => [["creatorType" => "author", "name" => "A"]], 'dateAdded' => '2014-02-04T00:00:00Z', 'dateModified' => '2014-01-04T01:00:00Z'], $this, 'jsonData'); $dataArray[] = API::createItem("newspaperArticle", ['title' => "F", 'creators' => [["creatorType" => "author", "name" => "F"]], 'dateAdded' => '2014-02-03T00:00:00Z', 'dateModified' => '2014-02-03T01:00:00Z'], $this, 'jsonData'); $dataArray[] = API::createItem("book", ['title' => "C", 'creators' => [["creatorType" => "author", "name" => "C"]], 'dateAdded' => '2014-02-02T00:00:00Z', 'dateModified' => '2014-03-02T01:00:00Z'], $this, 'jsonData'); // Get sorted keys usort($dataArray, function ($a, $b) { return strcmp($a['dateAdded'], $b['dateAdded']); }); $keysByDateAddedAscending = array_map(function ($data) { return $data['key']; }, $dataArray); $keysByDateAddedDescending = array_reverse($keysByDateAddedAscending); // Ascending $response = API::userGet(self::$config['userID'], "items?format=keys&sort=dateAdded&direction=asc"); $this->assert200($response); $this->assertEquals($keysByDateAddedAscending, explode("\n", trim($response->getBody()))); $response = API::userGet(self::$config['userID'], "items?format=json&sort=dateAdded&direction=asc"); $this->assert200($response); $json = API::getJSONFromResponse($response); $keys = array_map(function ($val) { return $val['key']; }, $json); $this->assertEquals($keysByDateAddedAscending, $keys); $response = API::userGet(self::$config['userID'], "items?format=atom&sort=dateAdded&direction=asc"); $this->assert200($response); $xml = API::getXMLFromResponse($response); $keys = array_map(function ($val) { return (string) $val; }, $xml->xpath('//atom:entry/zapi:key')); $this->assertEquals($keysByDateAddedAscending, $keys); // Ascending using old 'order'/'sort' instead of 'sort'/'direction' $response = API::userGet(self::$config['userID'], "items?format=keys&order=dateAdded&sort=asc"); $this->assert200($response); $this->assertEquals($keysByDateAddedAscending, explode("\n", trim($response->getBody()))); $response = API::userGet(self::$config['userID'], "items?format=json&order=dateAdded&sort=asc"); $this->assert200($response); $json = API::getJSONFromResponse($response); $keys = array_map(function ($val) { return $val['key']; }, $json); $this->assertEquals($keysByDateAddedAscending, $keys); $response = API::userGet(self::$config['userID'], "items?format=atom&order=dateAdded&sort=asc"); $this->assert200($response); $xml = API::getXMLFromResponse($response); $keys = array_map(function ($val) { return (string) $val; }, $xml->xpath('//atom:entry/zapi:key')); $this->assertEquals($keysByDateAddedAscending, $keys); // Deprecated 'order'/'sort', but the wrong way $response = API::userGet(self::$config['userID'], "items?format=keys&sort=dateAdded&order=asc"); $this->assert200($response); $this->assertEquals($keysByDateAddedAscending, explode("\n", trim($response->getBody()))); // Descending $response = API::userGet(self::$config['userID'], "items?format=keys&sort=dateAdded&direction=desc"); $this->assert200($response); $this->assertEquals($keysByDateAddedDescending, explode("\n", trim($response->getBody()))); $response = API::userGet(self::$config['userID'], "items?format=json&sort=dateAdded&direction=desc"); $this->assert200($response); $json = API::getJSONFromResponse($response); $keys = array_map(function ($val) { return $val['key']; }, $json); $this->assertEquals($keysByDateAddedDescending, $keys); $response = API::userGet(self::$config['userID'], "items?format=atom&sort=dateAdded&direction=desc"); $this->assert200($response); $xml = API::getXMLFromResponse($response); $keys = array_map(function ($val) { return (string) $val; }, $xml->xpath('//atom:entry/zapi:key')); $this->assertEquals($keysByDateAddedDescending, $keys); // Descending $response = API::userGet(self::$config['userID'], "items?format=keys&order=dateAdded&sort=desc"); $this->assert200($response); $this->assertEquals($keysByDateAddedDescending, explode("\n", trim($response->getBody()))); $response = API::userGet(self::$config['userID'], "items?format=json&order=dateAdded&sort=desc"); $this->assert200($response); $json = API::getJSONFromResponse($response); $keys = array_map(function ($val) { return $val['key']; }, $json); $this->assertEquals($keysByDateAddedDescending, $keys); $response = API::userGet(self::$config['userID'], "items?format=atom&order=dateAdded&sort=desc"); $this->assert200($response); $xml = API::getXMLFromResponse($response); $keys = array_map(function ($val) { return (string) $val; }, $xml->xpath('//atom:entry/zapi:key')); $this->assertEquals($keysByDateAddedDescending, $keys); }
public function testNewSearchConditionErrors() { $json = API::createSearch("Test", array(array("operator" => "contains", "value" => "test")), $this, 'responseJSON'); $this->assert400ForObject($json, "'condition' property not provided for search condition"); $json = API::createSearch("Test", array(array("condition" => "", "operator" => "contains", "value" => "test")), $this, 'responseJSON'); $this->assert400ForObject($json, "Search condition cannot be empty"); $json = API::createSearch("Test", array(array("condition" => "title", "value" => "test")), $this, 'responseJSON'); $this->assert400ForObject($json, "'operator' property not provided for search condition"); $json = API::createSearch("Test", array(array("condition" => "title", "operator" => "", "value" => "test")), $this, 'responseJSON'); $this->assert400ForObject($json, "Search operator cannot be empty"); }
private function _testMultiObjectWriteInvalidObject($objectType) { $objectTypePlural = API::getPluralObjectType($objectType); $response = API::userPost(self::$config['userID'], "{$objectTypePlural}", json_encode(["foo" => "bar"]), array("Content-Type: application/json")); $this->assert400($response, "Uploaded data must be a JSON array"); $response = API::userPost(self::$config['userID'], "{$objectTypePlural}", json_encode([[], ""]), array("Content-Type: application/json")); $this->assert400ForObject($response, "Invalid value for index 0 in uploaded data; expected JSON {$objectType} object"); $this->assert400ForObject($response, "Invalid value for index 1 in uploaded data; expected JSON {$objectType} object", 1); }
public static function useAPIKey($key) { self::$apiKey = $key; }
private function _testSinceContent($param) { API::userClear(self::$config['userID']); // Store content for one item $key = API::createItem("book", false, $this, 'key'); $json = API::createAttachmentItem("imported_url", [], $key, $this, 'jsonData'); $key1 = $json['key']; $content = "Here is some full-text content"; $response = API::userPut(self::$config['userID'], "items/{$key1}/fulltext", json_encode(["content" => $content]), array("Content-Type: application/json")); $this->assert204($response); $contentVersion1 = $response->getHeader("Last-Modified-Version"); $this->assertGreaterThan(0, $contentVersion1); // And another $key = API::createItem("book", false, $this, 'key'); $json = API::createAttachmentItem("imported_url", [], $key, $this, 'jsonData'); $key2 = $json['key']; $response = API::userPut(self::$config['userID'], "items/{$key2}/fulltext", json_encode(["content" => $content]), array("Content-Type: application/json")); $this->assert204($response); $contentVersion2 = $response->getHeader("Last-Modified-Version"); $this->assertGreaterThan(0, $contentVersion2); // Get newer one $response = API::userGet(self::$config['userID'], "fulltext?{$param}={$contentVersion1}"); $this->assert200($response); $this->assertContentType("application/json", $response); $this->assertEquals($contentVersion2, $response->getHeader("Last-Modified-Version")); $json = API::getJSONFromResponse($response); $this->assertCount(1, $json); $this->assertArrayHasKey($key2, $json); $this->assertEquals($contentVersion2, $json[$key2]); // Get both with since=0 $response = API::userGet(self::$config['userID'], "fulltext?{$param}=0"); $this->assert200($response); $this->assertContentType("application/json", $response); $json = API::getJSONFromResponse($response); $this->assertCount(2, $json); $this->assertArrayHasKey($key1, $json); $this->assertEquals($contentVersion1, $json[$key1]); $this->assertArrayHasKey($key1, $json); $this->assertEquals($contentVersion2, $json[$key2]); }
private function _testTagsSince($param) { $tags1 = array("a", "aa", "b"); $tags2 = array("b", "c", "cc"); $data1 = API::createItem("book", array("tags" => array_map(function ($tag) { return array("tag" => $tag); }, $tags1)), $this, 'jsonData'); $data2 = API::createItem("book", array("tags" => array_map(function ($tag) { return array("tag" => $tag); }, $tags2)), $this, 'jsonData'); // Only newly added tags should be included in 'since', // not previously added tags or tags added to items $response = API::userGet(self::$config['userID'], "tags?{$param}=" . $data1['version']); $this->assertNumResults(2, $response); // Deleting an item shouldn't update associated tag versions $response = API::userDelete(self::$config['userID'], "items/{$data1['key']}", array("If-Unmodified-Since-Version: " . $data1['version'])); $this->assert204($response); $response = API::userGet(self::$config['userID'], "tags?{$param}=" . $data1['version']); $this->assertNumResults(2, $response); $libraryVersion = $response->getHeader("Last-Modified-Version"); $response = API::userGet(self::$config['userID'], "tags?{$param}=" . $libraryVersion); $this->assertNumResults(0, $response); }
public function test204NoCompression() { $json = API::createItem("book", [], null, 'jsonData'); $response = API::userDelete(self::$config['userID'], "items/{$json['key']}", ["If-Unmodified-Since-Version: {$json['version']}"]); $this->assertHTTPStatus(204, $response); $this->assertNoCompression($response); $this->assertContentLength(0, $response); }