public function setUp() { API::userClear(self::$config['userID']); API::groupClear(self::$config['ownedPrivateGroupID']); API::groupClear(self::$config['ownedPublicGroupID']); self::$sessionID = Sync::login(); }
public function setUp() { API::userClear(self::$config['userID']); API::groupClear(self::$config['ownedPrivateGroupID']); API::groupClear(self::$config['ownedPrivateGroupID2']); self::$sessionID = Sync::login(); self::$sessionID2 = Sync::login(array('username' => self::$config['username2'], 'password' => self::$config['password2'])); }
public function testTagDeletePermissions() { API::userClear(self::$config['userID']); $xml = 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 static function tearDownAfterClass() { parent::tearDownAfterClass(); API::userClear(self::$config['userID']); }
private function _testDeleteAndDeleted($objectType) { API::userClear(self::$config['userID']); $objectTypePlural = API::getPluralObjectType($objectType); $xml = Sync::updated(self::$sessionID); $lastSyncTimestamp = (int) $xml['timestamp']; // Create via sync switch ($objectType) { case 'item': $keys[] = Sync::createItem(self::$sessionID, self::$config['libraryID'], "book", false, $this); break; case 'setting': $settingKey = "tagColors"; $response = API::userPut(self::$config['userID'], "settings/{$settingKey}?key=" . self::$config['apiKey'], json_encode(array("value" => array(array("name" => "_READ", "color" => "#990000")))), array("Content-Type: application/json", "If-Unmodified-Since-Version: 0")); $this->assertEquals(204, $response->getStatus()); $keys[] = $settingKey; break; } // Check via API foreach ($keys as $key) { $response = API::userGet(self::$config['userID'], "{$objectTypePlural}/{$key}?key=" . self::$config['apiKey']); $this->assertEquals(200, $response->getStatus()); $version = $response->getHeader("Last-Modified-Version"); $this->assertNotNull($version); } // Get empty deleted via API $response = API::userGet(self::$config['userID'], "deleted?key=" . self::$config['apiKey'] . "&newer={$version}"); $this->assertEquals(200, $response->getStatus()); $json = json_decode($response->getBody(), true); $this->assertEmpty($json[$objectTypePlural]); // Get empty deleted via API with newertime $response = API::userGet(self::$config['userID'], "deleted?key=" . self::$config['apiKey'] . "&newertime={$lastSyncTimestamp}"); $this->assertEquals(200, $response->getStatus()); $json = json_decode($response->getBody(), true); $this->assertEmpty($json[$objectTypePlural]); // Delete via sync foreach ($keys as $key) { switch ($objectType) { case 'item': Sync::deleteItem(self::$sessionID, self::$config['libraryID'], $key, $this); break; case 'setting': // Delete via sync $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; $xmlstr = '<data version="9">' . '<deleted>' . '<settings>' . '<setting libraryID="' . self::$config['libraryID'] . '" key="' . $key . '"/>' . '</settings>' . '</deleted>' . '</data>'; $response = Sync::upload(self::$sessionID, $updateKey, $xmlstr); Sync::waitForUpload(self::$sessionID, $response, $this); break; } } // Check 404 via API foreach ($keys as $key) { $response = API::userGet(self::$config['userID'], "{$objectTypePlural}/{$key}?key=" . self::$config['apiKey']); $this->assertEquals(404, $response->getStatus()); } // Get deleted via API $response = API::userGet(self::$config['userID'], "deleted?key=" . self::$config['apiKey'] . "&newer={$version}"); $this->assertEquals(200, $response->getStatus()); $json = json_decode($response->getBody(), true); $this->assertArrayHasKey($objectTypePlural, $json); $this->assertCount(sizeOf($keys), $json[$objectTypePlural]); foreach ($keys as $key) { $this->assertContains($key, $json[$objectTypePlural]); } // Get deleted via API with newertime $response = API::userGet(self::$config['userID'], "deleted?key=" . self::$config['apiKey'] . "&newertime={$lastSyncTimestamp}"); $this->assertEquals(200, $response->getStatus()); $json = json_decode($response->getBody(), true); $this->assertArrayHasKey($objectTypePlural, $json); $this->assertCount(sizeOf($keys), $json[$objectTypePlural]); foreach ($keys as $key) { $this->assertContains($key, $json[$objectTypePlural]); } // Should be empty with later newertime $xml = Sync::updated(self::$sessionID); $lastSyncTimestamp = (int) $xml['timestamp']; $response = API::userGet(self::$config['userID'], "deleted?key=" . self::$config['apiKey'] . "&newertime=" . ($lastSyncTimestamp + 2)); $this->assertEquals(200, $response->getStatus()); $json = json_decode($response->getBody(), true); $this->assertEmpty($json[$objectTypePlural]); }
public static function tearDownAfterClass() { parent::tearDownAfterClass(); require 'include/config.inc.php'; API::userClear($config['userID']); }
public function testAddFileClientZip() { API::userClear(self::$config['userID']); $auth = array('username' => self::$config['username'], 'password' => self::$config['password']); // Get last storage sync $response = API::userGet(self::$config['userID'], "laststoragesync?auth=1", array(), $auth); $this->assert404($response); $xml = API::createItem("book", false, $this); $data = API::parseDataFromAtomEntry($xml); $key = $data['key']; $fileContentType = "text/html"; $fileCharset = "UTF-8"; $fileFilename = "file.html"; $fileModtime = time(); $xml = API::createAttachmentItem("imported_url", [], $key, $this); $data = API::parseDataFromAtomEntry($xml); $key = $data['key']; $version = $data['version']; $json = json_decode($data['content']); $json->contentType = $fileContentType; $json->charset = $fileCharset; $json->filename = $fileFilename; $response = API::userPut(self::$config['userID'], "items/{$key}?key=" . self::$config['apiKey'], json_encode($json), array("Content-Type: application/json")); $this->assert204($response); // Get a sync timestamp from before the file is updated sleep(1); require_once 'include/sync.inc.php'; $sessionID = Sync::login(); $xml = Sync::updated($sessionID); $lastsync = (int) $xml['timestamp']; Sync::logout($sessionID); // Get file info $response = API::userGet(self::$config['userID'], "items/{$data['key']}/file?auth=1&iskey=1&version=1&info=1", array(), $auth); $this->assert404($response); $zip = new ZipArchive(); $file = "work/{$key}.zip"; if ($zip->open($file, ZIPARCHIVE::CREATE) !== TRUE) { throw new Exception("Cannot open ZIP file"); } $zip->addFromString($fileFilename, self::getRandomUnicodeString()); $zip->addFromString("file.css", self::getRandomUnicodeString()); $zip->close(); $hash = md5_file($file); $filename = $key . ".zip"; $size = filesize($file); $fileContents = file_get_contents($file); // Get upload authorization $response = API::userPost(self::$config['userID'], "items/{$data['key']}/file?auth=1&iskey=1&version=1", $this->implodeParams(array("md5" => $hash, "filename" => $filename, "filesize" => $size, "mtime" => $fileModtime, "zip" => 1)), array("Content-Type: application/x-www-form-urlencoded"), $auth); $this->assert200($response); $this->assertContentType("application/xml", $response); $xml = new SimpleXMLElement($response->getBody()); self::$toDelete[] = "{$hash}"; $boundary = "---------------------------" . rand(); $postData = ""; foreach ($xml->params->children() as $key => $val) { $postData .= "--" . $boundary . "\r\nContent-Disposition: form-data; " . "name=\"{$key}\"\r\n\r\n{$val}\r\n"; } $postData .= "--" . $boundary . "\r\nContent-Disposition: form-data; " . "name=\"file\"\r\n\r\n" . $fileContents . "\r\n"; $postData .= "--" . $boundary . "--"; // Upload to S3 $response = HTTP::post((string) $xml->url, $postData, array("Content-Type: multipart/form-data; boundary=" . $boundary)); $this->assert201($response); // // Register upload // $response = API::userPost(self::$config['userID'], "items/{$data['key']}/file?auth=1&iskey=1&version=1", "update=" . $xml->key . "&mtime=" . $fileModtime, array("Content-Type: application/x-www-form-urlencoded"), $auth); $this->assert204($response); // Verify attachment item metadata $response = API::userGet(self::$config['userID'], "items/{$data['key']}?key=" . self::$config['apiKey'] . "&content=json"); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $this->assertEquals($hash, $json->md5); $this->assertEquals($fileFilename, $json->filename); $this->assertEquals($fileModtime, $json->mtime); // Make sure attachment item wasn't updated (or else the client // will get a conflict when it tries to update the metadata) $sessionID = Sync::login(); $xml = Sync::updated($sessionID, $lastsync); Sync::logout($sessionID); $this->assertEquals(0, $xml->updated[0]->count()); $response = API::userGet(self::$config['userID'], "laststoragesync?auth=1", array(), array('username' => self::$config['username'], 'password' => self::$config['password'])); $this->assert200($response); $mtime = $response->getBody(); $this->assertRegExp('/^[0-9]{10}$/', $mtime); // File exists $response = API::userPost(self::$config['userID'], "items/{$data['key']}/file?auth=1&iskey=1&version=1", $this->implodeParams(array("md5" => $hash, "filename" => $filename, "filesize" => $size, "mtime" => $fileModtime + 1000, "zip" => 1)), array("Content-Type: application/x-www-form-urlencoded"), $auth); $this->assert200($response); $this->assertContentType("application/xml", $response); $this->assertEquals("<exists/>", $response->getBody()); // Make sure attachment item still wasn't updated $sessionID = Sync::login(); $xml = Sync::updated($sessionID, $lastsync); Sync::logout($sessionID); $this->assertEquals(0, $xml->updated[0]->count()); }
public function testTop() { API::userClear(self::$config['userID']); $collectionKey = API::createCollection('Test', false, $this, 'key'); $parentTitle1 = "Parent Title"; $childTitle1 = "This is a Test Title"; $parentTitle2 = "Another Parent Title"; $parentTitle3 = "Yet Another Parent Title"; $noteText = "This is a sample note."; $parentTitleSearch = "title"; $childTitleSearch = "test"; $dates = ["2013", "January 3, 2010", ""]; $orderedDates = [$dates[2], $dates[1], $dates[0]]; $itemTypes = ["journalArticle", "newspaperArticle", "book"]; $parentKeys = []; $childKeys = []; $parentKeys[] = API::createItem($itemTypes[0], ['title' => $parentTitle1, 'date' => $dates[0], 'collections' => [$collectionKey]], $this, 'key'); $childKeys[] = API::createAttachmentItem("linked_url", ['title' => $childTitle1], $parentKeys[0], $this, 'key'); $parentKeys[] = API::createItem($itemTypes[1], ['title' => $parentTitle2, 'date' => $dates[1]], $this, 'key'); $childKeys[] = API::createNoteItem($noteText, $parentKeys[1], $this, 'key'); // Create item with deleted child that matches child title search $parentKeys[] = API::createItem($itemTypes[2], ['title' => $parentTitle3], $this, 'key'); API::createAttachmentItem("linked_url", ['title' => $childTitle1, 'deleted' => true], $parentKeys[sizeOf($parentKeys) - 1], $this, 'key'); // Add deleted item with non-deleted child $deletedKey = API::createItem("book", ['title' => "This is a deleted item", 'deleted' => true], $this, 'key'); API::createNoteItem("This is a child note of a deleted item.", $deletedKey, $this, 'key'); // /top, Atom $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json"); $this->assert200($response); $this->assertNumResults(sizeOf($parentKeys), $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertCount(sizeOf($parentKeys), $xpath); foreach ($parentKeys as $parentKey) { $this->assertContains($parentKey, $xpath); } // /top, Atom, in collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&content=json"); $this->assert200($response); $this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertCount(1, $xpath); $this->assertContains($parentKeys[0], $xpath); // /top, keys $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&format=keys"); $this->assert200($response); $keys = explode("\n", trim($response->getBody())); $this->assertCount(sizeOf($parentKeys), $keys); foreach ($parentKeys as $parentKey) { $this->assertContains($parentKey, $keys); } // /top, keys, in collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&format=keys"); $this->assert200($response); $this->assertEquals($parentKeys[0], trim($response->getBody())); // /top with itemKey for parent, Atom $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&itemKey=" . $parentKeys[0]); $this->assert200($response); $this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertEquals($parentKeys[0], (string) array_shift($xpath)); // /top with itemKey for parent, Atom, in collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&content=json&itemKey=" . $parentKeys[0]); $this->assert200($response); $this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertEquals($parentKeys[0], (string) array_shift($xpath)); // /top with itemKey for parent, keys $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&format=keys&itemKey=" . $parentKeys[0]); $this->assert200($response); $this->assertEquals($parentKeys[0], trim($response->getBody())); // /top with itemKey for parent, keys, in collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&format=keys&itemKey=" . $parentKeys[0]); $this->assert200($response); $this->assertEquals($parentKeys[0], trim($response->getBody())); // /top with itemKey for child, Atom $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&itemKey=" . $childKeys[0]); $this->assert200($response); $this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertEquals($parentKeys[0], (string) array_shift($xpath)); // /top with itemKey for child, keys $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&format=keys&itemKey=" . $childKeys[0]); $this->assert200($response); $this->assertEquals($parentKeys[0], trim($response->getBody())); // /top, Atom, with q for all items $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&q={$parentTitleSearch}"); $this->assert200($response); $this->assertNumResults(sizeOf($parentKeys), $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertCount(sizeOf($parentKeys), $xpath); foreach ($parentKeys as $parentKey) { $this->assertContains($parentKey, $xpath); } // /top, Atom, in collection, with q for all items $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&content=json&q={$parentTitleSearch}"); $this->assert200($response); $this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertCount(1, $xpath); $this->assertContains($parentKeys[0], $xpath); // /top, Atom, with q for child item $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&q={$childTitleSearch}"); $this->assert200($response); $this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertCount(1, $xpath); $this->assertContains($parentKeys[0], $xpath); // /top, Atom, in collection, with q for child item $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top?key=" . self::$config['apiKey'] . "&content=json&q={$childTitleSearch}"); $this->assert200($response); $this->assertNumResults(0, $response); // Not currently possible /*$this->assertNumResults(1, $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:key'); $this->assertCount(1, $xpath); $this->assertContains($parentKeys[0], $xpath);*/ // /top, Atom, with q for all items, ordered by title $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&q={$parentTitleSearch}" . "&order=title"); $this->assert200($response); $this->assertNumResults(sizeOf($parentKeys), $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/atom:title'); $this->assertCount(sizeOf($parentKeys), $xpath); $orderedTitles = [$parentTitle1, $parentTitle2, $parentTitle3]; sort($orderedTitles); $orderedResults = array_map(function ($val) { return (string) $val; }, $xpath); $this->assertEquals($orderedTitles, $orderedResults); // /top, Atom, with q for all items, ordered by date asc $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&q={$parentTitleSearch}" . "&order=date&sort=asc"); $this->assert200($response); $this->assertNumResults(sizeOf($parentKeys), $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/atom:content'); $this->assertCount(sizeOf($parentKeys), $xpath); $orderedResults = array_map(function ($val) { return json_decode($val)->date; }, $xpath); $this->assertEquals($orderedDates, $orderedResults); // /top, Atom, with q for all items, ordered by date desc $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&q={$parentTitleSearch}" . "&order=date&sort=desc"); $this->assert200($response); $this->assertNumResults(sizeOf($parentKeys), $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/atom:content'); $this->assertCount(sizeOf($parentKeys), $xpath); $orderedDatesReverse = array_reverse($orderedDates); $orderedResults = array_map(function ($val) { return json_decode($val)->date; }, $xpath); $this->assertEquals($orderedDatesReverse, $orderedResults); // /top, Atom, with q for all items, ordered by item type asc $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&q={$parentTitleSearch}" . "&order=itemType"); $this->assert200($response); $this->assertNumResults(sizeOf($parentKeys), $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:itemType'); $this->assertCount(sizeOf($parentKeys), $xpath); $orderedItemTypes = $itemTypes; sort($orderedItemTypes); $orderedResults = array_map(function ($val) { return (string) $val; }, $xpath); $this->assertEquals($orderedItemTypes, $orderedResults); // /top, Atom, with q for all items, ordered by item type desc $response = API::userGet(self::$config['userID'], "items/top?key=" . self::$config['apiKey'] . "&content=json&q={$parentTitleSearch}" . "&order=itemType&sort=desc"); $this->assert200($response); $this->assertNumResults(sizeOf($parentKeys), $response); $xml = API::getXMLFromResponse($response); $xpath = $xml->xpath('//atom:entry/zapi:itemType'); $this->assertCount(sizeOf($parentKeys), $xpath); $orderedItemTypes = $itemTypes; rsort($orderedItemTypes); $orderedResults = array_map(function ($val) { return (string) $val; }, $xpath); $this->assertEquals($orderedItemTypes, $orderedResults); }
public function setUp() { parent::setUp(); API::userClear(self::$config['userID']); }
public function testTagNewer() { API::userClear(self::$config['userID']); // Create items with tags API::createItem("book", array("tags" => array(array("tag" => "a"), array("tag" => "b"))), $this); $version = API::getLibraryVersion(); // 'newer' shouldn't return any results $response = API::userGet(self::$config['userID'], "tags?key=" . self::$config['apiKey'] . "&content=json&newer={$version}"); $this->assert200($response); $this->assertNumResults(0, $response); // Create another item with tags API::createItem("book", array("tags" => array(array("tag" => "a"), array("tag" => "c"))), $this); // 'newer' should return new tag $response = API::userGet(self::$config['userID'], "tags?key=" . self::$config['apiKey'] . "&content=json&newer={$version}"); $this->assert200($response); $this->assertNumResults(1, $response); $this->assertGreaterThan($version, $response->getHeader('Last-Modified-Version')); $content = API::getContentFromResponse($response); $json = json_decode($content, true); $this->assertEquals("c", $json['tag']); $this->assertEquals(0, $json['type']); }
public function setUp() { API::userClear(self::$config['userID']); self::$sessionID = Sync::login(); }
public function testNewerContent() { API::userClear(self::$config['userID']); // Store content for one item $key = API::createItem("book", false, $this, 'key'); $xml = API::createAttachmentItem("imported_url", [], $key, $this, 'atom'); $data = API::parseDataFromAtomEntry($xml); $key1 = $data['key']; $content = "Here is some full-text content"; $response = API::userPut(self::$config['userID'], "items/{$key1}/fulltext?key=" . self::$config['apiKey'], 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'); $xml = API::createAttachmentItem("imported_url", [], $key, $this, 'atom'); $data = API::parseDataFromAtomEntry($xml); $key2 = $data['key']; $response = API::userPut(self::$config['userID'], "items/{$key2}/fulltext?key=" . self::$config['apiKey'], 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?key=" . self::$config['apiKey'] . "&newer={$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 newer=0 $response = API::userGet(self::$config['userID'], "fulltext?key=" . self::$config['apiKey'] . "&newer=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]); }
public function tearDown() { API::userClear(self::$config['userID']); API::groupClear(self::$config['ownedPrivateGroupID']); }
public static function tearDownAfterClass() { parent::tearDownAfterClass(); API::userClear(self::$config['userID']); API::groupClear(self::$config['ownedPrivateGroupID']); }
private function _testPartialWriteFailureWithUnchanged($objectType) { API::userClear(self::$config['userID']); $objectTypePlural = API::getPluralObjectType($objectType); switch ($objectType) { case 'collection': $data = API::createCollection("Test", false, $this, 'data'); $json1 = json_decode($data['content']); $json2 = array("name" => str_repeat("1234567890", 6554)); $json3 = array("name" => "Test"); break; case 'item': $data = API::createItem("book", array("title" => "Title"), $this, 'data'); $json1 = json_decode($data['content']); $json2 = API::getItemTemplate('book'); $json3 = clone $json2; $json2->title = str_repeat("1234567890", 6554); break; case 'search': $conditions = array(array('condition' => 'title', 'operator' => 'contains', 'value' => 'value')); $data = API::createSearch("Name", $conditions, $this, 'data'); $json1 = json_decode($data['content']); $json2 = array("name" => str_repeat("1234567890", 6554), "conditions" => $conditions); $json3 = array("name" => "Test", "conditions" => $conditions); break; } $response = API::userPost(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'], json_encode(array("{$objectTypePlural}" => array($json1, $json2, $json3))), array("Content-Type: application/json")); $this->assert200($response); $json = API::getJSONFromResponse($response); $this->assertUnchangedForObject($response, false, 0); $this->assert400ForObject($response, false, 1); $this->assert200ForObject($response, false, 2); $json = API::getJSONFromResponse($response); $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?format=keys&key=" . self::$config['apiKey']); $this->assert200($response); $keys = explode("\n", trim($response->getBody())); $this->assertCount(2, $keys); foreach ($json['success'] as $key) { $this->assertContains($key, $keys); } }