Exemplo n.º 1
0
 /**
  * @depends testNewSearch
  */
 public function testModifySearch($newSearchData)
 {
     $key = $newSearchData['key'];
     $version = $newSearchData['version'];
     $json = json_decode($newSearchData['content'], true);
     // Remove one search condition
     array_shift($json['conditions']);
     $name = $json['name'];
     $conditions = $json['conditions'];
     $response = API::userPut(self::$config['userID'], "searches/{$key}?key=" . self::$config['apiKey'], json_encode($json), array("Content-Type: application/json", "If-Unmodified-Since-Version: {$version}"));
     $this->assert204($response);
     $xml = API::getSearchXML($key);
     $data = API::parseDataFromAtomEntry($xml);
     $json = json_decode($data['content']);
     $this->assertEquals($name, (string) $json->name);
     $this->assertInternalType('array', $json->conditions);
     $this->assertCount(sizeOf($conditions), $json->conditions);
     foreach ($conditions as $i => $condition) {
         foreach ($condition as $key => $val) {
             $this->assertEquals($val, $json->conditions[$i]->{$key});
         }
     }
 }
Exemplo n.º 2
0
 private function _testUploadUnmodified($objectType)
 {
     $objectTypePlural = API::getPluralObjectType($objectType);
     switch ($objectType) {
         case 'collection':
             $xml = API::createCollection("Name", false, $this);
             break;
         case 'item':
             $xml = API::createItem("book", array("title" => "Title"), $this);
             break;
         case 'search':
             $xml = API::createSearch("Name", 'default', $this);
             break;
     }
     $version = (int) array_shift($xml->xpath('//atom:entry/zapi:version'));
     $this->assertNotEquals(0, $version);
     $data = API::parseDataFromAtomEntry($xml);
     $json = json_decode($data['content']);
     $response = API::userPut(self::$config['userID'], "{$objectTypePlural}/{$data['key']}?key=" . self::$config['apiKey'], json_encode($json));
     $this->assert204($response);
     $this->assertEquals($version, $response->getHeader("Last-Modified-Version"));
     switch ($objectType) {
         case 'collection':
             $xml = API::getCollectionXML($data['key']);
             break;
         case 'item':
             $xml = API::getItemXML($data['key']);
             break;
         case 'search':
             $xml = API::getSearchXML($data['key']);
             break;
     }
     $data = API::parseDataFromAtomEntry($xml);
     $this->assertEquals($version, $data['version']);
 }