Ejemplo n.º 1
0
 private function _testAPINewerTimestamp($objectType)
 {
     $objectTypePlural = API::getPluralObjectType($objectType);
     $xml = Sync::updated(self::$sessionID);
     $lastSyncTimestamp = $xml['timestamp'];
     // Create via sync
     switch ($objectType) {
         case 'collection':
             $keys[] = Sync::createCollection(self::$sessionID, self::$config['libraryID'], "Test", false, $this);
             break;
         case 'item':
             $keys[] = Sync::createItem(self::$sessionID, self::$config['libraryID'], "book", false, $this);
             break;
         case 'search':
             $keys[] = Sync::createSearch(self::$sessionID, self::$config['libraryID'], "Test", 'default', $this);
             break;
     }
     $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'] . "&newertime={$lastSyncTimestamp}&format=keys");
     $this->assertEquals(200, $response->getStatus());
     $responseKeys = explode("\n", trim($response->getBody()));
     $this->assertCount(sizeOf($keys), $responseKeys);
     foreach ($keys as $key) {
         $this->assertContains($key, $responseKeys);
     }
     // Should be empty with later timestamp
     $xml = Sync::updated(self::$sessionID);
     $lastSyncTimestamp = $xml['timestamp'];
     $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'] . "&newertime=" . ($lastSyncTimestamp + 2) . "&format=keys");
     $this->assertEquals(200, $response->getStatus());
     $this->assertEquals("", trim($response->getBody()));
 }
Ejemplo n.º 2
0
 public function testCollectionItemUpdate()
 {
     $collectionKey = Sync::createCollection(self::$sessionID, self::$config['libraryID'], "Test", null, $this);
     $itemKey = Sync::createItem(self::$sessionID, self::$config['libraryID'], "book", null, $this);
     $xml = Sync::updated(self::$sessionID);
     $updateKey = (string) $xml['updateKey'];
     // Get the item version
     $itemXML = API::getItemXML($itemKey);
     $data = API::parseDataFromAtomEntry($itemXML);
     $json = json_decode($data['content'], true);
     $itemVersion = $json['itemVersion'];
     $this->assertNotNull($itemVersion);
     // Add via sync
     $collectionXML = $xml->updated[0]->collections[0]->collection[0];
     $collectionXML['libraryID'] = self::$config['libraryID'];
     $collectionXML->addChild("items", $itemKey);
     $data = '<data version="9"><collections>' . $collectionXML->asXML() . '</collections>' . '</data>';
     $response = Sync::upload(self::$sessionID, $updateKey, $data, true);
     Sync::waitForUpload(self::$sessionID, $response, $this);
     // Make sure item was updated
     $itemXML = API::getItemXML($itemKey);
     $data = API::parseDataFromAtomEntry($itemXML);
     $json = json_decode($data['content'], true);
     $this->assertGreaterThan($itemVersion, $json['itemVersion']);
     $itemVersion = $json['itemVersion'];
     $this->assertCount(1, $json['collections']);
     $this->assertContains($collectionKey, $json['collections']);
     // Remove via sync
     $xml = Sync::updated(self::$sessionID);
     $updateKey = (string) $xml['updateKey'];
     $collectionXML = $xml->updated[0]->collections[0]->collection[0];
     $collectionXML['libraryID'] = self::$config['libraryID'];
     unset($collectionXML->items);
     $data = '<data version="9"><collections>' . $collectionXML->asXML() . '</collections>' . '</data>';
     $response = Sync::upload(self::$sessionID, $updateKey, $data, true);
     Sync::waitForUpload(self::$sessionID, $response, $this);
     // Make sure item was removed
     $itemXML = API::getItemXML($itemKey);
     $data = API::parseDataFromAtomEntry($itemXML);
     $json = json_decode($data['content'], true);
     $this->assertGreaterThan($itemVersion, $json['itemVersion']);
     $this->assertCount(0, $json['collections']);
 }