From f585611612a52469d667e3b0d35d4e252f92e816 Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Thu, 27 Sep 2018 11:05:26 +0200 Subject: [PATCH] dev #59497: display empty selection in search result --- library/Class/CriteresRecherche.php | 7 +++++- library/Class/MoteurRecherche.php | 8 ++++++- .../SearchSelection/SearchSelectionTest.php | 24 ++++++++++++++++++- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/library/Class/CriteresRecherche.php b/library/Class/CriteresRecherche.php index 5877decfd9a..c3b560a981a 100644 --- a/library/Class/CriteresRecherche.php +++ b/library/Class/CriteresRecherche.php @@ -479,6 +479,11 @@ class Class_CriteresRecherche { } + public function isEmptySelection() { + return $this->isSelection() && $this->getSelection()->isEmpty(); + } + + public function isRechercheCatalogueOuPanierOuSelection() { return $this->isRechercheCatalogue() || $this->isRecherchePanier() @@ -505,7 +510,7 @@ class Class_CriteresRecherche { return $this; } - if (($selection = $this->getSelection()) && !$selection->isEmpty()) { + if ($selection = $this->getSelection()) { $visitor->visitSelection($selection); return $this; } diff --git a/library/Class/MoteurRecherche.php b/library/Class/MoteurRecherche.php index 4aee09a8805..de281f3fb37 100644 --- a/library/Class/MoteurRecherche.php +++ b/library/Class/MoteurRecherche.php @@ -443,11 +443,17 @@ class Class_MoteurRecherche { if ($this->all_facettes) $this->setCondition("MATCH(facettes) AGAINST('" . trim($this->all_facettes)."' IN BOOLEAN MODE)"); - if($this->criteres_recherche->hasEmptyDomain() && !$this->criteres_recherche->isSearchInBasket()){ + if($this->criteres_recherche->hasEmptyDomain() + && !$this->criteres_recherche->isSearchInBasket()){ return ['statut' => 'erreur', 'erreur' => $this->_('Domaine non paramétré')]; } + if($this->criteres_recherche->isEmptySelection()){ + return ['statut' => 'erreur', + 'erreur' => $this->_('La sélection courante est vide')]; + } + return self::getConditionsForRequest($this->conditions, $this->_or_conditions, $this->_filter_domain_conditions); } diff --git a/tests/scenarios/SearchSelection/SearchSelectionTest.php b/tests/scenarios/SearchSelection/SearchSelectionTest.php index 79785695330..8c4f9a3a555 100644 --- a/tests/scenarios/SearchSelection/SearchSelectionTest.php +++ b/tests/scenarios/SearchSelection/SearchSelectionTest.php @@ -292,7 +292,7 @@ class SearchSelectionSelectAllTest extends SearchSelectionTestCase { -class SearchSelectionSelectViewTest extends SearchSelectionTestCase { +class SearchSelectionSelectViewWithSelectionTest extends SearchSelectionTestCase { public function setUp() { parent::setUp(); Zend_Registry::get('session')->search_record_selection = [8, 10]; @@ -321,6 +321,28 @@ class SearchSelectionSelectViewTest extends SearchSelectionTestCase { +class SearchSelectionSelectViewWithoutSelectionTest extends SearchSelectionTestCase { + public function setUp() { + parent::setUp(); + $this->mock_sql->beStrict(); + $this->dispatch('/recherche/simple/selection/1', true); + } + + + /** @test */ + public function pageShouldContainsRemovableCriteriaSelectionCourante() { + $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a', 'Sélection courante'); + } + + + /** @test */ + public function pageShouldContainsNoRecords() { + $this->assertXPathContentContains('//div', 'Aucun résultat trouvé'); + } +} + + + class SearchSelectionAdminVarsTest extends Admin_AbstractControllerTestCase { protected $_storm_default_to_volatile = true; -- GitLab