public function testNewEmptyBookItemMultiple() { $json = API::getItemTemplate("book"); $data = array(); $json->title = "A"; $data[] = $json; $json2 = clone $json; $json2->title = "B"; $data[] = $json2; $json3 = clone $json; $json3->title = "C"; $data[] = $json3; $response = API::postItems($data); $this->assert200($response); $json = API::getJSONFromResponse($response); $xml = API::getItemXML($json['success'], $this); $contents = $xml->xpath('/atom:feed/atom:entry/atom:content'); $content = json_decode(array_shift($contents)); $this->assertEquals("A", $content->title); $content = json_decode(array_shift($contents)); $this->assertEquals("B", $content->title); $content = json_decode(array_shift($contents)); $this->assertEquals("C", $content->title); }
public function testRelatedItemRelationsSingleRequest() { $uriPrefix = "http://zotero.org/users/" . self::$config['userID'] . "/items/"; // TEMP: Use autoloader require_once '../../model/Utilities.inc.php'; require_once '../../model/ID.inc.php'; $item1Key = \Zotero_ID::getKey(); $item2Key = \Zotero_ID::getKey(); $item1URI = $uriPrefix . $item1Key; $item2URI = $uriPrefix . $item2Key; $item1JSON = API::getItemTemplate('book'); $item1JSON->itemKey = $item1Key; $item1JSON->itemVersion = 0; $item1JSON->relations->{'dc:relation'} = $item2URI; $item2JSON = API::getItemTemplate('book'); $item2JSON->itemKey = $item2Key; $item2JSON->itemVersion = 0; $response = API::postItems([$item1JSON, $item2JSON]); $this->assert200($response); $json = API::getJSONFromResponse($response); // Make sure it exists on item 1 $xml = API::getItemXML($item1JSON->itemKey); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $this->assertCount(1, $json['relations']); $this->assertEquals($item2URI, $json['relations']['dc:relation']); // And item 2, since related items are bidirectional $xml = API::getItemXML($item2JSON->itemKey); $data = API::parseDataFromAtomEntry($xml); $json = json_decode($data['content'], true); $this->assertCount(1, $json['relations']); $this->assertEquals($item1URI, $json['relations']['dc:relation']); }