diff --git a/module/VuFind/tests/fixtures/recommend/europeana b/module/VuFind/tests/fixtures/recommend/europeana new file mode 100644 index 0000000000000000000000000000000000000000..0baf6d6cc80cf14ca9455ffcb538bf5818dcd173 --- /dev/null +++ b/module/VuFind/tests/fixtures/recommend/europeana @@ -0,0 +1,14 @@ +HTTP/1.1 200 OK +Content-Type: application/rss+xml +Date: Wed, 05 Apr 2017 13:55:18 GMT +Server: Apache-Coyote/1.1 +X-Vcap-Request-Id: 63351bb2-903e-446f-6aad-1ced4f862592 +transfer-encoding: chunked +Connection: Close + +f2f +<?xml version="1.0" encoding="UTF-8" standalone="yes"?><rss xmlns:georss="http://www.georss.org/georss" xmlns:fieldtrip="http://www.fieldtripper.com/fieldtrip_rss" xmlns:europeana="http://www.europeana.eu" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:enrichment="http://www.europeana.eu/schemas/ese/enrichment/" version="2.0"><channel><title>Europeana Open Search</title><link>http://www.europeana.eu</link><description>Europeana Open Search results</description><opensearch:totalResults>38810</opensearch:totalResults><opensearch:startIndex>1</opensearch:startIndex><opensearch:itemsPerPage>12</opensearch:itemsPerPage><atom:link href="" rel="search" type="application/rss+xml"/><opensearch:Query role="request" searchTerms="test" startPage="1"/><image><title>Europeana Open Search</title><link>http://www.europeana.eu</link><url>http://www.europeana.eu/portal/sp/img/europeana-logo-en.png</url></image><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_2000068736886.html</guid><title>Guiard des Moulins , Petite Bible historiale de Charles V. [Paris, BnF, MSS Français 5707]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource_2000068736886.html</link><description>Maître du Livre du sacre. Enlumineur de l'oeuvre reproduite; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_2000060239235.html</guid><title>Guiard des Moulins , Bible Historiale de Jean de Berry. [Paris, BnF, MSS Français 20090]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource_2000060239235.html</link><description>The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170726.html</guid><title>Saint Augustin , De civitate Dei (Livres XI-XXII) , traduit en français par Raoul de Presle. [Paris, BnF, MSS Français 173]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170726.html</link><description>Raoul de Presle. Traducteur; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170711.html</guid><title>Saint Augustin , La cité de Dieu [De Civitate Dei] , (Livres XI-XXII), traduit en français par Raoul de Presles. [Paris, BnF, MSS Français 174]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170711.html</link><description>Augustinus (saint ; 0354-0430). Auteur du texte; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170710.html</guid><title>Saint Augustin , De Civitate Dei , traduit en français par Raoul de Presles (Livre I-X). [Paris, BnF, MSS Français 22912]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170710.html</link><description>Augustinus (saint ; 0354-0430). Auteur du texte; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170694.html</guid><title>Péan Gastineau , Vie de saint Martin de Tours (en vers). [Paris, BnF, MSS Français 1043]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170694.html</link><description>Péan Gatineau (11..-1227?). Auteur du texte; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170677.html</guid><title>Guillaume Durand, évêque de Mende , Rational des divins offices , traduit en français par Jean Golein. [Paris, BnF, MSS Français 437]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource +854 +_1000157170677.html</link><description>Jean Golein. Traducteur; 1374; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170645.html</guid><title>Guillaume Durand , Rational des divins offices [ Rationale divinorum officiorum ] , traduction française par Jean Golein. [Paris, BnF, MSS Français 176]</title><link>http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170645.html</link><description>Durand, Guillaume (évêque de Mende). Auteur du texte; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675952.html</guid><title>Natural polymorphisms and transmitted drug resistance in Estonian HIV-1 CRF06_cpx and its recombinant viruses</title><link>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675952.html</link><description>Avi, Radko; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675484.html</guid><title>Tests for assessing the child’s school readiness and general development. Trial of the tests on the samples of pre-school children and first-grade students in Estonia</title><link>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675484.html</link><description>Häidkind, Pille; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675470.html</guid><title>Simultaneous adsorption of Cd2+, Ni2+, and Pb2+ on peat</title><link>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675470.html</link><description>Sõukand, Ülis; The European Library</description></item><item><guid>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675469.html</guid><title>Haaslava valla infoleht 2009. aasta valimiste ajal</title><link>http://www.europeana.eu/portal/record/92097/BibliographicResource_1000126675469.html</link><description>Vaagen, Ilona; 2011; The European Library</description></item></channel></rss> +0 + diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/EuropeanaResultsTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/EuropeanaResultsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..ae9b739a6dfb830d4ed9667dabee55d0d6eaefe4 --- /dev/null +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/Recommend/EuropeanaResultsTest.php @@ -0,0 +1,168 @@ +<?php + +/** + * EuropeanaResults tests. + * + * PHP version 5 + * + * Copyright (C) Villanova University 2017. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * @category VuFind + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +namespace VuFindTest\Recommend; + +use VuFind\Recommend\EuropeanaResults; +use VuFindHttp\HttpService; +use VuFindTest\Unit\TestCase as TestCase; +use Zend\Http\Client\Adapter\Test as TestAdapter; + +/** + * EuropeanaResults tests. + * + * @category VuFind + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link https://vufind.org/wiki/development:testing:unit_tests Wiki + */ +class EuropeanaResultsTest extends TestCase +{ + /** + * Test that the module properly parses a sample response. + * + * This is a bare minimum test to confirm that Zend\Feed deals with the RSS + * response correctly. More work should be done to confirm that URL generation + * works appropriately, optional configuration parameters are respected, etc. + * + * @return void + */ + public function testResponseParsing() + { + $europeana = new EuropeanaResults('fakekey'); + $europeana->setHttpService($this->getHttpService()); + $europeana->setConfig(''); // use defaults + $results = $this->getMockResults(); + $query = new \Zend\StdLib\Parameters(['lookfor' => 'test']); + $europeana->init($results->getParams(), $query); + $europeana->process($results); + $this->assertEquals( + [ + 'worksArray' => [ + [ + 'title' => 'Guiard des Moulins , Petite Bible historiale de Charles V. [Paris, BnF, MSS Français 5707]', + 'link' => 'http://www.europeana.eu/portal/record/92099/BibliographicResource_2000068736886.html', + 'enclosure' => null, + ], + [ + 'title' => 'Guiard des Moulins , Bible Historiale de Jean de Berry. [Paris, BnF, MSS Français 20090]', + 'link' => 'http://www.europeana.eu/portal/record/92099/BibliographicResource_2000060239235.html', + 'enclosure' => null, + ], + [ + 'title' => 'Saint Augustin , De civitate Dei (Livres XI-XXII) , traduit en français par Raoul de Presle. [Paris, BnF, MSS Français 173]', + 'link' => 'http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170726.html', + 'enclosure' => null, + ], + [ + 'title' => 'Saint Augustin , La cité de Dieu [De Civitate Dei] , (Livres XI-XXII), traduit en français par Raoul de Presles. [Paris, BnF, MSS Français 174]', + 'link' => 'http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170711.html', + 'enclosure' => null, + ], + [ + 'title' => 'Saint Augustin , De Civitate Dei , traduit en français par Raoul de Presles (Livre I-X). [Paris, BnF, MSS Français 22912]', + 'link' => 'http://www.europeana.eu/portal/record/92099/BibliographicResource_1000157170710.html', + 'enclosure' => null, + ], + ], + 'feedTitle' => 'Europeana.eu', + 'sourceLink' => + 'http://www.europeana.eu/portal/search.html?query=test', + ], + $europeana->getResults() + ); + } + + /** + * Return connector. + * + * @param string $fixture HTTP response fixture to load (optional) + * + * @return HttpClient + */ + protected function getHttpService($fixture = 'europeana') + { + $adapter = new TestAdapter(); + if ($fixture) { + $adapter->setResponse($this->loadResponse($fixture)); + } + $service = new HttpService(); + $service->setDefaultAdapter($adapter); + return $service; + } + + /** + * Get a fixture response + * + * @return string + */ + protected function loadResponse($file) + { + $fixturePath = realpath(__DIR__ . '/../../../../fixtures/recommend') . '/'; + return file_get_contents($fixturePath . $file); + } + + /** + * Get a mock results object. + * + * @param \VuFind\Search\Solr\Params $params Params to include in container. + * + * @return \VuFind\Search\Solr\Results + */ + protected function getMockResults($params = null) + { + if (null === $params) { + $params = $this->getMockParams(); + } + $results = $this->getMockBuilder('VuFind\Search\Solr\Results') + ->disableOriginalConstructor()->getMock(); + $results->expects($this->any())->method('getParams') + ->will($this->returnValue($params)); + return $results; + } + + /** + * Get a mock params object. + * + * @param \VuFindSearch\Query\Query $query Query to include in container. + * + * @return \VuFind\Search\Solr\Params + */ + protected function getMockParams($query = null) + { + if (null === $query) { + $query = new \VuFindSearch\Query\Query('foo', 'bar'); + } + $params = $this->getMockBuilder('VuFind\Search\Solr\Params') + ->disableOriginalConstructor()->getMock(); + $params->expects($this->any())->method('getQuery') + ->will($this->returnValue($query)); + return $params; + } +}