Exemplo n.º 1
0
 private function _testObjectKeyParameter($objectType)
 {
     $objectTypePlural = API::getPluralObjectType($objectType);
     $xmlArray = array();
     switch ($objectType) {
         case 'collection':
             $xmlArray[] = API::createCollection("Name", false, $this);
             $xmlArray[] = API::createCollection("Name", false, $this);
             break;
         case 'item':
             $xmlArray[] = API::createItem("book", false, $this);
             $xmlArray[] = API::createItem("book", false, $this);
             break;
         case 'search':
             $xmlArray[] = API::createSearch("Name", array(array("condition" => "title", "operator" => "contains", "value" => "test")), $this);
             $xmlArray[] = API::createSearch("Name", array(array("condition" => "title", "operator" => "contains", "value" => "test")), $this);
             break;
     }
     $keys = array();
     foreach ($xmlArray as $xml) {
         $data = API::parseDataFromAtomEntry($xml);
         $keys[] = $data['key'];
     }
     $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'] . "&content=json&{$objectType}Key={$keys[0]}");
     $this->assert200($response);
     $this->assertNumResults(1, $response);
     $xml = API::getXMLFromResponse($response);
     $data = API::parseDataFromAtomEntry($xml);
     $this->assertEquals($keys[0], $data['key']);
     $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'] . "&content=json&{$objectType}Key={$keys[0]},{$keys[1]}&order={$objectType}KeyList");
     $this->assert200($response);
     $this->assertNumResults(2, $response);
     $xml = API::getXMLFromResponse($response);
     $xpath = $xml->xpath('//atom:entry/zapi:key');
     $key = (string) array_shift($xpath);
     $this->assertEquals($keys[0], $key);
     $key = (string) array_shift($xpath);
     $this->assertEquals($keys[1], $key);
 }
Exemplo n.º 2
0
 public function testNewSearchConditionErrors()
 {
     $json = API::createSearch("Test", array(array("operator" => "contains", "value" => "test")), $this, 'responsejson');
     $this->assert400ForObject($json, "'condition' property not provided for search condition");
     $json = API::createSearch("Test", array(array("condition" => "", "operator" => "contains", "value" => "test")), $this, 'responsejson');
     $this->assert400ForObject($json, "Search condition cannot be empty");
     $json = API::createSearch("Test", array(array("condition" => "title", "value" => "test")), $this, 'responsejson');
     $this->assert400ForObject($json, "'operator' property not provided for search condition");
     $json = API::createSearch("Test", array(array("condition" => "title", "operator" => "", "value" => "test")), $this, 'responsejson');
     $this->assert400ForObject($json, "Search operator cannot be empty");
 }
Exemplo n.º 3
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']);
 }
Exemplo n.º 4
0
 private function _testPartialWriteFailureWithUnchanged($objectType)
 {
     API::userClear(self::$config['userID']);
     $objectTypePlural = API::getPluralObjectType($objectType);
     switch ($objectType) {
         case 'collection':
             $data = API::createCollection("Test", false, $this, 'data');
             $json1 = json_decode($data['content']);
             $json2 = array("name" => str_repeat("1234567890", 6554));
             $json3 = array("name" => "Test");
             break;
         case 'item':
             $data = API::createItem("book", array("title" => "Title"), $this, 'data');
             $json1 = json_decode($data['content']);
             $json2 = API::getItemTemplate('book');
             $json3 = clone $json2;
             $json2->title = str_repeat("1234567890", 6554);
             break;
         case 'search':
             $conditions = array(array('condition' => 'title', 'operator' => 'contains', 'value' => 'value'));
             $data = API::createSearch("Name", $conditions, $this, 'data');
             $json1 = json_decode($data['content']);
             $json2 = array("name" => str_repeat("1234567890", 6554), "conditions" => $conditions);
             $json3 = array("name" => "Test", "conditions" => $conditions);
             break;
     }
     $response = API::userPost(self::$config['userID'], "{$objectTypePlural}?key=" . self::$config['apiKey'], json_encode(array("{$objectTypePlural}" => array($json1, $json2, $json3))), array("Content-Type: application/json"));
     $this->assert200($response);
     $json = API::getJSONFromResponse($response);
     $this->assertUnchangedForObject($response, false, 0);
     $this->assert400ForObject($response, false, 1);
     $this->assert200ForObject($response, false, 2);
     $json = API::getJSONFromResponse($response);
     $response = API::userGet(self::$config['userID'], "{$objectTypePlural}?format=keys&key=" . self::$config['apiKey']);
     $this->assert200($response);
     $keys = explode("\n", trim($response->getBody()));
     $this->assertCount(2, $keys);
     foreach ($json['success'] as $key) {
         $this->assertContains($key, $keys);
     }
 }