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 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 testParentItemPatch() { $xml = API::createItem("book", false, $this); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $parentKey = $data['key']; $parentVersion = $data['version']; $xml = API::createAttachmentItem("linked_url", [], $parentKey, $this); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $childKey = $data['key']; $childVersion = $data['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}?key=" . self::$config['apiKey'], json_encode($json), array("If-Unmodified-Since-Version: " . $childVersion)); $this->assert204($response); $xml = API::getItemXML($childKey); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $this->assertArrayHasKey('parentItem', $json); }
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 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); }