From 6c84432af34264d058a401434ba6ab5ff1552e8b Mon Sep 17 00:00:00 2001 From: Ghislain Loas <ghislo@sandbox.pergame.net> Date: Thu, 30 Oct 2014 17:36:47 +0100 Subject: [PATCH] hotline_#16652_search_with_bib_filter wrote tests on bib/selection + refacto --- .../opac/controllers/BibController.php | 37 ++++------ .../opac/views/scripts/bib/selection.phtml | 66 +++++++++++------- library/ZendAfi/View/Helper/TagInput.php | 29 ++++++++ public/opac/js/bib.js | 39 ++++++----- .../opac/controllers/BibControllerTest.php | 67 ++++++++++++++++--- 5 files changed, 162 insertions(+), 76 deletions(-) create mode 100644 library/ZendAfi/View/Helper/TagInput.php diff --git a/application/modules/opac/controllers/BibController.php b/application/modules/opac/controllers/BibController.php index bdb67f7bdff..49d56a57840 100644 --- a/application/modules/opac/controllers/BibController.php +++ b/application/modules/opac/controllers/BibController.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 */ ////////////////////////////////////////////////////////////////////////////////////////// // OPAC3 - Controleur localisations @@ -41,8 +41,8 @@ class BibController extends Zend_Controller_Action { protected function _getArticlesForBibs($bibs) { - if (Class_Profil::getCurrentProfil()->getModulePreference('bib', - $this->getRequest()->getActionName(), + if (Class_Profil::getCurrentProfil()->getModulePreference('bib', + $this->getRequest()->getActionName(), 'hide_news')) return array(); @@ -50,7 +50,7 @@ class BibController extends Zend_Controller_Action { $art_loader = Class_Article::getLoader(); foreach($bibs as $bib) - $news = array_merge($news, + $news = array_merge($news, $art_loader->getArticlesByPreferences(array('id_bib' => $bib->getId()))); return $art_loader->filterByLocaleAndWorkflow($news); } @@ -77,7 +77,7 @@ class BibController extends Zend_Controller_Action { function zoneviewAction() { - $bibs = $this->_prepareZoneMap(); + $bibs = $this->_prepareZoneMap(); $this->view->articles = $this->_getArticlesForBibs($bibs); } @@ -88,29 +88,18 @@ class BibController extends Zend_Controller_Action { function selectionAction() { - $this->view->title = "Selection de bibliothèque"; - $class_zone = new Class_Zone(); - $class_bib = new Class_Bib(); + $this->view->titre = $this->view->_('Sélection de bibliothèques pour la recherche'); - $zone_array = $class_zone->getAllZone(); - $this->view->territoire = $zone_array; - $this->view->bib = $class_bib; + $this->view->territoire = Class_Zone::findAll(); - // Url de retour - $url=$_SERVER["HTTP_REFERER"]; - $pos=strPos($_SERVER["HTTP_REFERER"],"bib_select"); - if($pos) $url=substr($url,0,$pos-1); - if(strPos($url,"?") === false) $url.="?"; else $url.="&"; - $this->view->url_retour=$url."bib_select="; - - // Selection active - $id_bibs=$_SESSION["selection_bib"]["id_bibs"]; + $id_bibs = $_SESSION["selection_bib"]["id_bibs"]; if($id_bibs) { $this->view->sel_bib=array(); $id_bibs=explode(",",$id_bibs); foreach($id_bibs as $bib) $this->view->sel_bib[$bib]=true; } - else $this->view->sel_bib="all"; + else + $this->view->sel_bib="all"; } //------------------------------------------------------------------------------------------------------ @@ -122,9 +111,9 @@ class BibController extends Zend_Controller_Action { $retour = $this->_request->getParam('retour'); // Url de retour - if($retour == "notice") + if($retour == "notice") $this->view->url_retour = $_SESSION["recherche"]["retour_notice"]; - if(substr($retour,0,5)=="http:") + if(substr($retour,0,5)=="http:") $this->view->url_retour=$retour; else { $this->view->url_retour = sprintf('%s/bib/bibview/id/%d', BASE_URL, $id_bib); @@ -135,7 +124,7 @@ class BibController extends Zend_Controller_Action { $data = ZendAfi_Filters_Serialize::unserialize($bib->GOOGLE_MAP); // Pas de carte - if(!$data) + if(!$data) $this->_redirect($this->view->url_retour); // Création du javascript diff --git a/application/modules/opac/views/scripts/bib/selection.phtml b/application/modules/opac/views/scripts/bib/selection.phtml index b4c187e0eea..cfa1d71717f 100644 --- a/application/modules/opac/views/scripts/bib/selection.phtml +++ b/application/modules/opac/views/scripts/bib/selection.phtml @@ -1,33 +1,49 @@ -<?php -$this->openBoite($this->_("Sélection de bibliothèques"))?> +<?php +$this->openBoite($this->titre); +echo $this->tag('p', + $this->_('Vous pouvez sélectionner une ou plusieurs bibliothèques pour effectuer une recherche ')); + +echo $this->tagAnchor('javascript:selectall()', + $this->_('Tout cocher')); -<p><span class="textDef" style="padding-left:15px;"><?php echo $this->_('Vous pouvez sélectionner une ou plusieurs bibliothèques pour effectuer une recherche ') ?></span></p> -<p> - <input type="button" name="Valider" value="<?php echo $this->_('Valider la sélection'); ?> " onclick="envoie('<?php echo $this->url_retour; ?>');" /> - <a href="javascript:selectall()"><?php echo $this->_('Tout cocher') ?></a> - - <a href="javascript:deselectall()"><?php echo $this->_('Tout décocher') ?></a> -</p> -<br><br> +echo $this->tagAnchor('javascript:deselectall()', + $this->_('Tout décocher')); +?> <form name="selection"> <?php +echo ('<ul>'); foreach($this->territoire as $zone ) { - echo ('<h2>'.$zone->LIBELLE.'</h2><br />'); - $bib_array = $this->bib->getAllBibByIdZone($zone->ID_ZONE); - if($bib_array) - { - foreach ($bib_array as $bib) - { - if($bib["VISIBILITE"] != "2") continue; - $coche=""; - if($this->sel_bib == "all") $coche="checked"; - elseif($this->sel_bib[$bib["ID_SITE"]] == true) $coche="checked"; - echo ('<input type="checkbox" name="'.$bib["ID_SITE"].'" '.$coche.'/> '.$bib["LIBELLE"].'<br />'); - } - } - echo('<br />'); + echo '<li>' . $this->tag('h2', $zone->getLibelle()); + $bibs = Class_Bib::findAllBy(['id_zone' => $zone->getId()]); + echo ('<ul>'); + foreach($bibs as $bib) { + if($bib->getVisibilite() != "2") + continue; + $coche=""; + + if($this->sel_bib == "all") + $coche="checked"; + elseif($this->sel_bib[$bib->getIdSite()] == true) { + $coche="checked"; + } + echo $this->tag('li', + $this->tag('span', $bib->getLibelle()). + $this->tagInput(['type' => 'checkbox', + 'name' => $bib->getIdSite(), + 'checked' => $coche, + 'value' => $bib->getLibelle()])); + } + echo('</ul></li>'); } -print('</form>'); +echo ('</ul></form>'); +echo $this->tag('p', $this->tagInput(['type' => 'button', + 'name' => 'Valider', + 'value' => $this->_('Valider la sélection'), + 'onclick' => 'envoie(\'' . $this->url(['module' => 'opac', + 'controller' => 'index', + 'action' => 'index', + 'id_profil' => Class_Profil::getCurrentProfil()->getId()], null, true) . '\');'])); $this->closeBoite(); -?> \ No newline at end of file +?> diff --git a/library/ZendAfi/View/Helper/TagInput.php b/library/ZendAfi/View/Helper/TagInput.php new file mode 100644 index 00000000000..91d0af629dd --- /dev/null +++ b/library/ZendAfi/View/Helper/TagInput.php @@ -0,0 +1,29 @@ +<?php +/** + * Copyright (c) 2012-2014, 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_TagInput extends Zend_View_Helper_HtmlElement { + public function tagInput($attribs) { + $html = '<input ' . $this->_htmlAttribs($attribs); + return $html . '>'; + } +} +?> \ No newline at end of file diff --git a/public/opac/js/bib.js b/public/opac/js/bib.js index 1f0a6b9055e..257db12c746 100644 --- a/public/opac/js/bib.js +++ b/public/opac/js/bib.js @@ -1,28 +1,31 @@ -// OPAC3 : Sélection des bibliothèques +/* bib/selection */ + + function envoie(sUrl) { - var chaine="", toutEstCoche=true; - for (var i=0;i<document.selection.length;i++) - { - if (document.selection[i].checked==true) - { - if(chaine > '') chaine=chaine+","; - chaine=chaine+document.selection[i].name; - } - else toutEstCoche=false; - } - if(toutEstCoche==true | chaine == "") chaine="TOUT"; - document.location=sUrl + chaine; + var chaine="", toutEstCoche=true; + + for (var i=0 ; i < document.selection.length; i++) { + if (document.selection[i].checked == true){ + if(chaine > '') + chaine = chaine + "/"; + chaine = chaine + document.selection[i].name; + } + else toutEstCoche=false; + } + if(toutEstCoche==true | chaine == "") + chaine="TOUT"; + document.location = sUrl+ '/bib_select/' + chaine; } function selectall() { - elm=document.selection.length; - for(var i=0;i<elm;i++) document.selection[i].checked="checked"; + elm=document.selection.length; + for(var i=0;i<elm;i++) document.selection[i].checked="checked"; } - + function deselectall() { - elm=document.selection.length; - for(var i=0;i<elm;i++) document.selection[i].checked=""; + elm=document.selection.length; + for(var i=0;i<elm;i++) document.selection[i].checked=""; } diff --git a/tests/application/modules/opac/controllers/BibControllerTest.php b/tests/application/modules/opac/controllers/BibControllerTest.php index 9425d8f537a..a13b7afccdd 100644 --- a/tests/application/modules/opac/controllers/BibControllerTest.php +++ b/tests/application/modules/opac/controllers/BibControllerTest.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 'AbstractControllerTestCase.php'; @@ -55,7 +55,7 @@ abstract class BibControllerWithZoneTestCase extends AbstractControllerTestCase ->setCategorie(Class_ArticleCategorie::getLoader() ->newInstanceWithId(5) ->setLibelle('Bonnes pratiques')); - + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') ->whenCalled('getArticlesByPreferences') ->with(array('id_bib' => '4')) @@ -83,7 +83,7 @@ class BibControllerZoneViewOneTest extends BibControllerWithZoneTestCase { /** @test */ public function bibListShouldBeVisible() { - $this->assertXPathContentContains("//table//td[@class='listeTitre']", + $this->assertXPathContentContains("//table//td[@class='listeTitre']", "Bibliothèque"); } @@ -285,8 +285,8 @@ class BibControllerBibViewAnnecyTest extends BibControllerWithZoneTestCase { /** @test */ public function urlRetourShouldBeZoneViewIdOne() { - $this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]', - 'Retour'); + $this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]', + 'Retour'); } } @@ -295,15 +295,15 @@ class BibControllerBibViewAnnecyWithParamRetourHistoriqueTest extends BibControl /** @test */ public function withUrlRetourCmsArticleViewFiveShouldBeAccepted() { $this->dispatch('bib/bibview/id/4?retour=cms+articleview+5'); - $this->assertXPathContentContains('//a[contains(@href, "/cms/articleview/id/5")]', - 'Retour'); + $this->assertXPathContentContains('//a[contains(@href, "/cms/articleview/id/5")]', + 'Retour'); } /** @test */ public function withUrlRetourCmsOnlyShouldNotBeAccepted() { $this->dispatch('bib/bibview/id/4?retour=cms'); - $this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]', - 'Retour'); + $this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]', + 'Retour'); } } @@ -321,4 +321,53 @@ class BibControllerBibViewInexistantTest extends BibControllerWithZoneTestCase { } } + + +class BibControllerBibSelectionTest extends AbstractControllerTestCase { + public function setUp() { + parent::setUp(); + + $_SERVER['HTTP_REFERER'] = 'http://my-bokeh.fr'; + $_SESSION['selection_bib'] = ['id_bibs' => []]; + + $this->fixture('Class_Zone', + ['id' => 1, + 'libelle' => 'Africa']); + + $cairo = $this->fixture('Class_Bib', + ['id' => 1, + 'id_site' => 1, + 'libelle' => 'Cairo', + 'id_zone' => 1, + 'visibilite' => 2]); + + $casablanca = $this->fixture('Class_Bib', + ['id' => 2, + 'id_site' => '2', + 'libelle' => 'Casablanca', + 'visibilite' => 2, + 'id_zone' => 1]); + + $this->dispatch('bib/selection', true); + } + + + /** @test */ + public function pageShouldBeHtml5Valid() { + $this->assertHTML5($this->_response->getBody()); + } + + + /** @test */ + public function cairoShouldBeInBibList() { + $this->assertXPathContentContains('//li/span', 'Cairo'); + } + + + /** @test */ + public function casablancaShouldBeInBibList() { + $this->assertXPathContentContains('//li/span', 'Casablanca'); + } +} + ?> \ No newline at end of file -- GitLab