Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
php-modules
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
library
php-modules
Commits
5b4ce5c3
Commit
5b4ce5c3
authored
6 years ago
by
Hoop, Bert Jan de
Browse files
Options
Downloads
Patches
Plain Diff
L05DOCBST-38 add get_hits method
parent
039c07e0
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/library/Webquery.php
+16
-0
16 additions, 0 deletions
src/library/Webquery.php
tests/library/WebqueryTest.php
+2
-0
2 additions, 0 deletions
tests/library/WebqueryTest.php
with
18 additions
and
0 deletions
src/library/Webquery.php
+
16
−
0
View file @
5b4ce5c3
...
@@ -343,6 +343,22 @@ class Webquery {
...
@@ -343,6 +343,22 @@ class Webquery {
}
}
/**
* return value of the hits element in search response
* @return number of hits or false if there is no valid search reponse
*/
public
function
get_hits
()
{
$resp_xml
=
$this
->
get_resp_xml
();
if
(
!
isset
(
$resp_xml
))
{
return
false
;
}
$hits
=
$resp_xml
->
xpath
(
"//hits"
);
return
empty
(
$hits
)
?
false
:
(
string
)
$hits
[
0
];
}
/**
/**
* @return boolean true if response contains next element
* @return boolean true if response contains next element
*/
*/
...
...
This diff is collapsed.
Click to expand it.
tests/library/WebqueryTest.php
+
2
−
0
View file @
5b4ce5c3
...
@@ -140,6 +140,7 @@ EOT;
...
@@ -140,6 +140,7 @@ EOT;
$this
->
assertEquals
(
$expect
,
$records
,
'1st: search response records'
);
$this
->
assertEquals
(
$expect
,
$records
,
'1st: search response records'
);
$this
->
assertEquals
(
''
,
$wq
->
get_error_code
(),
'1st: search response error code'
);
$this
->
assertEquals
(
''
,
$wq
->
get_error_code
(),
'1st: search response error code'
);
$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'
);
// second request fails
// second request fails
$wq
->
set_query
(
'record=nothing'
);
$wq
->
set_query
(
'record=nothing'
);
...
@@ -160,6 +161,7 @@ EOT;
...
@@ -160,6 +161,7 @@ EOT;
$this
->
assertEquals
(
$expect
,
$records
,
'2nd: search response records'
);
$this
->
assertEquals
(
$expect
,
$records
,
'2nd: search response records'
);
$this
->
assertEquals
(
'WQW_NO_HITS'
,
$wq
->
get_error_code
(),
'2nd: search response error code'
);
$this
->
assertEquals
(
'WQW_NO_HITS'
,
$wq
->
get_error_code
(),
'2nd: search response error code'
);
$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
(
2
,
count
(
$request_history
),
'request history count'
);
$this
->
assertEquals
(
2
,
count
(
$request_history
),
'request history count'
);
// check first request
// check first request
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment