diff --git a/VERSIONS_HOTLINE/114276 b/VERSIONS_HOTLINE/114276 new file mode 100644 index 0000000000000000000000000000000000000000..b5a961d30194f8598c3fa0549ae7134d8185c6e1 --- /dev/null +++ b/VERSIONS_HOTLINE/114276 @@ -0,0 +1 @@ + - ticket #114276 : Magasin de thèmes : correction de la prise en compte du critère de tri dans la boîte de recherche simple \ No newline at end of file diff --git a/library/templates/Intonation/Library/Widget/Search/View.php b/library/templates/Intonation/Library/Widget/Search/View.php index 99effe30272fd3eb49220b0d5069dde54a5dc054..c2754d77a06f0be8328a362a5d0cc64b47f54872 100644 --- a/library/templates/Intonation/Library/Widget/Search/View.php +++ b/library/templates/Intonation/Library/Widget/Search/View.php @@ -201,8 +201,9 @@ abstract class IntonationSearchRenderAbstract { $form ->addElement('hidden', - uniqid() . 'tri', - ['value' => $this->_getOrder()]) + 'tri', + ['value' => $this->_getOrder(), + 'id' => uniqid() . 'tri']) ->addElement('search', 'expressionRecherche', @@ -408,10 +409,9 @@ abstract class IntonationSearchRenderAbstract { protected function _getOrder() { - if ($user_order = (new Class_User_Settings($this->_user))->getSearchOrder()) - return $user_order; - - return $this->_settings->getTri(); + return ($current_order = $this->_criteria->getParam('tri', null)) + ? $current_order + : $this->_settings->getTri(); } diff --git a/tests/scenarios/Templates/TemplatesSearchTest.php b/tests/scenarios/Templates/TemplatesSearchTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2580d03bb04eec820fd77da74ce53f95b72fbdab --- /dev/null +++ b/tests/scenarios/Templates/TemplatesSearchTest.php @@ -0,0 +1,384 @@ +<?php +/** + * Copyright (c) 2012-2020, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH 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). + * + * BOKEH 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 BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +require_once 'TemplatesTest.php'; + +abstract class TemplatesSearchWithSortParameterInWidgetTesCase extends Admin_AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + + $this->_buildTemplateProfil(['id' => 1, + 'libelle' => 'My search page']) + ->setBoiteOfTypeInDivision(1, + Intonation_Library_Widget_Search_Definition::CODE, + ['tri' => Class_CriteresRecherche::SORT_NOVELTY_DESC, + 'placeholder' => 'Pomme, poire']) + ->assertSave(); + } +} + + + +class TemplatesSearchWithSortParameterInWidgetFromIndexPageTest extends TemplatesSearchWithSortParameterInWidgetTesCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/'); + } + + + /** @test */ + public function pageShouldContainsSearchWidget() { + $this->assertXPath('//div[contains(@class, "boite rech_simple")]'); + } + + + /** @test */ + public function expressionRecherchePlaceHolderShouldBePommePoire() { + $this->assertXPath('//input[@name="expressionRecherche"][@placeholder="Pomme, poire"]'); + } + + + /** @test */ + public function formShouldContainsHiddenInputTriWithValueDateCreationAscAlphaTitreAsc() { + $this->assertXPath('//form//input[@type="hidden"][@name="tri"][@value="date_creation desc, alpha_titre asc"]'); + } +} + + + + +class TemplatesSearchWithSortParameterInWidgetFromSearchPageWithTriParamTest extends TemplatesSearchWithSortParameterInWidgetTesCase { + public function setUp() { + parent::setUp(); + $this->dispatch('/recherche/simple/expressionRecherche/poire/tri/alpha_auteur+desc'); + } + + + /** @test */ + public function formShouldContainsHiddenInputTriWithValueAlphaTitre() { + $this->assertXPath('//form//input[@type="hidden"][@name="tri"][@value="alpha_auteur desc"]'); + } +} + + + + +class TemplatesDispatchIntonationSearchTest extends TemplatesIntonationTestCase { + public function setUp() { + parent::setUp(); + + $this->dispatch('/opac/recherche/simple/expressionRecherche/pomme/id_profil/72/multifacets/T1-Y1/facette/Y1/section/1', true); + } + + + /** @test */ + public function searchResultShouldBeDisplay() { + $this->assertXPathContentContains('//h1', 'Résultats pour pomme'); + } + + + public function adminNavShouldBePresent() { + $this->assertXPath('//div[contains(@class, "menu_admin")]'); + } + + + /** @test */ + public function footerShouldBePresent() { + $this->assertXPath('//body//footer'); + } + + + /** @test */ + public function breadcrumbShouldBePresent() { + $this->assertXPath('//ol[@class="breadcrumb"]'); + } + + + /** @test */ + public function navShouldBePresent() { + $this->assertXPath('//body//nav[contains(@class, "navbar")][@role="navigation"]'); + } + + + /** @test */ + public function widgetInMainSectionShouldNotBeVisible() { + $this->assertNotXPath('//main//section//div[contains(@class, "card widget")]'); + } + + + /** @test */ + public function currentProfilTemplateShouldBeIntonation() { + $this->assertEquals('INTONATION', Class_Profil::getCurrentProfil()->getTemplate()); + } + + + /** @test */ + public function linkToDeleteFacetShoulContainsMultifacetT3() { + $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a[@href="/recherche/simple/expressionRecherche/pomme/multifacets/T1"]', 'Site:'); + } +} + + + + +class TemplatesPostDispatchSearchWithCustomMultifactesTest extends AbstractControllerTestCase { + protected $_storm_default_to_volatile = true; + + public function setUp() { + parent::setUp(); + $this->postDispatch('/opac/recherche/simple/', ['custom_multifacets_annexe' => 'A1', + 'custom_multifacets_domains' => 'D1', + 'custom_multifacets_doctype' => ['T1','T2']]); + } + + /** @test */ + public function shouldRedirectToSimpleSearchWithMultifacets() { + $this->assertRedirectTo('/recherche/simple/multifacets/A1-D1-T1-T2'); + } +} + + + + +class TemplatesSearchViewRecordTest extends TemplatesIntonationTestCase { + public function setUp() { + parent::setUp(); + + $conf = (new Class_Systeme_Widget_Action) + ->setId('recherche_viewnotice_1') + ->setProfileId(72) + ->load(); + + $conf + ->setNewDatas(['IntonationIcoAllRecordData' => 'https://ma.super-ico.afi-sa.fr', + 'IntonationLabelAllRecordData' => 'Tout savoir', + 'IntonationTitleAllRecordData' => 'Tout savoir sur la notice']) + ->updateProfile(); + + Class_Profil::clearCache(); + + $this->fixture('Class_CodifGenre', + ['id' => 13, + 'libelle' => 'Roman']); + + $this->fixture('Class_CodifMatiere', + ['id' => 12, + 'libelle' => 'Horreur']); + + $this->fixture('Class_Notice', + ['id' => 456, + 'type_doc' => 1, + 'date_creation' => date('Y-m-d', Class_Notice::getTimeSource()->time()), + 'titre_principal' => 'Psycho', + 'clef_oeuvre' => 'PSYKO', + 'clef_alpha' => 'PSYKO', + 'facettes' => 'G13 M12']); + + $this->fixture('Class_TypeDoc', + ['id' => 1, + 'label' => 'book']); + + $this->fixture('Class_AvisNotice', + ['id' => 178, + 'entete' => "Lost héighway", + 'clef_oeuvre' => 'PSYKO', + 'avis' => 'Oh po po !', + 'note' => 5, + 'date_avis' => '2015-03-18 13:00:00', + 'statut' => 1, + 'abon_ou_bib' => 1, + 'id_notice' => 456, + 'source_author' => null]); + + $this->dispatch('/opac/recherche/viewnotice/id/456/id_profil/72'); + } + + + /** @test */ + public function dispatchViewRecordShouldDisplayPsycho() { + $this->assertXPathContentContains('//h1', 'Psycho'); + } + + + /** @test */ + public function shouldBeANovelty() { + $this->assertXPathContentContains('//a[contains(@href, "/nouveaute/1")]', 'Nouveauté'); + } + + + /** @test */ + public function ratingShouldBeDisplayed() { + $this->assertXPathContentContains('//div', 'Lost héighway'); + } + + + /** @test */ + public function ratingDateForLostHeighwayShouldBe20150318() { + $this->assertXPathContentContains('//div', '18 mars 2015'); + } + + + /** @test */ + public function badgesShouldContainsOneBorrowerReview() { + $this->assertXPathContentContains('//span[contains(@class, "badge")]', '1 avis abonné'); + } + + + /** @test */ + public function badgesShouldContainsTopicRoman() { + $this->assertXPathContentContains('//a[contains(@class, "badge")][contains(@href, "/recherche/simple")][contains(@href, "code_rebond/G13")]', 'Roman'); + } + + + /** @test */ + public function textareaShouldHaveClassFormControl() { + $this->assertXPath('//textarea[contains(@class, "form-control")]'); + } + + + /** @test */ + public function recordNavShouldContainsHomeLinkActive() { + $this->assertXPathContentContains('//ul[contains(@class, "nav")]//li//a[contains(@class, "active")][contains(@href, "recherche/viewnotice")]//div', 'Tout savoir'); + } + + + /** @test */ + public function recordNavHomeLinkShouldContainsIcoMaSuperIcoAndToutSavoirSurLaNoticeTitle() { + $this->assertXPath('//ul[contains(@class, "nav")]//li//a[contains(@class, "active")][contains(@href, "recherche/viewnotice")][@title="Tout savoir sur la notice"]//img[@src= "https://ma.super-ico.afi-sa.fr"]'); + } +} + + + + +class TemplatesSearchRecordsTest extends TemplatesIntonationTestCase { + public function setUp() { + parent::setUp(); + $this->fixture('Class_Notice', + ['id' => 456, + 'titre_principal' => 'Psycho', + 'clef_oeuvre' => 'PSYKO', + 'facettes' => 'G13 M12']); + + $this->dispatch('/opac/recherche/psyko/id_profil/72'); + } + + + /** @test */ + public function shouldDisplayResultsForPsycho() { + $this->assertXPathContentContains('//h1', 'Résultats pour psyko'); + } +} + + + + +class TemplatesDispatchIntonationSearchListFormatWallTest extends TemplatesIntonationTestCase { + public function setUp() { + parent::setUp(); + + $this->fixture('Class_CodifAuteur', + ['id' => 43, + 'libelle' => 'Pomme d\'API']); + + $records = [$this->fixture('Class_Notice', + ['id' => 89]), + $this->fixture('Class_Notice', + ['id' => 99])]; + + $result = $this->mock(); + + $result + ->whenCalled('setDuration') + ->answers($result) + + ->whenCalled('setSettings') + ->answers($result) + + ->whenCalled('getSettings') + ->answers(['facettes' => '']) + + ->whenCalled('fetchFacetsAndTags') + ->answers(['facettes' => '', + 'suggests' => [['id' => 'M87', + 'label' => 'Pomme (sujet)'], + + ['id' => 'A43', + 'label' => 'Pomme d\'API (auteur)']]]) + + ->whenCalled('getRecordsCount') + ->answers(2) + + ->whenCalled('isError') + ->answers(false) + + ->whenCalled('getCriteresRecherche') + ->answers((new Intonation_Library_Search_Criteria)->setParams(['liste_format' => 4])) + + ->whenCalled('fetchRecords') + ->answers($records); + + $engine = $this->mock() + + ->whenCalled('lancerRecherche') + ->answers($result); + + Class_MoteurRecherche::setInstance($engine); + + (new Class_User_Settings(Class_Users::getIdentity()))->setSearchOrder(Class_CriteresRecherche::SORT_AUTHOR_DESC)->save(); + + $this->dispatch('/opac/recherche/simple/expressionRecherche/pomme/id_profil/72/liste_format/4/titre/Les documents', true); + } + + + /** @test */ + public function searchResultOrderShouldBeAuthorDESC() { + $this->assertXPath('//select/option[@selected="selected"][@value="alpha_auteur desc"]'); + } + + + /** @test */ + public function searchResultShouldBeDisplay() { + $this->assertXPathContentContains('//h1', 'les documents'); + } + + + /** @test */ + public function buttonMurShouldBeActive() { + $this->assertXpath('//div//a[contains(@class, "active")][contains(@href, "/liste_format/4")]'); + } + + + /** @test */ + public function suggestionsShouldBeDisplay() { + $this->assertXPathContentContains('//b', 'Suggestions'); + } + + + /** @test */ + public function masonryShouldBeLoaded() { + $this->assertXPath('//head/script[contains(@src, "/masonry.js")]'); + } +} + +?> \ No newline at end of file diff --git a/tests/scenarios/Templates/TemplatesTest.php b/tests/scenarios/Templates/TemplatesTest.php index ab30bcb6819b49dce594dbc5423234dcb27febde..f73f4aeaf02c63aee06ad8c84fb418a6954211be 100644 --- a/tests/scenarios/Templates/TemplatesTest.php +++ b/tests/scenarios/Templates/TemplatesTest.php @@ -826,64 +826,6 @@ class TemplatesDispatchIntonationWithSectionSettingsTest extends TemplatesIntona -class TemplatesDispatchIntonationSearchTest extends TemplatesIntonationTestCase { - public function setUp() { - parent::setUp(); - - $this->dispatch('/opac/recherche/simple/expressionRecherche/pomme/id_profil/72/multifacets/T1-Y1/facette/Y1/section/1', true); - } - - - /** @test */ - public function searchResultShouldBeDisplay() { - $this->assertXPathContentContains('//h1', 'Résultats pour pomme'); - } - - - public function adminNavShouldBePresent() { - $this->assertXPath('//div[contains(@class, "menu_admin")]'); - } - - - /** @test */ - public function footerShouldBePresent() { - $this->assertXPath('//body//footer'); - } - - - /** @test */ - public function breadcrumbShouldBePresent() { - $this->assertXPath('//ol[@class="breadcrumb"]'); - } - - - /** @test */ - public function navShouldBePresent() { - $this->assertXPath('//body//nav[contains(@class, "navbar")][@role="navigation"]'); - } - - - /** @test */ - public function widgetInMainSectionShouldNotBeVisible() { - $this->assertNotXPath('//main//section//div[contains(@class, "card widget")]'); - } - - - /** @test */ - public function currentProfilTemplateShouldBeIntonation() { - $this->assertEquals('INTONATION', Class_Profil::getCurrentProfil()->getTemplate()); - } - - - /** @test */ - public function linkToDeleteFacetShoulContainsMultifacetT3() { - $this->assertXPathContentContains('//div[@class="criteres_recherche"]//a[@href="/recherche/simple/expressionRecherche/pomme/multifacets/T1"]', 'Site:'); - } -} - - - - class TemplatesEditTest extends TemplatesEnabledTestCase { protected $_storm_default_to_volatile = true; @@ -1323,134 +1265,6 @@ class TemplatesILSBorrowerLoggedTest extends TemplatesIntonationTestCase { -class TemplatesPostDispatchSearchWithCustomMultifactesTest extends AbstractControllerTestCase { - protected $_storm_default_to_volatile = true; - - public function setUp() { - parent::setUp(); - $this->postDispatch('/opac/recherche/simple/', ['custom_multifacets_annexe' => 'A1', - 'custom_multifacets_domains' => 'D1', - 'custom_multifacets_doctype' => ['T1','T2']]); - } - - /** @test */ - public function shouldRedirectToSimpleSearchWithMultifacets() { - $this->assertRedirectTo('/recherche/simple/multifacets/A1-D1-T1-T2'); - } -} - - - - -class TemplatesViewRecordTest extends TemplatesIntonationTestCase { - public function setUp() { - parent::setUp(); - - $conf = (new Class_Systeme_Widget_Action) - ->setId('recherche_viewnotice_1') - ->setProfileId(72) - ->load(); - - $conf - ->setNewDatas(['IntonationIcoAllRecordData' => 'https://ma.super-ico.afi-sa.fr', - 'IntonationLabelAllRecordData' => 'Tout savoir', - 'IntonationTitleAllRecordData' => 'Tout savoir sur la notice']) - ->updateProfile(); - - Class_Profil::clearCache(); - - $this->fixture('Class_CodifGenre', - ['id' => 13, - 'libelle' => 'Roman']); - - $this->fixture('Class_CodifMatiere', - ['id' => 12, - 'libelle' => 'Horreur']); - - $this->fixture('Class_Notice', - ['id' => 456, - 'type_doc' => 1, - 'date_creation' => date('Y-m-d', Class_Notice::getTimeSource()->time()), - 'titre_principal' => 'Psycho', - 'clef_oeuvre' => 'PSYKO', - 'clef_alpha' => 'PSYKO', - 'facettes' => 'G13 M12']); - - $this->fixture('Class_TypeDoc', - ['id' => 1, - 'label' => 'book']); - - $this->fixture('Class_AvisNotice', - ['id' => 178, - 'entete' => "Lost héighway", - 'clef_oeuvre' => 'PSYKO', - 'avis' => 'Oh po po !', - 'note' => 5, - 'date_avis' => '2015-03-18 13:00:00', - 'statut' => 1, - 'abon_ou_bib' => 1, - 'id_notice' => 456, - 'source_author' => null]); - - $this->dispatch('/opac/recherche/viewnotice/id/456/id_profil/72'); - } - - - /** @test */ - public function dispatchViewRecordShouldDisplayPsycho() { - $this->assertXPathContentContains('//h1', 'Psycho'); - } - - - /** @test */ - public function shouldBeANovelty() { - $this->assertXPathContentContains('//a[contains(@href, "/nouveaute/1")]', 'Nouveauté'); - } - - - /** @test */ - public function ratingShouldBeDisplayed() { - $this->assertXPathContentContains('//div', 'Lost héighway'); - } - - - /** @test */ - public function ratingDateForLostHeighwayShouldBe20150318() { - $this->assertXPathContentContains('//div', '18 mars 2015'); - } - - - /** @test */ - public function badgesShouldContainsOneBorrowerReview() { - $this->assertXPathContentContains('//span[contains(@class, "badge")]', '1 avis abonné'); - } - - - /** @test */ - public function badgesShouldContainsTopicRoman() { - $this->assertXPathContentContains('//a[contains(@class, "badge")][contains(@href, "/recherche/simple")][contains(@href, "code_rebond/G13")]', 'Roman'); - } - - - /** @test */ - public function textareaShouldHaveClassFormControl() { - $this->assertXPath('//textarea[contains(@class, "form-control")]'); - } - - - /** @test */ - public function recordNavShouldContainsHomeLinkActive() { - $this->assertXPathContentContains('//ul[contains(@class, "nav")]//li//a[contains(@class, "active")][contains(@href, "recherche/viewnotice")]//div', 'Tout savoir'); - } - - - /** @test */ - public function recordNavHomeLinkShouldContainsIcoMaSuperIcoAndToutSavoirSurLaNoticeTitle() { - $this->assertXPath('//ul[contains(@class, "nav")]//li//a[contains(@class, "active")][contains(@href, "recherche/viewnotice")][@title="Tout savoir sur la notice"]//img[@src= "https://ma.super-ico.afi-sa.fr"]'); - } -} - - class TemplatesDispatchNoticeAjaxResourcesTest extends TemplatesIntonationTestCase { /** @test */ @@ -1877,28 +1691,6 @@ class TemplatesDispatchNoticeajaxAuthorActionTest extends TemplatesIntonationTes -class TemplatesSearchRecordsTest extends TemplatesIntonationTestCase { - public function setUp() { - parent::setUp(); - $this->fixture('Class_Notice', - ['id' => 456, - 'titre_principal' => 'Psycho', - 'clef_oeuvre' => 'PSYKO', - 'facettes' => 'G13 M12']); - - $this->dispatch('/opac/recherche/psyko/id_profil/72'); - } - - - /** @test */ - public function shouldDisplayResultsForPsycho() { - $this->assertXPathContentContains('//h1', 'Résultats pour psyko'); - } -} - - - - class TemplatesNoticeajaxMediaDispatchTest extends TemplatesIntonationTestCase { public function setUp() { parent::setUp(); @@ -1938,97 +1730,6 @@ class TemplatesNoticeajaxMediaDispatchTest extends TemplatesIntonationTestCase { -class TemplatesDispatchIntonationSearchListFormatWallTest extends TemplatesIntonationTestCase { - public function setUp() { - parent::setUp(); - - $this->fixture('Class_CodifAuteur', - ['id' => 43, - 'libelle' => 'Pomme d\'API']); - - $records = [$this->fixture('Class_Notice', - ['id' => 89]), - $this->fixture('Class_Notice', - ['id' => 99])]; - - $result = $this->mock(); - - $result - ->whenCalled('setDuration') - ->answers($result) - - ->whenCalled('setSettings') - ->answers($result) - - ->whenCalled('getSettings') - ->answers(['facettes' => '']) - - ->whenCalled('fetchFacetsAndTags') - ->answers(['facettes' => '', - 'suggests' => [['id' => 'M87', - 'label' => 'Pomme (sujet)'], - - ['id' => 'A43', - 'label' => 'Pomme d\'API (auteur)']]]) - - ->whenCalled('getRecordsCount') - ->answers(2) - - ->whenCalled('isError') - ->answers(false) - - ->whenCalled('getCriteresRecherche') - ->answers((new Intonation_Library_Search_Criteria)->setParams(['liste_format' => 4])) - - ->whenCalled('fetchRecords') - ->answers($records); - - $engine = $this->mock() - - ->whenCalled('lancerRecherche') - ->answers($result); - - Class_MoteurRecherche::setInstance($engine); - - (new Class_User_Settings(Class_Users::getIdentity()))->setSearchOrder(Class_CriteresRecherche::SORT_AUTHOR_DESC)->save(); - - $this->dispatch('/opac/recherche/simple/expressionRecherche/pomme/id_profil/72/liste_format/4/titre/Les documents', true); - } - - - /** @test */ - public function searchResultOrderShouldBeAuthorDESC() { - $this->assertXPath('//select/option[@selected="selected"][@value="alpha_auteur desc"]'); - } - - - /** @test */ - public function searchResultShouldBeDisplay() { - $this->assertXPathContentContains('//h1', 'les documents'); - } - - - /** @test */ - public function buttonMurShouldBeActive() { - $this->assertXpath('//div//a[contains(@class, "active")][contains(@href, "/liste_format/4")]'); - } - - - /** @test */ - public function suggestionsShouldBeDisplay() { - $this->assertXPathContentContains('//b', 'Suggestions'); - } - - - /** @test */ - public function masonryShouldBeLoaded() { - $this->assertXPath('//head/script[contains(@src, "/masonry.js")]'); - } -} - - - - abstract class TemplatesIntonationAccountTestCase extends TemplatesIntonationTestCase { protected $_mock_emprunts, $_emprunteur; @@ -3342,9 +3043,8 @@ class TemplatesDispatchEditAllActionsTest extends TemplatesIntonationTestCase { -class TemplatesSearchInSessionTest extends TemplatesIntonationTestCase { - +class TemplatesSearchInSessionTest extends TemplatesIntonationTestCase { public function setUp() { parent::setUp(); Zend_Registry::get('session')->last_search = ['expressionRecherche' => 'trolls de troy'];