Skip to content
Snippets Groups Projects
Commit d2fc5fe3 authored by Hoop, Bert Jan de's avatar Hoop, Bert Jan de
Browse files

L05DOCBST-38 add get_next_ofs method

parent e27d7345
No related branches found
No related tags found
No related merge requests found
...@@ -345,7 +345,7 @@ class Webquery { ...@@ -345,7 +345,7 @@ class Webquery {
/** /**
* return value of the hits element in search response * return value of the hits element in search response
* @return number of hits or false if there is no valid search reponse * @return number of hits or false if there is no valid search response
*/ */
public function get_hits() { public function get_hits() {
...@@ -374,6 +374,26 @@ class Webquery { ...@@ -374,6 +374,26 @@ class Webquery {
} }
/**
* return value of wq_ofs attribute of next element in search response
* @return value of next wq_ofs or false if there is no valid search response
*/
public function get_next_ofs() {
$resp_xml = $this->get_resp_xml();
if (!isset($resp_xml)) {
return false;
}
$next = $resp_xml->xpath("//next");
if (empty($next)) {
return false;
}
$attr = $next[0]->attributes();
return empty($attr['wq_ofs']) ? false : (string) $attr['wq_ofs'];
}
/** /**
* convert xml tree to x-www-form-urlencoded string * convert xml tree to x-www-form-urlencoded string
* @param SimpleXMLElement $xml xml tree * @param SimpleXMLElement $xml xml tree
......
...@@ -143,6 +143,7 @@ EOT; ...@@ -143,6 +143,7 @@ EOT;
$this->assertEquals('', $wq->get_error_message(), '1st: search response error message'); $this->assertEquals('', $wq->get_error_message(), '1st: search response error message');
$this->assertEquals(1, $wq->get_hits(), '1st: search response hits'); $this->assertEquals(1, $wq->get_hits(), '1st: search response hits');
$this->assertTrue($wq->has_next(), '1st: search response has next element'); $this->assertTrue($wq->has_next(), '1st: search response has next element');
$this->assertEquals(1, $wq->get_next_ofs(), '1st: search response next wq_ofs');
// second request fails // second request fails
$wq->set_query('record=nothing'); $wq->set_query('record=nothing');
...@@ -164,6 +165,7 @@ EOT; ...@@ -164,6 +165,7 @@ EOT;
$this->assertEquals('nothing found', $wq->get_error_message(), '2nd: search response error message'); $this->assertEquals('nothing found', $wq->get_error_message(), '2nd: search response error message');
$this->assertEquals(false, $wq->get_hits(), '2nd: search response hits'); $this->assertEquals(false, $wq->get_hits(), '2nd: search response hits');
$this->assertFalse($wq->has_next(), '1st: search response has next element'); $this->assertFalse($wq->has_next(), '1st: search response has next element');
$this->assertEquals(false, $wq->get_next_ofs(), '2nd: search response next wq_ofs');
$this->assertEquals(2, count($request_history), 'request history count'); $this->assertEquals(2, count($request_history), 'request history count');
// check first request // check first request
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment