Beispiel #1
0
 public function testDeleteCollectionRelation()
 {
     $relations = array("owl:sameAs" => "http://zotero.org/groups/1/collections/AAAAAAAA");
     $data = API::createCollection("Test", array("relations" => $relations), $this, 'jsonData');
     // Remove all relations
     $data['relations'] = new \stdClass();
     unset($relations['owl:sameAs']);
     $response = API::userPut(self::$config['userID'], "collections/{$data['key']}", json_encode($data));
     $this->assert204($response);
     // Make sure it's gone
     $data = API::getCollection($data['key'], $this, 'json')['data'];
     $this->assertCount(sizeOf($relations), $data['relations']);
     foreach ($relations as $predicate => $object) {
         $this->assertEquals($object, $data['relations'][$predicate]);
     }
 }
Beispiel #2
0
 private function _testUploadUnmodified($objectType)
 {
     $objectTypePlural = API::getPluralObjectType($objectType);
     switch ($objectType) {
         case 'collection':
             $data = API::createCollection("Name", false, $this, 'jsonData');
             break;
         case 'item':
             $data = API::createItem("book", array("title" => "Title"), $this, 'jsonData');
             break;
         case 'search':
             $data = API::createSearch("Name", 'default', $this, 'jsonData');
             break;
     }
     $version = $data['version'];
     $this->assertNotEquals(0, $version);
     $response = API::userPut(self::$config['userID'], "{$objectTypePlural}/{$data['key']}", json_encode($data));
     $this->assert204($response);
     $this->assertEquals($version, $response->getHeader("Last-Modified-Version"));
     switch ($objectType) {
         case 'collection':
             $json = API::getCollection($data['key'], $this, 'json');
             break;
         case 'item':
             $json = API::getItem($data['key'], $this, 'json');
             break;
         case 'search':
             $json = API::getSearch($data['key'], $this, 'json');
             break;
     }
     $this->assertEquals($version, $json['version']);
 }
Beispiel #3
0
 public function testCollectionItemChange()
 {
     $collectionKey1 = API::createCollection('Test', false, $this, 'key');
     $collectionKey2 = API::createCollection('Test', false, $this, 'key');
     $json = API::createItem("book", array('collections' => array($collectionKey1)), $this, 'json');
     $itemKey1 = $json['key'];
     $itemVersion1 = $json['version'];
     $this->assertEquals([$collectionKey1], $json['data']['collections']);
     $json = API::createItem("journalArticle", array('collections' => array($collectionKey2)), $this, 'json');
     $itemKey2 = $json['key'];
     $itemVersion2 = $json['version'];
     $this->assertEquals([$collectionKey2], $json['data']['collections']);
     $json = API::getCollection($collectionKey1, $this);
     $this->assertEquals(1, $json['meta']['numItems']);
     $json = API::getCollection($collectionKey2, $this);
     $this->assertEquals(1, $json['meta']['numItems']);
     $collectionData2 = $json['data'];
     $libraryVersion = API::getLibraryVersion();
     // Add items to collection
     $response = API::userPatch(self::$config['userID'], "items/{$itemKey1}", json_encode(array("collections" => array($collectionKey1, $collectionKey2))), array("Content-Type: application/json", "If-Unmodified-Since-Version: {$itemVersion1}"));
     $this->assert204($response);
     // Item version should change
     $json = API::getItem($itemKey1, $this);
     $this->assertEquals($libraryVersion + 1, $json['version']);
     // Collection timestamp shouldn't change, but numItems should
     $json = API::getCollection($collectionKey2, $this);
     $this->assertEquals(2, $json['meta']['numItems']);
     $this->assertEquals($collectionData2['version'], $json['version']);
     $collectionData2 = $json['data'];
     $libraryVersion = API::getLibraryVersion();
     // Remove collections
     $response = API::userPatch(self::$config['userID'], "items/{$itemKey2}", json_encode(array("collections" => array())), array("Content-Type: application/json", "If-Unmodified-Since-Version: {$itemVersion2}"));
     $this->assert204($response);
     // Item version should change
     $json = API::getItem($itemKey2, $this);
     $this->assertEquals($libraryVersion + 1, $json['version']);
     // Collection timestamp shouldn't change, but numItems should
     $json = API::getCollection($collectionKey2, $this);
     $this->assertEquals(1, $json['meta']['numItems']);
     $this->assertEquals($collectionData2['version'], $json['version']);
     // Check collections arrays and numItems
     $json = API::getItem($itemKey1, $this);
     $this->assertCount(2, $json['data']['collections']);
     $this->assertContains($collectionKey1, $json['data']['collections']);
     $this->assertContains($collectionKey2, $json['data']['collections']);
     $json = API::getItem($itemKey2, $this);
     $this->assertCount(0, $json['data']['collections']);
     $json = API::getCollection($collectionKey1, $this);
     $this->assertEquals(1, $json['meta']['numItems']);
     $json = API::getCollection($collectionKey2, $this);
     $this->assertEquals(1, $json['meta']['numItems']);
 }