public function testFormatKeys() { // // Collections // for ($i = 0; $i < 5; $i++) { self::$collectionKeys[] = API::createCollection("Test", false, null, 'key'); } // // Items // for ($i = 0; $i < 5; $i++) { self::$itemKeys[] = API::createItem("book", false, null, 'key'); } self::$itemKeys[] = API::createAttachmentItem("imported_file", [], false, null, 'key'); // // Searches // for ($i = 0; $i < 5; $i++) { self::$searchKeys[] = API::createSearch("Test", 'default', null, 'key'); } $this->_testFormatKeys('collection'); $this->_testFormatKeys('item'); $this->_testFormatKeys('search'); $this->_testFormatKeysSorted('collection'); $this->_testFormatKeysSorted('item'); $this->_testFormatKeysSorted('search'); }
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'); }*/ }
public function testParentItemPatch() { $json = API::createItem("book", false, $this, 'jsonData'); $parentKey = $json['key']; $parentVersion = $json['version']; $json = API::createAttachmentItem("linked_url", [], $parentKey, $this, 'jsonData'); $childKey = $json['key']; $childVersion = $json['version']; $this->assertArrayHasKey('parentItem', $json); $this->assertEquals($parentKey, $json['parentItem']); $json = array( 'title' => 'Test' ); // With PATCH, parent shouldn't be removed even though unspecified $response = API::userPatch( self::$config['userID'], "items/$childKey", json_encode($json), array("If-Unmodified-Since-Version: " . $childVersion) ); $this->assert204($response); $json = API::getItem($childKey, $this, 'json')['data']; $this->assertArrayHasKey('parentItem', $json); $childVersion = $json['version']; // But it should be removed with parentItem: false $json = [ 'parentItem' => false ]; $response = API::userPatch( self::$config['userID'], "items/$childKey", json_encode($json), ["If-Unmodified-Since-Version: " . $childVersion] ); $this->assert204($response); $json = API::getItem($childKey, $this, 'json')['data']; $this->assertArrayNotHasKey('parentItem', $json); }
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); }
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]); }
public function testCollectionItems() { $collectionKey = API::createCollection('Test', false, $this, 'key'); $json = API::createItem("book", ['collections' => [$collectionKey]], $this, 'jsonData'); $itemKey1 = $json['key']; $itemVersion1 = $json['version']; $this->assertEquals([$collectionKey], $json['collections']); $json = API::createItem("journalArticle", ['collections' => [$collectionKey]], $this, 'jsonData'); $itemKey2 = $json['key']; $itemVersion2 = $json['version']; $this->assertEquals([$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?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?format=keys"); $this->assert200($response); $keys = explode("\n", trim($response->getBody())); $this->assertCount(2, $keys); $this->assertContains($itemKey1, $keys); $this->assertContains($itemKey2, $keys); }