private function myFileDeleteTest($guid, $collection, $expectedHTTPStatus = "200", $expectedXMLElements, $expectedXMLAttributes) { $url = $this->service_url . "/" . $guid; $curl = curl_init($url); $curl_post_data = array("collection" => $collection, "test" => "test", "test2" => "test2"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // return the result on success curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); // set post fields curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xml")); // set accept header curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); $curl_response = curl_exec($curl); $headers = curl_getinfo($curl); curl_close($curl); // print_r($headers); //echo $curl_response; // validate result if ($curl_response == true) { $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, "200", array("track_to_be_deleted"), array("collection", "id"), $this); MyLog::printWithDuration("Successfully added with the result: " . str_replace("\n", "", $curl_response)); } else { echo __METHOD__ . "\n"; echo "curl_response:" . $curl_response . "\n"; print_r($headers); print_r($curl_post_data); $this->fail("There was a problem accessing the api! \n\n"); } }
public function testSimple() { $config = TestConfig::getConfig(); $service_url = $config['server']['baseurl'] . '/version'; $curl = curl_init($service_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xmlx")); $curl_response = curl_exec($curl); $headers = curl_getinfo($curl); curl_close($curl); $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, "406", array("error"), array("code"), $this); $errorAttributes = array(); foreach ($xml->error[0]->attributes() as $name => $value) { $versionAttributes[$name] = $value; // test if all values are numbers $this->assertType(PHPUnit_Framework_Constraint_IsType::TYPE_NUMERIC, (string) $value, "Type of ErrorCode is wrong."); } }
private function myQueryTest($trackid) { $config = TestConfig::getConfig(); $service_url = $config['server']['baseurl'] . '/track_external_key/'; $curl = curl_init($service_url . $trackid); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xml")); $curl_response = curl_exec($curl); $headers = curl_getinfo($curl); curl_close($curl); if ($curl_response == true) { $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, "404", array("error", "errorDetail"), array("code"), $this); } else { echo __METHOD__ . "\n"; echo "curl_response:" . $curl_response . "\n"; print_r($headers); $this->fail("There was a problem accessing the api! \n\n"); } }
private function myQueryTest($trackextkey, $collectionname = null, $expectedHTTPStatus = "200", $expectedXMLElements, $expectedXMLAttributes) { $config = TestConfig::getConfig(); $service_url = $config['server']['baseurl'] . '/track_external_key/'; $url = $service_url . $trackextkey; if (!is_null($collectionname)) { $url = $url . "?collection=" . urlencode($collectionname); } $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xml")); $curl_response = curl_exec($curl); $headers = curl_getinfo($curl); curl_close($curl); if ($curl_response == true) { $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, $expectedHTTPStatus, $expectedXMLElements, $expectedXMLAttributes, $this); } else { echo __METHOD__ . "\n"; echo "curl_response:" . $curl_response . "\n"; print_r($headers); $this->fail("There was a problem accessing the api! \n\n"); } }
/** * Function to test adding of URLs * * @param string $file_url the URL * @param string $ext_key the external Key; if empty string no ext_key will be set * @param string $collection the collection name; if empty string no collection will be set * @param string $expectedHTTPStatus the statuscode of the expected result * @param string $expectedXMLElements an array containing all expected elements of the returned xml * @param string $expectedXMLAttributes an array containing all expected attributes of the returned xml * @return void * @author jochum */ private function myFileAddTest($file_url, $ext_key, $collection, $expectedHTTPStatus = "200", $expectedXMLElements, $expectedXMLAttributes) { $service_url = $this->config['server']['baseurl'] . '/track/add/'; # build post options $curl_post_data = array(); if (file_exists($file_url)) { # file is local $curl_post_data["file"] = $file_url; } else { # assume it is remote $curl_post_data["url"] = $file_url; } if (is_string($ext_key) && strlen($ext_key) > 0) { $curl_post_data["external_key"] = $ext_key; } if (is_string($collection) && strlen($collection) > 0) { $curl_post_data["collection"] = $collection; } # build curl request $curl = curl_init($service_url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // return the result on success curl_setopt($curl, CURLOPT_POST, true); // set post curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data); // set post fields curl_setopt($curl, CURLOPT_HTTPHEADER, array("Accept: application/xml")); // set accept header $curl_response = curl_exec($curl); $headers = curl_getinfo($curl); curl_close($curl); if ($curl_response == true) { $xml = SmintTestUtils::validateXMLResponse($headers, $curl_response, $expectedHTTPStatus, $expectedXMLElements, $expectedXMLAttributes, $this); MyLog::printWithDuration("Successfully added with the result: " . str_replace("\n", "", $curl_response)); } else { echo __METHOD__ . "\n"; echo "curl_response:" . $curl_response . "\n"; echo "headers:\n"; print_r($headers); echo "curl_post_data:\n"; print_r($curl_post_data); $this->fail("There was a problem accessing the api! \n\n"); } }