From 3b2d9f2d2183de706dc9084b18ac4e1c0e7aa769 Mon Sep 17 00:00:00 2001 From: llaffont <laurent.laffont@gmail.com> Date: Wed, 26 Feb 2014 18:23:20 +0100 Subject: [PATCH] Create front module "Domain browser" --- library/Class/Systeme/ModulesAccueil.php | 4 +- .../Systeme/ModulesAccueil/DomainBrowser.php | 38 ++++++ .../View/Helper/Accueil/DomainBrowser.php | 33 +++++ .../ZendAfi/View/Helper/DomainsBrowsing.php | 7 +- library/storm | 2 +- .../ProfilControllerPageAccueilTest.php | 6 + .../View/Helper/Accueil/DomainBrowserTest.php | 114 ++++++++++++++++++ 7 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 library/Class/Systeme/ModulesAccueil/DomainBrowser.php create mode 100644 library/ZendAfi/View/Helper/Accueil/DomainBrowser.php create mode 100644 tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php diff --git a/library/Class/Systeme/ModulesAccueil.php b/library/Class/Systeme/ModulesAccueil.php index 8d90a40143a..9c0e22a9dbe 100644 --- a/library/Class/Systeme/ModulesAccueil.php +++ b/library/Class/Systeme/ModulesAccueil.php @@ -125,7 +125,9 @@ class Class_Systeme_ModulesAccueil extends Class_Systeme_ModulesAbstract { 'NEWSLETTERS' => new Class_Systeme_ModulesAccueil_Newsletters, 'MULTIMEDIA' => new Class_Systeme_ModulesAccueil_Multimedia, 'HISTORIQUE_RECHERCHES' => new Class_Systeme_ModulesAccueil_HistoriqueRecherches, - 'PANIER' => new Class_Systeme_ModulesAccueil_Panier]; + 'PANIER' => new Class_Systeme_ModulesAccueil_Panier, + 'DOMAIN_BROWSER' => new Class_Systeme_ModulesAccueil_DomainBrowser, + ]; } return self::$_modules; diff --git a/library/Class/Systeme/ModulesAccueil/DomainBrowser.php b/library/Class/Systeme/ModulesAccueil/DomainBrowser.php new file mode 100644 index 00000000000..e41f9c15893 --- /dev/null +++ b/library/Class/Systeme/ModulesAccueil/DomainBrowser.php @@ -0,0 +1,38 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * 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 + */ + + +class Class_Systeme_ModulesAccueil_DomainBrowser extends Class_Systeme_ModulesAccueil_Null{ + + protected $_group = Class_Systeme_ModulesAccueil::GROUP_RECH; + + protected $_libelle = 'Domaines'; + + protected $_popupWidth = 600; + + protected $_popupHeight = 200; + + protected $_defaultValues = ['titre' => 'Domaines', + 'root_domain_id' => 0]; + +} + +?> diff --git a/library/ZendAfi/View/Helper/Accueil/DomainBrowser.php b/library/ZendAfi/View/Helper/Accueil/DomainBrowser.php new file mode 100644 index 00000000000..0a447dcae73 --- /dev/null +++ b/library/ZendAfi/View/Helper/Accueil/DomainBrowser.php @@ -0,0 +1,33 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * 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 + */ +class ZendAfi_View_Helper_Accueil_DomainBrowser extends ZendAfi_View_Helper_Accueil_Base { + /** @return array */ + public function getHTML() { + $this->titre = $this->preferences['titre']; + + $current_domain = Class_Catalogue::find($this->preferences['root_domain_id']); + $this->contenu = $this->view->domainsBrowsing($current_domain, ''); + + return $this->getHtmlArray(); + } +} + +?> \ No newline at end of file diff --git a/library/ZendAfi/View/Helper/DomainsBrowsing.php b/library/ZendAfi/View/Helper/DomainsBrowsing.php index f35adcee756..c3877e01488 100644 --- a/library/ZendAfi/View/Helper/DomainsBrowsing.php +++ b/library/ZendAfi/View/Helper/DomainsBrowsing.php @@ -20,9 +20,10 @@ */ class ZendAfi_View_Helper_DomainsBrowsing extends ZendAfi_View_Helper_BaseHelper { - - public function domainsBrowsing($current_domain,$current_breadcrumb) { + if (null == $current_domain) + $current_domain = Class_Catalogue::getRoot(); + return $this->displayParentsDomains($current_breadcrumb). $this->displayDomain($current_domain,$current_breadcrumb). @@ -76,7 +77,7 @@ class ZendAfi_View_Helper_DomainsBrowsing extends ZendAfi_View_Helper_BaseHelper 'parents' => $parents]),null,true) : $this->view->url(array_filter(['controller' =>'recherche', 'action' => 'simple', - 'id'=> $domain->getId(), + 'id_catalogue'=> $domain->getId(), 'parents' => $parents]),null,true); } diff --git a/library/storm b/library/storm index 5f32b4d00d6..f403adf40d0 160000 --- a/library/storm +++ b/library/storm @@ -1 +1 @@ -Subproject commit 5f32b4d00d6d5f4dcd22dc27e0b260a50e44076f +Subproject commit f403adf40d0c2a4904541aba1c07e0f984d4fea9 diff --git a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php index ecae8ceb8dc..8cdff99e86b 100644 --- a/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php +++ b/tests/application/modules/admin/controllers/ProfilControllerPageAccueilTest.php @@ -130,6 +130,12 @@ class Admin_ProfilControllerPageAccueilJeunesseTest extends Admin_ProfilControll $this->assertXPathContentContains('//ul[@id="allItems"]/li[@id="PRETS"]','Prêts'); } + + /** @test */ + public function domainBrowserModuleShouldBeAvailable() { + $this->assertXPathContentContains('//ul[@id="allItems"]/li[@id="DOMAIN_BROWSER"]','Domaines'); + } + /** @test */ public function boitePretsShouldBeInDivisionOne() { $this->assertXPath('//ul[@id="box1"]/li[@id="PRETS"][@id_module="9"]//img[contains(@onclick,"accueil/prets")]'); diff --git a/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php b/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php new file mode 100644 index 00000000000..b328776598c --- /dev/null +++ b/tests/library/ZendAfi/View/Helper/Accueil/DomainBrowserTest.php @@ -0,0 +1,114 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details. + * + * 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 + */ +require_once 'library/ZendAfi/View/Helper/ViewHelperTestCase.php'; + + +abstract class ZendAfi_View_Helper_Accueil_DomainBrowserTestCase extends ViewHelperTestCase { + /** @var string */ + protected $_html; + + + public function setUp() { + parent::setUp(); + Class_CodifThesaurus::beVolatile(); + $this->fixture('Class_Catalogue', + ['id' => 1, + 'libelle' => 'Metal']); + $this->fixture('Class_Catalogue', + ['id' => 2, + 'libelle' => 'Jazz', + 'sous_domaines' => [ + $this->fixture('Class_Catalogue', + ['id' => 21, + 'libelle' => 'BeBop']), + $this->fixture('Class_Catalogue', + ['id' => 22, + 'libelle' => 'Acid']) + ]]); + } +} + + + +class ZendAfi_View_Helper_Accueil_DomainBrowserTest extends ZendAfi_View_Helper_Accueil_DomainBrowserTestCase { + public function setUp() { + parent::setUp(); + + $helper = new ZendAfi_View_Helper_Accueil_DomainBrowser(9, [ + 'division' => 1, + 'type_module' => 'DOMAIN_BROWSER', + 'preferences' => [ + 'boite' => '', + 'titre' => 'Browse Jazz domain', + 'root_domain_id' => '2']]); + + $helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_html = $helper->getBoite(); + } + + /** @test */ + public function titleShouldBeBrowseJazzDomain() { + $this->assertXPathContentContains($this->_html, '//div[@class="titre"]', 'Browse Jazz domain'); + } + + + /** @test */ + public function linkForDomainBeBopShouldBePresent() { + $this->assertXPath($this->_html, '//a[contains(@href, "/recherche/simple/id_catalogue/21")]', $this->_html); + } + + + /** @test */ + public function linkForDomainAcidShouldBePresent() { + $this->assertXPath($this->_html, '//a[contains(@href, "/recherche/simple/id_catalogue/22")]', $this->_html); + } +} + + + + +class ZendAfi_View_Helper_Accueil_DomainBrowserWithoutConfigTest extends ZendAfi_View_Helper_Accueil_DomainBrowserTestCase { + public function setUp() { + parent::setUp(); + + $helper = new ZendAfi_View_Helper_Accueil_DomainBrowser(9, [ + 'division' => 1, + 'type_module' => 'DOMAIN_BROWSER', + 'preferences' => []]); + + $helper->setView(new ZendAfi_Controller_Action_Helper_View()); + $this->_html = $helper->getBoite(); + } + + + /** @test */ + public function linkForDomainMetalShouldBePresent() { + $this->assertXPath($this->_html, '//a[contains(@href, "/recherche/simple/id_catalogue/1")]', $this->_html); + } + + + /** @test */ + public function linkForDomainJazzShouldBePresent() { + $this->assertXPath($this->_html, '//a[contains(@href, "/recherche/simple/id_catalogue/2")]', $this->_html); + } +} + +?> \ No newline at end of file -- GitLab