Skip to content

Commit

Permalink
III-291: Return empty array when there are no saved searches, instead…
Browse files Browse the repository at this point in the history
… of throwing an exception:
  • Loading branch information
cyberwolf committed May 5, 2015
1 parent 396588b commit 8c31aa1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
17 changes: 11 additions & 6 deletions CultureFeed/CultureFeed/SavedSearches/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,18 @@ public function getList($allConsumers = false) {
$xml_element = $this->getXmlElementFromXmlString($result);
$saved_searches = array();

$search_elements = $xml_element->xpath('/response/savedSearches/savedSearch');
if (empty($search_elements)) {
$this->throwXmlElementException($xml_element, $result);
$savedSearchesElement = $xml_element->xpath('/response/savedSearches', false);

if (!($savedSearchesElement instanceof SimpleXMLElement)) {
$this->throwXmlElementException($xml_element, $result);
}
foreach ($search_elements as $search_element) {
$search = $this->parseSavedSearch($search_element);
$saved_searches[$search->id] = $search;

$search_elements = $savedSearchesElement->xpath('//savedSearch');
if (!empty($search_elements)) {
foreach ($search_elements as $search_element) {
$search = $this->parseSavedSearch($search_element);
$saved_searches[$search->id] = $search;
}
}

return $saved_searches;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,27 @@ public function testGetListWithoutXml() {
$result = $this->savedSearches->getList(TRUE);
}

public function testGetEmptyList() {
$saved_search_list_xml = file_get_contents(
__DIR__ . '/data/savedsearchlist_empty.xml'
);

$this->oauthClient->expects($this->once())
->method('authenticatedGetAsXml')
->with(
$this->equalTo('savedSearch/list'),
$this->equalTo(array(
'all' => 'true',
))
)
->will($this->returnValue($saved_search_list_xml));

$this->assertSame(
array(),
$this->savedSearches->getList(TRUE)
);
}

public function testGetListWithIncorrectXml() {
$saved_search_list_xml = file_get_contents(dirname(__FILE__) . '/data/savedsearchlist_missing_parameter.xml');

Expand Down
5 changes: 5 additions & 0 deletions CultureFeed/test/savedsearches/data/savedsearchlist_empty.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<response xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:cdb="http://www.cultuurdatabank.com/XMLSchema/CdbXSD/3.1/FINAL" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<savedSearches/>
<total>0</total>
</response>

0 comments on commit 8c31aa1

Please sign in to comment.