public static function setUpBeforeClass() { parent::setUpBeforeClass(); API::userClear(self::$config['userID']); // // Collections // /*for ($i=0; $i<5; $i++) { self::$collectionKeys[] = API::createCollection("Test", false, null, 'key'); }*/ // // Items // $titles = self::$titles; $names = self::$names; for ($i = 0; $i < sizeOf(self::$titles) - 2; $i++) { $key = API::createItem("book", ['title' => array_shift($titles), 'creators' => [["creatorType" => "author", "name" => array_shift($names)]]], null, 'key'); // Child attachments if (!is_null(self::$attachmentTitles[$i])) { self::$childAttachmentKeys[] = API::createAttachmentItem("imported_file", ['title' => self::$attachmentTitles[$i]], $key, null, 'key'); } // Child notes if (!is_null(self::$notes[$i])) { self::$childNoteKeys[] = API::createNoteItem(self::$notes[$i], $key, null, 'key'); } self::$itemKeys[] = $key; } // Top-level attachment self::$itemKeys[] = API::createAttachmentItem("imported_file", ['title' => array_shift($titles)], false, null, 'key'); // Top-level note self::$itemKeys[] = API::createNoteItem(array_shift($titles), false, null, 'key'); // // Searches // /*for ($i=0; $i<5; $i++) { self::$searchKeys[] = API::createSearch("Test", 'default', null, 'key'); }*/ }
private function _testSinceAndVersionsFormat($objectType, $sinceParam) { $objectTypePlural = API::getPluralObjectType($objectType); $dataArray = []; switch ($objectType) { case 'collection': $dataArray[] = API::createCollection("Name", false, $this, 'jsonData'); $dataArray[] = API::createCollection("Name", false, $this, 'jsonData'); $dataArray[] = API::createCollection("Name", false, $this, 'jsonData'); break; case 'item': $dataArray[] = API::createItem("book", array("title" => "Title"), $this, 'jsonData'); $dataArray[] = API::createNoteItem("Foo", $dataArray[0]['key'], $this, 'jsonData'); $dataArray[] = API::createItem("book", array("title" => "Title"), $this, 'jsonData'); $dataArray[] = API::createItem("book", array("title" => "Title"), $this, 'jsonData'); break; case 'search': $dataArray[] = API::createSearch("Name", array(array("condition" => "title", "operator" => "contains", "value" => "test")), $this, 'jsonData'); $dataArray[] = API::createSearch("Name", array(array("condition" => "title", "operator" => "contains", "value" => "test")), $this, 'jsonData'); $dataArray[] = API::createSearch("Name", array(array("condition" => "title", "operator" => "contains", "value" => "test")), $this, 'jsonData'); } $objects = $dataArray; $firstVersion = $objects[0]['version']; $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?format=versions&{$sinceParam}={$firstVersion}"); $this->assert200($response); $json = json_decode($response->getBody(), true); $this->assertNotNull($json); $this->assertCount(sizeOf($objects) - 1, $json); $keys = array_keys($json); if ($objectType == 'item') { $this->assertEquals($objects[3]['key'], array_shift($keys)); $this->assertEquals($objects[3]['version'], array_shift($json)); } $this->assertEquals($objects[2]['key'], array_shift($keys)); $this->assertEquals($objects[2]['version'], array_shift($json)); $this->assertEquals($objects[1]['key'], array_shift($keys)); $this->assertEquals($objects[1]['version'], array_shift($json)); $this->assertEmpty($json); // Test /top for items if ($objectType == 'item') { $response = API::userGet(self::$config['userID'], "items/top?format=versions&{$sinceParam}={$firstVersion}"); $this->assert200($response); $json = json_decode($response->getBody(), true); $this->assertNotNull($json); $this->assertCount(sizeOf($objects) - 2, $json); // Exclude first item and child $keys = array_keys($json); $objects = $dataArray; $this->assertEquals($objects[3]['key'], array_shift($keys)); $this->assertEquals($objects[3]['version'], array_shift($json)); $this->assertEquals($objects[2]['key'], array_shift($keys)); $this->assertEquals($objects[2]['version'], array_shift($json)); $this->assertEmpty($json); } }
public function testIncludeTrashed() { API::userClear(self::$config['userID']); $key1 = API::createItem("book", false, $this, 'key'); $key2 = API::createItem("book", [ "deleted" => 1 ], $this, 'key'); $key3 = API::createNoteItem("", $key1, $this, 'key'); // All three items should show up with includeTrashed=1 $response = API::userGet( self::$config['userID'], "items?includeTrashed=1" ); $json = API::getJSONFromResponse($response); $this->assertCount(3, $json); $keys = [$json[0]['key'], $json[1]['key'], $json[2]['key']]; $this->assertContains($key1, $keys); $this->assertContains($key2, $keys); $this->assertContains($key3, $keys); // ?itemKey should show the deleted item $response = API::userGet( self::$config['userID'], "items?itemKey=$key2,$key3&includeTrashed=1" ); $json = API::getJSONFromResponse($response); $this->assertCount(2, $json); $keys = [$json[0]['key'], $json[1]['key']]; $this->assertContains($key2, $keys); $this->assertContains($key3, $keys); // /top should show the deleted item $response = API::userGet( self::$config['userID'], "items/top?includeTrashed=1" ); $json = API::getJSONFromResponse($response); $this->assertCount(2, $json); $keys = [$json[0]['key'], $json[1]['key']]; $this->assertContains($key1, $keys); $this->assertContains($key2, $keys); }
public function testCollectionChildItemError() { $collectionKey = API::createCollection('Test', false, $this, 'key'); $key = API::createItem("book", array(), $this, 'key'); $json = API::createNoteItem("Test Note", $key, $this, 'jsonData'); $json['collections'] = [$collectionKey]; $response = API::userPut(self::$config['userID'], "items/{$json['key']}", json_encode($json), array("Content-Type: application/json")); $this->assert400($response); $this->assertEquals("Child items cannot be assigned to collections", $response->getBody()); }
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 testKeyNoteAccess() { API::userClear(self::$config['userID']); API::setKeyOption(self::$config['userID'], self::$config['apiKey'], 'libraryNotes', 1); $keys = array(); $topLevelKeys = array(); $bookKeys = array(); $key = API::createItem('book', array("title" => "A"), $this, 'key'); $keys[] = $key; $topKeys[] = $key; $bookKeys[] = $key; $key = API::createNoteItem("B", false, $this, 'key'); $keys[] = $key; $topKeys[] = $key; $key = API::createNoteItem("C", false, $this, 'key'); $keys[] = $key; $topKeys[] = $key; $key = API::createNoteItem("D", false, $this, 'key'); $keys[] = $key; $topKeys[] = $key; $key = API::createNoteItem("E", false, $this, 'key'); $keys[] = $key; $topKeys[] = $key; $key = API::createItem('book', array("title" => "F"), $this, 'key'); $keys[] = $key; $topKeys[] = $key; $bookKeys[] = $key; $key = API::createNoteItem("G", $key, $this, 'key'); $keys[] = $key; // Create collection and add items to it $response = API::userPost(self::$config['userID'], "collections", json_encode([["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", implode(" ", $topKeys)); $this->assert204($response); // // format=atom // // Root $response = API::userGet(self::$config['userID'], "items"); $this->assertNumResults(sizeOf($keys), $response); $this->assertTotalResults(sizeOf($keys), $response); // Top $response = API::userGet(self::$config['userID'], "items/top"); $this->assertNumResults(sizeOf($topKeys), $response); $this->assertTotalResults(sizeOf($topKeys), $response); // Collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items/top"); $this->assertNumResults(sizeOf($topKeys), $response); $this->assertTotalResults(sizeOf($topKeys), $response); // // format=keys // // Root $response = API::userGet(self::$config['userID'], "items?format=keys"); $this->assert200($response); $this->assertCount(sizeOf($keys), explode("\n", trim($response->getBody()))); // Top $response = API::userGet(self::$config['userID'], "items/top?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?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=json // // totalResults with limit $response = API::userGet(self::$config['userID'], "items?limit=1"); $this->assertNumResults(1, $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // And without limit $response = API::userGet(self::$config['userID'], "items"); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // Top $response = API::userGet(self::$config['userID'], "items/top"); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // Collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items"); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // // format=atom // // totalResults with limit $response = API::userGet(self::$config['userID'], "items?format=atom&limit=1"); $this->assertNumResults(1, $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // And without limit $response = API::userGet(self::$config['userID'], "items?format=atom"); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // Top $response = API::userGet(self::$config['userID'], "items/top?format=atom"); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // Collection $response = API::userGet(self::$config['userID'], "collections/{$collectionKey}/items?format=atom"); $this->assertNumResults(sizeOf($bookKeys), $response); $this->assertTotalResults(sizeOf($bookKeys), $response); // // format=keys // $response = API::userGet(self::$config['userID'], "items?format=keys"); $keys = explode("\n", trim($response->getBody())); sort($keys); $this->assertEmpty(array_merge(array_diff($bookKeys, $keys), array_diff($keys, $bookKeys))); }