diff --git a/application/modules/admin/views/scripts/opds/browse.phtml b/application/modules/admin/views/scripts/opds/browse.phtml index 436859d14df879d5aeea3a3f3e41b5a169f2af61..1532a7a3762fa4c8bba55bd997600e781dcc978c 100644 --- a/application/modules/admin/views/scripts/opds/browse.phtml +++ b/application/modules/admin/views/scripts/opds/browse.phtml @@ -7,7 +7,7 @@ <?php } ?> </ul> <?php } ?> - <?php if ($this->catalog->getSearch()) echo $this->catalog->getSearchForm();?> + <?php if ($this->catalog->getSearch()->isValid()) echo $this->catalog->getSearchForm();?> </div> <ul> <?php foreach($this->catalog->getEntries() as $entry) { ?> @@ -28,5 +28,3 @@ <?php } ?> </ul> - - diff --git a/library/Class/WebService/OPDS/CatalogSearch.php b/library/Class/WebService/OPDS/CatalogSearch.php index 2f09349f4218ba036f6465f5d2ee10c78561f0f6..1932cce930c153b2f472dc4378e4e7bb39a29951 100644 --- a/library/Class/WebService/OPDS/CatalogSearch.php +++ b/library/Class/WebService/OPDS/CatalogSearch.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_OPDS_CatalogSearch { const TERM_TOKEN = '{searchTerms}'; @@ -36,8 +36,8 @@ class Class_WebService_OPDS_CatalogSearch { $this->_load(); if (!$this->hasTemplate()) return; - return str_replace(array(self::TERM_TOKEN, self::PAGE_TOKEN), - array(urlencode($term), 1), + return str_replace(array(self::TERM_TOKEN, self::PAGE_TOKEN), + array(urlencode($term), 1), $this->_template); } @@ -47,13 +47,17 @@ class Class_WebService_OPDS_CatalogSearch { return null != $this->_template; } + public function isValid() { + return true; + } + public function startUrl($attributes) { if (!array_key_exists('TYPE', $attributes) || !array_key_exists('TEMPLATE', $attributes)) return; - if ('application/atom+xml' != $attributes['TYPE']) + if ('application/atom+xml' != $attributes['TYPE']) return; $this->_template = $attributes['TEMPLATE']; diff --git a/library/Class/WebService/OPDS/NullCatalogSearch.php b/library/Class/WebService/OPDS/NullCatalogSearch.php index 3dddacdee10e910eab4612ff9fefe8c117352482..fe7c6c8ea0e83f714bd9153ac5b83f0c3457949a 100644 --- a/library/Class/WebService/OPDS/NullCatalogSearch.php +++ b/library/Class/WebService/OPDS/NullCatalogSearch.php @@ -16,11 +16,12 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ class Class_WebService_OPDS_NullCatalogSearch extends Class_WebService_OPDS_CatalogSearch { public function __construct() {} public function entryForTerm($term) {} public function hasTemplate() {return false;} + public function isValid() { return false; } } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/OpdsControllerTest.php b/tests/application/modules/admin/controllers/OpdsControllerTest.php index d95bc5ef717b02cd5590fe5e377e4a4b54e635d0..3a5d8ec106eea376da512032223b318e9c2aa231 100644 --- a/tests/application/modules/admin/controllers/OpdsControllerTest.php +++ b/tests/application/modules/admin/controllers/OpdsControllerTest.php @@ -16,7 +16,7 @@ * * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * along with AFI-OPAC 2.0; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; @@ -32,7 +32,11 @@ abstract class Admin_OpdsControllerTestCase extends Admin_AbstractControllerTest Class_OpdsCatalog::getLoader()->newInstanceWithId(2) ->setLibelle('PragPub Magazine') - ->setUrl('http://pragprog.com/magazines.opds'))) + ->setUrl('http://pragprog.com/magazines.opds'), + + Class_OpdsCatalog::getLoader()->newInstanceWithId(3) + ->setLibelle('Atramenta') + ->setUrl('http://www.atramenta.net/opds/catalog.atom'))) ->whenCalled('save') ->answers(true) @@ -201,7 +205,7 @@ class Admin_OpdsControllerAddPostActionTest extends Admin_OpdsControllerTestCase $this->_new_catalog = $this->_wrapper->getFirstAttributeForLastCallOn('save'); } - + /** @test */ public function newCatalogLibelleShouldBeFreebooks() { $this->assertEquals('Freebooks', $this->_new_catalog->getLibelle()); @@ -210,7 +214,7 @@ class Admin_OpdsControllerAddPostActionTest extends Admin_OpdsControllerTestCase /** @test */ public function newCatalogUrlShouldFreebookDotOrg() { - $this->assertEquals('http://www.freebooks.org/opds', + $this->assertEquals('http://www.freebooks.org/opds', $this->_new_catalog->getUrl()); } @@ -234,16 +238,16 @@ class Admin_OpdsControllerInvalidPostActionTest extends Admin_OpdsControllerTest 'url' => 'zork')); } - + /** @test */ public function errorsShouldContainsUneValeurEstRequise() { $this->assertXPathContentContains('//ul[@class="errors"]//li', 'Une valeur est requise'); } - + /** @test */ public function errorsShouldContainsUrlNotValid() { - $this->assertXPathContentContains('//ul[@class="errors"]//li', + $this->assertXPathContentContains('//ul[@class="errors"]//li', "'zork' n'est pas une URL valide"); } @@ -295,13 +299,13 @@ class Admin_OpdsControllerEditPostActionTest extends Admin_OpdsControllerTestCas 'url' => 'http://sev.opds')); } - + /** @test */ public function libelleShouldBeScienceEtVie() { $this->assertEquals('Science et vie', Class_OpdsCatalog::getLoader()->find(2)->getLibelle()); } - + /** @test */ public function saveShouldHaveBeenCalled() { $this->assertTrue(Class_OpdsCatalog::getLoader()->methodHasBeenCalled('save')); @@ -333,7 +337,7 @@ class Admin_OpdsControllerDeleteActionTest extends Admin_OpdsControllerTestCase /** @test */ public function shouldRedirectToIndex() { $this->assertRedirectTo('/admin/opds/index'); - } + } } @@ -361,7 +365,7 @@ class Admin_OpdsControllerActionsWithUnknowCatalogTest extends Admin_OpdsControl Class_OpdsCatalog::beVolatile(); } - + /** @test */ public function browseShouldRedirectToIndex() { $this->dispatch('/admin/opds/browse/id/666'); @@ -376,19 +380,50 @@ class Admin_OpdsControllerActionsWithUnknowCatalogTest extends Admin_OpdsControl } } +abstract class Admin_OpdsControllerBrowseAtramentaTestCase extends Admin_OpdsControllerTestCase { + public function setUp() { + parent::setUp(); + + Class_OpdsCatalog::getLoader() + ->find(2) + ->setWebClient(Storm_Test_ObjectWrapper::mock() + ->whenCalled('open_url') + ->with('http://www.atramenta.net/opds/catalog.atom') + ->answers(OPDSFeedFixtures::atramentaStartXml())); + } +} + +class Admin_OpdsControllerBrowseAtramentaActionTest extends Admin_OpdsControllerBrowseAtramentaTestCase { + + public function setUp() { + parent::setUp(); + $this->dispatch('/admin/opds/browse/id/3'); + } + + /** @test */ + public function titleShouldBeParcoursDuCatalogueAtramenta() { + $this->assertXPathContentContains('//h1', 'Parcours du catalogue "Atramenta"', $this->_response->getBody()); + } + + /** @test */ + public function searchFieldShouldNotBePresent() { + $this->assertNotXPath('//div[@class="panel"]//input[@name="search"]'); + } +} + abstract class Admin_OpdsControllerBrowseEbooksGratuitsTestCase extends Admin_OpdsControllerTestCase { public function setUp() { parent::setUp(); - + Class_OpdsCatalog::getLoader() ->find(1) ->setWebClient(Storm_Test_ObjectWrapper::mock() ->whenCalled('open_url') ->with('http://www.ebooksgratuits.com/opds/') ->answers(OPDSFeedFixtures::ebooksGratuitsStartXml()) - + ->whenCalled('open_url') ->with('http://www.ebooksgratuits.com/opds/opensearch.xml') ->answers(OPDSFeedFixtures::ebooksGratuitsSearchDescriptionXml())); @@ -397,7 +432,6 @@ abstract class Admin_OpdsControllerBrowseEbooksGratuitsTestCase extends Admin_Op - class Admin_OpdsControllerBrowseActionTest extends Admin_OpdsControllerBrowseEbooksGratuitsTestCase { public function setUp() { parent::setUp(); @@ -455,21 +489,19 @@ class Admin_OpdsControllerBrowseActionTest extends Admin_OpdsControllerBrowseEbo /** @test */ public function linkToLastPublishedShouldBePresent() { - $this->assertXPathContentContains('//a[contains(@href, "/browse/id/1?entry=' . urlencode('http://www.ebooksgratuits.com/opds/feed.php') . '")]', + $this->assertXPathContentContains('//a[contains(@href, "/browse/id/1?entry=' . urlencode('http://www.ebooksgratuits.com/opds/feed.php') . '")]', 'Dernieres parutions', $this->_response->getBody()); } /** @test */ public function linkToAuteursShouldBePresent() { - $this->assertXPathContentContains('//a[contains(@href, "/browse/id/1?entry=' . urlencode('http://www.ebooksgratuits.com/opds/authors.php') . '")]', + $this->assertXPathContentContains('//a[contains(@href, "/browse/id/1?entry=' . urlencode('http://www.ebooksgratuits.com/opds/authors.php') . '")]', 'Auteurs'); } } - - class Admin_OpdsControllerBrowseEbooksGratuitsLastUpdatedTest extends Admin_OpdsControllerBrowseEbooksGratuitsTestCase { public function setUp() { parent::setUp(); @@ -479,7 +511,7 @@ class Admin_OpdsControllerBrowseEbooksGratuitsLastUpdatedTest extends Admin_Opds ->whenCalled('open_url') ->with('http://www.opacsgratuits.com/opds/feed.php?mode=maj') ->answers(OPDSFeedFixtures::ebooksGratuitsLastUpdatedXml()); - + $this->dispatch('/admin/opds/browse/id/1?entry=' . urlencode('http://www.opacsgratuits.com/opds/feed.php?mode=maj'), true); } @@ -534,7 +566,7 @@ class Admin_OpdsControllerBrowseEbooksGratuitsImportTest extends Admin_OpdsContr 'bibliotheques' => '1;5', 'annexes' => '7;10;19']); - $this->fixture('Class_TypeDoc', ['id'=>Class_TypeDoc::EPUB, + $this->fixture('Class_TypeDoc', ['id'=>Class_TypeDoc::EPUB, 'codif_type_doc' => $codif_type_doc, 'label'=> 'Type doc' ]); @@ -587,13 +619,13 @@ class Admin_OpdsControllerBrowseEbooksGratuitsImportTest extends Admin_OpdsContr $album = Class_Album::find(777); $this->assertEquals('1_777.epub',$album->getRessources()[0]->getFichier()); } - + /** @test */ public function albumCreatedShouldContainsHashedIdOrigine() { $album=Class_Album::find(777); $this->assertEquals( - hash('adler32', 'http://www.ebooksgratuits.com/details.php?book=592'), + hash('adler32', 'http://www.ebooksgratuits.com/details.php?book=592'), $album->getIdOrigine()); } } @@ -604,7 +636,7 @@ class Admin_OpdsControllerBrowseSearchPostActionTest extends Admin_OpdsControlle public function setUp() { parent::setUp(); - + $this->postDispatch('/admin/opds/browse/id/1', array('search' => 'dracula')); } @@ -809,7 +841,7 @@ class OPDSFeedFixtures { </entry> </feed>'; } - + public static function ebooksGratuitsSearchDescriptionXml() { @@ -827,6 +859,42 @@ class OPDSFeedFixtures { <Query role="example" searchTerms="robot" /> </OpenSearchDescription>'; } + + public static function atramentaStartXml() { + return '<?xml version="1.0" encoding="UTF-8"?> + <feed xmlns:app="http://www.w3.org/2007/app" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:opds="http://opds-spec.org/2010/catalog" xml:lang="en" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns="http://www.w3.org/2005/Atom"> + <id>http://www.atramenta.net/opds/catalog.atom</id> + <link type="application/atom+xml" href="http://www.atramenta.net/opds/catalog.atom" rel="self"/> + <title>Atramenta</title> + <updated>2014-08-25T16:19:07+02:00</updated> + <icon>http://www.atramenta.net/favicon.ico</icon> + <author> + <name>Atramenta</name> + <uri>http://www.atramenta.net</uri> + <email>noreply@atramenta.net</email> + </author> +<link type="application/atom+xml; profile=opds-catalog; kind=navigation" href="http://www.atramenta.net/opds/catalog.atom" rel="self"/> + +<entry> + <title>Lecture libre</title> + <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="http://www.atramenta.net/opds/lecture_libre.atom" rel="subsection"/> + <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="http://www.atramenta.net/opds/catalog.atom" rel="start" title="Atramenta"/> + <updated>2014-08-25T16:19:07+02:00</updated> + <id>http://www.atramenta.net/opds/lecture_libre.atom</id> + <content type="text">Des milliers d\'oeuvres du domaine public et d\'auteurs contemporains à télécharger gratuitement</content> +</entry> + +<entry> + <title>Mon compte</title> + <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="https://www.atramenta.net/opds/account.atom" rel="subsection"/> + <link type="application/atom+xml;profile=opds-catalog;kind=navigation" href="http://www.atramenta.net/opds/catalog.atom" rel="start" title="Atramenta"/> + <updated>2014-08-25T16:19:07+02:00</updated> + <id>https://www.atramenta.net/opds/account.atom</id> + <content type="text">Vos oeuvres favorites et vos propres oeuvres et ebooks</content> +</entry> + +</feed>'; + } } @@ -853,8 +921,8 @@ class Admin_OpdsControllerBrowseFeedbooksTestCase extends Admin_OpdsControllerTe urlencode('http://www.feedbooks.com/opds'), urlencode('http://www.feedbooks.com/item/4141'))); } - - + + /** @test */ public function albumShouldHaveThumbnail() { $album = Class_Album::getLoader()->getFirstAttributeForLastCallOn('save');