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 testGroupTagAddItemChange() { $key = 'AAAAAAAA'; $groupID = self::$config['ownedPrivateGroupID']; $libraryID = self::$config['ownedPrivateGroupLibraryID']; $sessionID2 = Sync::login(array('username' => self::$config['username2'], 'password' => self::$config['password2'])); $xml = Sync::updated($sessionID2); $updateKey = (string) $xml['updateKey']; // Create item via sync $data = '<data version="9"><items><item libraryID="' . $libraryID . '" ' . 'itemType="book" ' . 'dateAdded="2009-03-07 04:53:20" ' . 'dateModified="2009-03-07 04:54:09" ' . 'key="' . $key . '"/></items></data>'; $response = Sync::upload($sessionID2, $updateKey, $data); Sync::waitForUpload($sessionID2, $response, $this); // Get item version via API $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=json"); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $version = $data['version']; // Verify createdByUserID and lastModifiedByUserID $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=none"); $xml = API::getXMLFromResponse($response); $xml->registerXPathNamespace('zxfer', 'http://zotero.org/ns/transfer'); $createdByUser = (string) array_shift($xml->xpath('//atom:entry/atom:author/atom:name')); $lastModifiedByUser = (string) array_shift($xml->xpath('//atom:entry/zapi:lastModifiedByUser')); $this->assertEquals(self::$config['username2'], $createdByUser); $this->assertEquals(self::$config['username2'], $lastModifiedByUser); // Get item via sync $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; $this->assertEquals(1, sizeOf($xml->updated->items->item)); // Add tag to item via sync $data = '<data version="9"><tags><tag libraryID="' . $libraryID . '" ' . 'name="Test" ' . 'dateAdded="2009-03-07 04:54:56" ' . 'dateModified="2009-03-07 04:54:56" ' . 'key="BBBBBBBB">' . '<items>' . $key . '</items>' . '</tag></tags></data>'; $response = Sync::upload(self::$sessionID, $updateKey, $data); Sync::waitForUpload(self::$sessionID, $response, $this); // Get item via API $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=json"); $xml = API::getXMLFromResponse($response); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content']); $this->assertCount(1, $json->tags); $this->assertTrue(isset($json->tags[0]->tag)); $this->assertEquals("Test", $json->tags[0]->tag); $this->assertGreaterThan($version, $data['version']); // Verify createdByUserID and lastModifiedByUserID $response = API::groupGet($groupID, "items/{$key}?key=" . self::$config['apiKey'] . "&content=none"); $xml = API::getXMLFromResponse($response); $xml->registerXPathNamespace('zxfer', 'http://zotero.org/ns/transfer'); $createdByUser = (string) array_shift($xml->xpath('//atom:entry/atom:author/atom:name')); $lastModifiedByUser = (string) array_shift($xml->xpath('//atom:entry/zapi:lastModifiedByUser')); $this->assertEquals(self::$config['username2'], $createdByUser); $this->assertEquals(self::$config['username'], $lastModifiedByUser); }
public function testFullTextNoAccess() { API::groupClear(self::$config['ownedPrivateGroupID2']); // Add item to group as user 2 $user2SessionID = Sync::login(['username' => self::$config['username2'], 'password' => self::$config['password2']]); $xml = Sync::updated($user2SessionID); $updateKey = (string) $xml['updateKey']; $key = Zotero_Utilities::randomString(8, 'key', true); $dateAdded = date('Y-m-d H:i:s', time() - 1); $dateModified = date('Y-m-d H:i:s'); $xmlstr = '<data version="9">' . '<items>' . '<item libraryID="' . self::$config['ownedPrivateGroupLibraryID2'] . '" ' . 'itemType="attachment" ' . 'dateAdded="' . $dateAdded . '" ' . 'dateModified="' . $dateModified . '" ' . 'key="' . $key . '"/>' . '</items>' . '</data>'; $response = Sync::upload($user2SessionID, $updateKey, $xmlstr); Sync::waitForUpload($user2SessionID, $response, $this); // Make sure item exists $xml = Sync::updated($user2SessionID, 1); $this->assertEquals(1, $xml->updated[0]->items->count()); $this->assertEquals(1, $xml->updated[0]->items[0]->item->count()); // Try to add full-text content as user 1 $xml = Sync::updated(self::$sessionID); $updateKey = (string) $xml['updateKey']; $content = "This is some full-text content."; $totalChars = 2500; $xmlstr = '<data version="9">' . '<fulltexts>' . '<fulltext libraryID="' . self::$config['ownedPrivateGroupLibraryID2'] . '" ' . 'key="' . $key . '" ' . 'indexedChars="' . strlen($content) . '" ' . 'totalChars="' . $totalChars . '" ' . 'indexedPages="0" ' . 'totalPages="0">' . htmlspecialchars($content) . '</fulltext>' . '</fulltexts>' . '</data>'; $response = Sync::upload(self::$sessionID, $updateKey, $xmlstr); Sync::waitForUpload(self::$sessionID, $response, $this); // Retrieve it as user 2 $xml = Sync::updated($user2SessionID, 1, false, false, ["ft" => 1]); $this->assertEquals(0, $xml->updated[0]->fulltexts->count()); API::groupClear(self::$config['ownedPrivateGroupID2']); }
public function setUp() { API::userClear(self::$config['userID']); self::$sessionID = Sync::login(); }