Skip to content
Snippets Groups Projects
Commit 6c84432a authored by Ghislain Loas's avatar Ghislain Loas
Browse files

hotline_#16652_search_with_bib_filter wrote tests on bib/selection + refacto

parent c50fac77
Branches
Tags
4 merge requests!529Hotline 6.56,!519Master,!518Hotline 6.55,!507Hotline #16652 search with bib filter
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * 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 * 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 // OPAC3 - Controleur localisations
...@@ -41,8 +41,8 @@ class BibController extends Zend_Controller_Action { ...@@ -41,8 +41,8 @@ class BibController extends Zend_Controller_Action {
protected function _getArticlesForBibs($bibs) { protected function _getArticlesForBibs($bibs) {
if (Class_Profil::getCurrentProfil()->getModulePreference('bib', if (Class_Profil::getCurrentProfil()->getModulePreference('bib',
$this->getRequest()->getActionName(), $this->getRequest()->getActionName(),
'hide_news')) 'hide_news'))
return array(); return array();
...@@ -50,7 +50,7 @@ class BibController extends Zend_Controller_Action { ...@@ -50,7 +50,7 @@ class BibController extends Zend_Controller_Action {
$art_loader = Class_Article::getLoader(); $art_loader = Class_Article::getLoader();
foreach($bibs as $bib) foreach($bibs as $bib)
$news = array_merge($news, $news = array_merge($news,
$art_loader->getArticlesByPreferences(array('id_bib' => $bib->getId()))); $art_loader->getArticlesByPreferences(array('id_bib' => $bib->getId())));
return $art_loader->filterByLocaleAndWorkflow($news); return $art_loader->filterByLocaleAndWorkflow($news);
} }
...@@ -77,7 +77,7 @@ class BibController extends Zend_Controller_Action { ...@@ -77,7 +77,7 @@ class BibController extends Zend_Controller_Action {
function zoneviewAction() { function zoneviewAction() {
$bibs = $this->_prepareZoneMap(); $bibs = $this->_prepareZoneMap();
$this->view->articles = $this->_getArticlesForBibs($bibs); $this->view->articles = $this->_getArticlesForBibs($bibs);
} }
...@@ -88,29 +88,18 @@ class BibController extends Zend_Controller_Action { ...@@ -88,29 +88,18 @@ class BibController extends Zend_Controller_Action {
function selectionAction() { function selectionAction() {
$this->view->title = "Selection de bibliothèque"; $this->view->titre = $this->view->_('Sélection de bibliothèques pour la recherche');
$class_zone = new Class_Zone();
$class_bib = new Class_Bib();
$zone_array = $class_zone->getAllZone(); $this->view->territoire = Class_Zone::findAll();
$this->view->territoire = $zone_array;
$this->view->bib = $class_bib;
// Url de retour $id_bibs = $_SESSION["selection_bib"]["id_bibs"];
$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"];
if($id_bibs) { if($id_bibs) {
$this->view->sel_bib=array(); $this->view->sel_bib=array();
$id_bibs=explode(",",$id_bibs); $id_bibs=explode(",",$id_bibs);
foreach($id_bibs as $bib) $this->view->sel_bib[$bib]=true; 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 { ...@@ -122,9 +111,9 @@ class BibController extends Zend_Controller_Action {
$retour = $this->_request->getParam('retour'); $retour = $this->_request->getParam('retour');
// Url de retour // Url de retour
if($retour == "notice") if($retour == "notice")
$this->view->url_retour = $_SESSION["recherche"]["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; $this->view->url_retour=$retour;
else { else {
$this->view->url_retour = sprintf('%s/bib/bibview/id/%d', BASE_URL, $id_bib); $this->view->url_retour = sprintf('%s/bib/bibview/id/%d', BASE_URL, $id_bib);
...@@ -135,7 +124,7 @@ class BibController extends Zend_Controller_Action { ...@@ -135,7 +124,7 @@ class BibController extends Zend_Controller_Action {
$data = ZendAfi_Filters_Serialize::unserialize($bib->GOOGLE_MAP); $data = ZendAfi_Filters_Serialize::unserialize($bib->GOOGLE_MAP);
// Pas de carte // Pas de carte
if(!$data) if(!$data)
$this->_redirect($this->view->url_retour); $this->_redirect($this->view->url_retour);
// Création du javascript // Création du javascript
......
<?php <?php
$this->openBoite($this->_("Sélection de bibliothèques"))?> $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> echo $this->tagAnchor('javascript:deselectall()',
<p> $this->_('Tout décocher'));
<input type="button" name="Valider" value="<?php echo $this->_('Valider la sélection'); ?> " onclick="envoie('<?php echo $this->url_retour; ?>');" />&nbsp;&nbsp; ?>
<a href="javascript:selectall()"><?php echo $this->_('Tout cocher') ?></a> -
<a href="javascript:deselectall()"><?php echo $this->_('Tout décocher') ?></a>
</p>
<br><br>
<form name="selection"> <form name="selection">
<?php <?php
echo ('<ul>');
foreach($this->territoire as $zone ) foreach($this->territoire as $zone )
{ {
echo ('<h2>'.$zone->LIBELLE.'</h2><br />'); echo '<li>' . $this->tag('h2', $zone->getLibelle());
$bib_array = $this->bib->getAllBibByIdZone($zone->ID_ZONE); $bibs = Class_Bib::findAllBy(['id_zone' => $zone->getId()]);
if($bib_array) echo ('<ul>');
{ foreach($bibs as $bib) {
foreach ($bib_array as $bib) if($bib->getVisibilite() != "2")
{ continue;
if($bib["VISIBILITE"] != "2") continue; $coche="";
$coche="";
if($this->sel_bib == "all") $coche="checked"; if($this->sel_bib == "all")
elseif($this->sel_bib[$bib["ID_SITE"]] == true) $coche="checked"; $coche="checked";
echo ('<input type="checkbox" name="'.$bib["ID_SITE"].'" '.$coche.'/>&nbsp;'.$bib["LIBELLE"].'<br />'); elseif($this->sel_bib[$bib->getIdSite()] == true) {
} $coche="checked";
} }
echo('<br />'); 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(); $this->closeBoite();
?> ?>
\ No newline at end of file
<?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
// OPAC3 : Sélection des bibliothèques /* bib/selection */
function envoie(sUrl) function envoie(sUrl)
{ {
var chaine="", toutEstCoche=true; var chaine="", toutEstCoche=true;
for (var i=0;i<document.selection.length;i++)
{ for (var i=0 ; i < document.selection.length; i++) {
if (document.selection[i].checked==true) if (document.selection[i].checked == true){
{ if(chaine > '')
if(chaine > '') chaine=chaine+","; chaine = chaine + "/";
chaine=chaine+document.selection[i].name; chaine = chaine + document.selection[i].name;
} }
else toutEstCoche=false; else toutEstCoche=false;
} }
if(toutEstCoche==true | chaine == "") chaine="TOUT"; if(toutEstCoche==true | chaine == "")
document.location=sUrl + chaine; chaine="TOUT";
document.location = sUrl+ '/bib_select/' + chaine;
} }
function selectall() function selectall()
{ {
elm=document.selection.length; elm=document.selection.length;
for(var i=0;i<elm;i++) document.selection[i].checked="checked"; for(var i=0;i<elm;i++) document.selection[i].checked="checked";
} }
function deselectall() function deselectall()
{ {
elm=document.selection.length; elm=document.selection.length;
for(var i=0;i<elm;i++) document.selection[i].checked=""; for(var i=0;i<elm;i++) document.selection[i].checked="";
} }
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * 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 * 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'; require_once 'AbstractControllerTestCase.php';
...@@ -55,7 +55,7 @@ abstract class BibControllerWithZoneTestCase extends AbstractControllerTestCase ...@@ -55,7 +55,7 @@ abstract class BibControllerWithZoneTestCase extends AbstractControllerTestCase
->setCategorie(Class_ArticleCategorie::getLoader() ->setCategorie(Class_ArticleCategorie::getLoader()
->newInstanceWithId(5) ->newInstanceWithId(5)
->setLibelle('Bonnes pratiques')); ->setLibelle('Bonnes pratiques'));
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article') Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Article')
->whenCalled('getArticlesByPreferences') ->whenCalled('getArticlesByPreferences')
->with(array('id_bib' => '4')) ->with(array('id_bib' => '4'))
...@@ -83,7 +83,7 @@ class BibControllerZoneViewOneTest extends BibControllerWithZoneTestCase { ...@@ -83,7 +83,7 @@ class BibControllerZoneViewOneTest extends BibControllerWithZoneTestCase {
/** @test */ /** @test */
public function bibListShouldBeVisible() { public function bibListShouldBeVisible() {
$this->assertXPathContentContains("//table//td[@class='listeTitre']", $this->assertXPathContentContains("//table//td[@class='listeTitre']",
"Bibliothèque"); "Bibliothèque");
} }
...@@ -285,8 +285,8 @@ class BibControllerBibViewAnnecyTest extends BibControllerWithZoneTestCase { ...@@ -285,8 +285,8 @@ class BibControllerBibViewAnnecyTest extends BibControllerWithZoneTestCase {
/** @test */ /** @test */
public function urlRetourShouldBeZoneViewIdOne() { public function urlRetourShouldBeZoneViewIdOne() {
$this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]', $this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]',
'Retour'); 'Retour');
} }
} }
...@@ -295,15 +295,15 @@ class BibControllerBibViewAnnecyWithParamRetourHistoriqueTest extends BibControl ...@@ -295,15 +295,15 @@ class BibControllerBibViewAnnecyWithParamRetourHistoriqueTest extends BibControl
/** @test */ /** @test */
public function withUrlRetourCmsArticleViewFiveShouldBeAccepted() { public function withUrlRetourCmsArticleViewFiveShouldBeAccepted() {
$this->dispatch('bib/bibview/id/4?retour=cms+articleview+5'); $this->dispatch('bib/bibview/id/4?retour=cms+articleview+5');
$this->assertXPathContentContains('//a[contains(@href, "/cms/articleview/id/5")]', $this->assertXPathContentContains('//a[contains(@href, "/cms/articleview/id/5")]',
'Retour'); 'Retour');
} }
/** @test */ /** @test */
public function withUrlRetourCmsOnlyShouldNotBeAccepted() { public function withUrlRetourCmsOnlyShouldNotBeAccepted() {
$this->dispatch('bib/bibview/id/4?retour=cms'); $this->dispatch('bib/bibview/id/4?retour=cms');
$this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]', $this->assertXPathContentContains('//a[contains(@href, "/bib/zoneview/id/1")]',
'Retour'); 'Retour');
} }
} }
...@@ -321,4 +321,53 @@ class BibControllerBibViewInexistantTest extends BibControllerWithZoneTestCase { ...@@ -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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment