本文整理汇总了PHP中Zend_Dom_Query::registerXpathNamespaces方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Dom_Query::registerXpathNamespaces方法的具体用法?PHP Zend_Dom_Query::registerXpathNamespaces怎么用?PHP Zend_Dom_Query::registerXpathNamespaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Dom_Query
的用法示例。
在下文中一共展示了Zend_Dom_Query::registerXpathNamespaces方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test11RetrieveConceptFiletrStatus
public function test11RetrieveConceptFiletrStatus()
{
// Use API to search for concept and filter on status
// todo: test additionele zoek parameters
print "\n" . "Test: get concept via filters";
$client = Authenticator::authenticate();
//prepare and send request
$uri = BASE_URI_ . '/public/api/find-concepts?q=prefLabel:' . CONCEPT_prefLabel . '&status:' . CONCEPT_status_forfilter . '&tenant:' . TENANT . '&inScheme:' . CONCEPT_schema_forfilter;
print "\n filtered request's uri: " . $uri . "\n";
$client->setUri($uri);
$client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
$client->SetHeaders(array('Accept' => 'text/html,application/xhtml+xml,application/xml', 'Content-Type' => 'application/xml', 'Accept-Language' => 'nl,en-US,en', 'Accept-Encoding' => 'gzip, deflate', 'Connection' => 'keep-alive'));
$response = $client->request(Zend_Http_Client::GET);
// analyse respond
print "\n get status: " . $response->getMessage() . "\n";
$this->AssertEquals(200, $response->getStatus());
$namespaces = array("rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "skos" => "http://www.w3.org/2004/02/skos/core#", "openskos" => "http://openskos.org/xmlns/openskos.xsd");
$dom = new Zend_Dom_Query();
$dom->setDocumentXML($response->getBody());
$dom->registerXpathNamespaces($namespaces);
$elem = $dom->queryXpath('/rdf:RDF');
$this->assertEquals(XML_ELEMENT_NODE, $elem->current()->nodeType, 'The root node of the response is not an element');
$this->assertEquals(1, $elem->current()->getAttribute("openskos:numFound"));
$resDescr = $dom->queryXpath('/rdf:RDF/rdf:Description');
$i = 0;
$l = $resDescr->count();
$resDescr->rewind();
while ($i < $l) {
$labels = $resDescr->current()->getElementsByTagName("altLabel");
//print "\n val:" . $labels ->item(0) ->textContent;
$randomn = rand(0, 4096);
$labels->item(0)->nodeValue = "test-1-" . $randomn;
$doc = $resDescr->current()->ownerDocument;
$xml = $doc->saveXML();
var_dump($xml);
// try $newdom isntead of $dom, which can be corrupted
//$dom = new DOMDocument('1.0', 'utf-8');
//$rdf = $dom -> createElement("rdf:RDF");
//$dom ->importNode($newDescr, TRUE);// appendChild($rdf);
//$rdf ->appendChild($newDescr);
//$xml = $dom->saveXML();
//var_dump($xml);
$client->setUri(BASE_URI_ . "/public/api/concept?");
$client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
$response = $client->setEncType('text/xml')->setRawData($xml)->setParameterGet('tenant', TENANT)->setParameterGet('collection', COLLECTION_1_code)->setParameterGet('key', API_KEY)->request(Zend_Http_Client::PUT);
print "\n Update response message: " . $response->getMessage();
$this->AssertEquals(200, $response->getStatus(), 'Update request returned worng status code');
$resDescr->next();
$i++;
}
}
示例2: evaluate
/**
* Evaluate an object to see if it fits the constraints
*
* @param string Response content to be matched against (haystack)
* @param null|string Assertion type
* @param string (optional) String to match (needle), may be required depending on assertion type
* @return bool
*
* NOTE:
* Drastic changes up to PHPUnit 3.5.15 this was:
* public function evaluate($other, $assertType = null)
* In PHPUnit 3.6.0 they changed the interface into this:
* public function evaluate($other, $description = '', $returnResult = FALSE)
* We use the new interface for PHP-strict checking, but emulate the old one
*/
public function evaluate($content, $assertType = '', $match = FALSE)
{
if (strstr($assertType, 'Not')) {
$this->setNegate(true);
$assertType = str_replace('Not', '', $assertType);
}
if (strstr($assertType, 'Xpath')) {
$this->setUseXpath(true);
$assertType = str_replace('Xpath', 'Query', $assertType);
}
if (!in_array($assertType, $this->_assertTypes)) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception(sprintf('Invalid assertion type "%s" provided to %s constraint', $assertType, __CLASS__));
}
$this->_assertType = $assertType;
$method = $this->_useXpath ? 'queryXpath' : 'query';
$domQuery = new Zend_Dom_Query($content);
$domQuery->registerXpathNamespaces($this->_xpathNamespaces);
$result = $domQuery->{$method}($this->_path);
switch ($assertType) {
case self::ASSERT_CONTENT_CONTAINS:
if (!$match) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No content provided against which to match');
}
$this->_content = $match;
return $this->_negate ? $this->_notMatchContent($result, $match) : $this->_matchContent($result, $match);
case self::ASSERT_CONTENT_REGEX:
if (!$match) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No pattern provided against which to match');
}
$this->_content = $match;
return $this->_negate ? $this->_notRegexContent($result, $match) : $this->_regexContent($result, $match);
case self::ASSERT_CONTENT_COUNT:
case self::ASSERT_CONTENT_COUNT_MIN:
case self::ASSERT_CONTENT_COUNT_MAX:
if ($match === false) {
require_once 'Zend/Test/PHPUnit/Constraint/Exception.php';
throw new Zend_Test_PHPUnit_Constraint_Exception('No count provided against which to compare');
}
$this->_content = $match;
return $this->_countContent($result, $match, $assertType);
case self::ASSERT_QUERY:
default:
if ($this->_negate) {
return 0 == count($result);
} else {
return 0 != count($result);
}
}
}
示例3: evaluate
/**
* Evaluate an object to see if it fits the constraints
*
* @param mixed $other String to examine
* @param string $description
* @param bool $returnResult
*
* @return bool|mixed
*/
public function evaluate($other, $description = '', $returnResult = false)
{
$method = $this->_useXpath ? 'queryXpath' : 'query';
$domQuery = new Zend_Dom_Query($other);
$domQuery->registerXpathNamespaces($this->_xpathNamespaces);
$result = $domQuery->{$method}($this->_path);
switch ($this->_assertType) {
case self::ASSERT_CONTENT_CONTAINS:
return $this->_negate ? $this->_notMatchContent($result, $this->_content) : $this->_matchContent($result, $this->_content);
case self::ASSERT_CONTENT_REGEX:
return $this->_negate ? $this->_notRegexContent($result, $this->_content) : $this->_regexContent($result, $this->_content);
case self::ASSERT_CONTENT_COUNT:
case self::ASSERT_CONTENT_COUNT_MIN:
case self::ASSERT_CONTENT_COUNT_MAX:
return $this->_countContent($result, $this->_content, $this->_assertType);
case self::ASSERT_QUERY:
default:
if ($this->_negate) {
return 0 == count($result);
} else {
return 0 != count($result);
}
}
}
示例4: testImport
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));
}
示例5: getAbout
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;
}
示例6: assertionsForXMLRDFConcept
private function assertionsForXMLRDFConcept($response, $prefLabel, $altLabel, $hiddenLabel, $lang, $definition, $notation, $topConceptOf, $inScheme)
{
$dom = new Zend_Dom_Query();
$namespaces = RequestResponse::setNamespaces();
$dom->registerXpathNamespaces($namespaces);
$xml = $response->getBody();
$dom->setDocumentXML($xml);
$results1 = $dom->queryXpath('/rdf:RDF/rdf:Description');
$this->AssertEquals(1, count($results1));
$this->AssertStringStartsWith(BASE_URI_ . "/" . OPENSKOS_SET_code, $results1->current()->getAttribute('rdf:about'));
$results2 = $dom->query('rdf:type');
$this->AssertEquals(CONCEPT_type, $results2->current()->getAttribute('rdf:resource'));
$results3 = $dom->query('skos:notation');
$this->AssertEquals($notation, $results3->current()->nodeValue);
$results4 = $dom->query('skos:inScheme');
$this->AssertEquals($inScheme, count($results4));
$results5 = $dom->query('skos:topConceptOf');
$this->AssertEquals($topConceptOf, count($results5));
$results6 = $dom->query('skos:prefLabel');
$this->AssertEquals($lang, $results6->current()->getAttribute('xml:lang'));
$this->AssertEquals($prefLabel, $results6->current()->nodeValue);
$results6a = $dom->query('skos:altLabel');
$this->AssertEquals($lang, $results6a->current()->getAttribute('xml:lang'));
$this->AssertEquals($altLabel, $results6a->current()->nodeValue);
$results6b = $dom->query('skos:hiddenLabel');
$this->AssertEquals($lang, $results6b->current()->getAttribute('xml:lang'));
$this->AssertEquals($hiddenLabel, $results6b->current()->nodeValue);
$results7 = $dom->query('skos:definition');
$this->AssertEquals($definition, $results7->current()->nodeValue);
$results9 = $dom->query('dcterms:creator');
$this->AssertStringStartsWith(BASE_URI_, $results9->current()->getAttribute('rdf:resource'));
$results8 = $dom->query('openskos:set');
$this->AssertEquals(OPENSKOS_SET_code, $results8->current()->nodeValue);
}
示例7: test11RetrieveConceptFiletrStatus
public function test11RetrieveConceptFiletrStatus()
{
// Use API to search for concept and filter on status
// todo: test additionele zoek parameters
print "\n" . "Test: get concept via filters";
$client = Authenticator::authenticate();
//prepare and send request
$uri = BASE_URI_ . '/public/api/find-concepts?q=prefLabel:' . CONCEPT_prefLabel . '&status:' . CONCEPT_status_forfilter . '&tenant:' . TENANT . '&inScheme:' . CONCEPT_schema_forfilter;
print "\n fileterd request's uri: " . $uri;
$client->setUri($uri);
$client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
$client->SetHeaders(array('Accept' => 'text/html,application/xhtml+xml,application/xml', 'Content-Type' => 'application/xml', 'Accept-Language' => 'nl,en-US,en', 'Accept-Encoding' => 'gzip, deflate', 'Connection' => 'keep-alive'));
$response = $client->request(Zend_Http_Client::GET);
// analyse respond
if ($response->getStatus() != 200) {
print "\n " . $response->getMessage();
}
print "\n Response Headers: ";
var_dump($response->getHeaders());
$this->AssertEquals(200, $response->getStatus());
$namespaces = array("rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "skos" => "http://www.w3.org/2004/02/skos/core#", "openskos" => "http://openskos.org/xmlns/openskos.xsd");
print "\n\n\n Response Body: ";
var_dump($response->getBody());
$dom = new Zend_Dom_Query();
$dom->setDocumentXML($response->getBody());
$dom->registerXpathNamespaces($namespaces);
$elem = $dom->queryXpath('/rdf:RDF');
$this->assertEquals($elem->current()->nodeType, XML_ELEMENT_NODE, 'The root node of the response is not an element');
$resDescr = $dom->queryXpath('/rdf:RDF/rdf:Description');
$resStatus = $dom->queryXpath('/rdf:RDF/rdf:Description/openskos:status');
$this->assertEquals(1, $resDescr->count());
$this->assertEquals($resDescr->count(), $resStatus->count(), "Not all result concepts have status field. ");
}
示例8: test07CreateConceptWithoutUri
public function test07CreateConceptWithoutUri()
{
// Create a concept without Uri and with unique PrefLabel.
print "\n\n test07 ... \n";
$client = Authenticator::authenticate();
$randomn = rand(0, 4092);
$prefLabel = 'testPrefLable_' . $randomn;
$dateSubmitted = date(DateTime::ISO8601);
$xml = '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:dcterms="http://purl.org/dc/terms/" > ' . '<rdf:Description>' . '<rdf:type rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>' . '<dcterms:creator>Test</dcterms:creator>' . '<skos:prefLabel xml:lang="nl">' . $prefLabel . '</skos:prefLabel>' . '<dcterms:dateSubmitted>' . $dateSubmitted . '</dcterms:dateSubmitted>' . '<skos:inScheme rdf:resource="http://data.beeldengeluid.nl/gtaa/GeografischeNamen"/>' . '</rdf:Description>' . '</rdf:RDF>';
$client->setUri(BASE_URI_ . "/public/api/concept?");
$client->setConfig(array('maxredirects' => 0, 'timeout' => 30));
$response = $client->setEncType('text/xml')->setRawData($xml)->setParameterGet('tenant', TENANT)->setParameterGet('collection', COLLECTION_1_code)->setParameterGet('key', API_KEY)->setParameterGet('autoGenerateIdentifiers', 'true')->request('POST');
if ($response->isSuccessful()) {
print "\n Concept created \n";
var_dump($response->getBody());
} else {
print "\n Failed to create concept: " . $response->getHeader('X-Error-Msg');
}
$this->AssertEquals(201, $response->getStatus());
print "\n HTTPResponseHeader-Location: " . $response->getHeader('Location');
$namespaces = array("rdf" => "http://www.w3.org/1999/02/22-rdf-syntax-ns#", "skos" => "http://www.w3.org/2004/02/skos/core#", "openskos" => "http://openskos.org/xmlns/openskos.xsd");
$dom = new Zend_Dom_Query();
$dom->setDocumentXML($response->getBody());
$dom->registerXpathNamespaces($namespaces);
$elem = $dom->queryXpath('/rdf:RDF');
$this->assertEquals($elem->current()->nodeType, XML_ELEMENT_NODE, 'The root node of the response is not an element');
$resURI = $dom->queryXpath('/rdf:RDF/rdf:Description')->current()->getAttribute("rdf:about");
$this->assertNotEquals("", $resURI, "No valid uri for SKOS concept");
$status = $dom->queryXpath('/rdf:RDF/rdf:Description/openskos:status');
$this->assertEquals(1, $status->count(), "No valid uri for SKOS concept");
print "\n New concept is created with URI {$resURI} and status" . $status->current()->nodeValue;
}