public function testExport() { if (self::$response0->getStatus() == 201) { self::$client->resetParameters(); //self::$client->setUri(BASE_URI_ . '/public/api/find-concepts?q=prefLabel:' . self::$prefLabel); //$response = self::$client->request(Zend_Http_Client::GET); //!!! it used to be self::$uuid!!! $response = RequestResponse::ExportRequest(self::$client, self::$about, dirname(__DIR__) . '/OpenSkos2/ExportTest.xml'); if ($response->getStatus() != 200) { Logging::failureMessaging($response, "export concept"); } $this->AssertEquals(200, $response->getStatus()); var_dump($response->GetBody()); $this->assertions($response); } else { Logging::failureMessaging(self::$response0, "create test concept"); } }
public function testDeleteApproved() { print "\n deleting concept with approved status ..."; if (self::$response0->getStatus() === 201) { $response = RequestResponse::DeleteRequest(self::$client, self::$about); self::$client->setUri(BASE_URI_ . '/public/api/concept?id=' . self::$uuid); $responseCheck = self::$client->request('GET'); if ($responseCheck->getStatus() === 410) { print "\n Approved concept has been marked as deleted! \n"; } $this->AssertEquals(410, $responseCheck->getStatus()); if ($response->getStatus() !== 202) { print "\n delete return status " . $response->getStatus(); print "\n with the message " . $response->getMessage(); } $this->AssertEquals(202, $response->getStatus()); } }
private function assertionsHTMLAllInstitutions($response) { $dom = new Zend_Dom_Query(); $dom->setDocumentHTML($response->getBody()); $institutions = $dom->query('ul > li > a > strong'); // fetches institutions and formats together $this->AssertEquals(NUMBER_INSTITUTIONS, count($institutions)); for ($i = 0; $i < NUMBER_INSTITUTIONS; $i++) { $title = RequestResponse::getByIndex($institutions, $i)->nodeValue; if ($i === 0) { $this->AssertEquals(INSTITUTION_NAME, $title); } else { $this->AssertEquals(1, 0); } } $list = $dom->query('ul > li > a'); // fetches institutions and formats together $this->AssertEquals(3, count($list) - NUMBER_INSTITUTIONS); }
public function testImport() { print "\n" . "Testing import ... "; $response = RequestResponse::ImportConceptRequest(self::$client, self::$postData, self::$boundaryNumeric); Logging::var_error_log("\n Response body ", $response->getBody(), __DIR__ . "/ImportResponse.html"); $this->AssertEquals(200, $response->getStatus(), 'Failed to import concept'); $output = array('0' => "The ouput of sending jobs: "); $retvar = 0; $sendjob = exec(PHP_JOBS_PROCESS, $output, $retvar); // check via spraql query //$sparqlResult = $this ->sparqlRetrieveTriplesForNotation(self::$notation); //var_dump($sparqlResult); self::$client->setUri(BASE_URI_ . '/public/api/find-concepts?q=prefLabel:' . self::$prefLabel); $responseGet = self::$client->request(Zend_Http_Client::GET); $this->AssertEquals(200, $responseGet->getStatus(), $responseGet->getMessage()); $dom = new Zend_Dom_Query(); $namespaces = RequestResponse::setNamespaces(); $dom->registerXpathNamespaces($namespaces); $xml = $responseGet->getBody(); $dom->setDocumentXML($xml); var_dump($xml); $results1 = $dom->query('rdf:RDF'); $this->AssertEquals(1, $results1->current()->getAttribute('openskos:numFound')); $results2 = $dom->queryXpath('/rdf:RDF/rdf:Description'); $this->AssertEquals(1, count($results2)); }
public static function deleteConcepts($abouts, $client) { foreach ($abouts as $about) { if ($about != null) { $response = RequestResponse::DeleteRequest($client, $about); if ($response->getStatus() !== 202 && $response->getStatus() !== 200) { Logging::failureMessaging($response, 'deleting test concept ' . $about); } } } }
/** * @param array $opt * @param array $optCustom * * @return RequestResponse * @throws RequestException */ private function process(array $opt, array $optCustom = array()) { $curl = curl_init(); // add options to retrieve header $opt[CURLOPT_HEADER] = 1; // merge options foreach ($optCustom as $key => $val) { $opt[$key] = $optCustom[$key]; } curl_setopt_array($curl, $opt); // run request $response = curl_exec($curl); // parse header $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); $header = $this->parseHttpHeaders(substr($response, 0, $header_size)); // parse body $body = substr($response, $header_size); // cache error if any occurs $error = curl_error($curl); // cache http code $httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); // url on which we eventually might have ended up (301 redirects) $lastUrl = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); curl_close($curl); // throw if request failed if ($response === false) { throw new RequestException($error); } // -------------------------------------- $response = new RequestResponse(); return $response->setHttpCode($httpCode)->setHeader($header)->setBody($body)->setLastUrl($lastUrl); }
private function getAbout($response) { $dom = new Zend_Dom_Query(); $namespaces = RequestResponse::setNamespaces(); $dom->setDocumentXML($response->getBody()); $dom->registerXpathNamespaces($namespaces); $description = $dom->queryXpath('/rdf:RDF/rdf:Description'); $this->assertEquals(1, $description->count(), "rdf:Description element is not declared"); $resURI = $description->current()->getAttribute("rdf:about"); $this->assertNotEquals("", $resURI, "No valid uri for SKOS concept"); return $resURI; }
public function testCreateRelationWithParametersInRequest() { print "\n" . "Test: create relation X has narrower Y with parameter requests "; $this->AssertEquals(201, self::$responseX->getStatus(), "\n Cannot perform the test because something is wrong with creating a test concept X: " . self::$responseX->getHeader('X-Error-Msg')); $this->AssertEquals(201, self::$responseY->getStatus(), "\n Cannot perform the test because something is wrong with creating a test concept Y: " . self::$responseY->getHeader('X-Error-Msg')); $response = RequestResponse::CreateRelationViaParametersRequest(self::$client, self::$aboutX, "http://www.w3.org/2004/02/skos/core#narrower", self::$aboutY); $this->AssertEquals(200, $response->getStatus(), $response->getHeader('X-Error-Msg')); // todo: add assertions }
private function assertionsForHTMLConcept($response, $prefLabel, $altLabel, $hiddenLabel, $lang, $definition, $notation, $topConceptOf, $inScheme) { $dom = new Zend_Dom_Query(); $dom->setDocumentHtml($response->getBody()); //does not work because of . : $results1 = $dom->query('dl > dd > a[href="http://hdl.handle.net/11148/CCR_C-4046_944cc750-1c29-ccf0-fb68-4d00385d7b42"]'); $resultsUri1 = $dom->query('dl > dt'); $propertyName = RequestResponse::getByIndex($resultsUri1, 2)->nodeValue; $this->AssertEquals("SKOS Class:", $propertyName); $resultsUri2 = $dom->query('dl > dd > a'); $property = RequestResponse::getByIndex($resultsUri2, 2); $this->AssertEquals("http://www.w3.org/2004/02/skos/core#Concept", $property->nodeValue); $this->AssertEquals("http://www.w3.org/2004/02/skos/core#Concept", $property->getAttribute('href')); $h3s = $dom->query('h3'); $inSchemeName = RequestResponse::getByIndex($h3s, 0)->nodeValue; $this->AssertEquals("inScheme", $inSchemeName); $lexLabels = RequestResponse::getByIndex($h3s, 2)->nodeValue; $this->AssertEquals("LexicalLabels", $lexLabels); $h4s = $dom->query('h4'); $altLabelName = RequestResponse::getByIndex($h4s, 2)->nodeValue; $this->AssertEquals("skos:http://www.w3.org/2004/02/skos/core#altLabel", $altLabelName); $prefLabelName = RequestResponse::getByIndex($h4s, 4)->nodeValue; $this->AssertEquals("skos:http://www.w3.org/2004/02/skos/core#prefLabel", $prefLabelName); $notationName = RequestResponse::getByIndex($h4s, 5)->nodeValue; $this->AssertEquals("skos:http://www.w3.org/2004/02/skos/core#notation", $notationName); $list = $dom->query('ul > li > a > span'); $prefLabelVal = RequestResponse::getByIndex($list, 4)->nodeValue; $this->AssertEquals($prefLabel, $prefLabelVal); }
public function testAutocompleteFormatHTML() { print "\n testAutocomplete search pref Label"; if (self::$success) { $word = self::$labelMap[PREF_LABEL] . self::$prefs[1]; // prefLabel<someuuid>a. $response = RequestResponse::AutocomleteRequest(self::$client, $word, "?format=html"); if ($response->getStatus() != 200) { Logging::failureMessaging($response, 'autocomplete on word ' . $word . "?format=html"); } $this->AssertEquals(200, $response->getStatus()); // todo: add some chek when it becomes clear how the output looks like } else { print "\n Cannot perform the test because something is wrong with creating test concepts, see above. \n "; } }
private function assertionsHTMLCollection(Zend_Dom_Query $dom, $i) { $institution = $dom->query('dl > dd > a'); $schemata = $dom->query('ul > li > a'); // also grabs 3 items for formats if ($i == 0) { $this->AssertEquals(NUMBER_INSTITUTIONS, count($institution)); $title = RequestResponse::getByIndex($institution, 0)->nodeValue; $this->AssertEquals(INSTITUTION_NAME, $title); $this->AssertEquals(NUMBER_SCHEMATA, count($schemata) - 3); } }