diff --git a/VERSIONS_HOTLINE/180221 b/VERSIONS_HOTLINE/180221 new file mode 100644 index 0000000000000000000000000000000000000000..45460a72df3907b28e33ddbaa1983606a0806ae9 --- /dev/null +++ b/VERSIONS_HOTLINE/180221 @@ -0,0 +1 @@ + - ticket#180221 : Résultat de recherche : Problème de typage résolu quand on fait un regroupement par oeuvre combiné à une surbrilance des termes recherchés. \ No newline at end of file diff --git a/library/Class/MoteurRecherche/Result.php b/library/Class/MoteurRecherche/Result.php index 1776d975ab99b7e1cceaa0020840b057242e9577..cafb67432f4c84876d183595268979b1f6c24939 100644 --- a/library/Class/MoteurRecherche/Result.php +++ b/library/Class/MoteurRecherche/Result.php @@ -321,6 +321,12 @@ class Class_MoteurRecherche_ResultWork extends Class_MoteurRecherche_Result { } + public function getRecords() : array { + return array_map(fn($notice_work)=> $notice_work->getRecord(), + $this->_records); + } + + public function fetchRecords() { if (!$this->_records_query || $this->_records) return $this->_records; diff --git a/library/Trait/DecorateLabelCallback.php b/library/Trait/DecorateLabelCallback.php new file mode 100644 index 0000000000000000000000000000000000000000..11d42982b0c0fc4678246806913eb20db93cc260 --- /dev/null +++ b/library/Trait/DecorateLabelCallback.php @@ -0,0 +1,32 @@ +<?php +/** + * Copyright (c) 2012-2022, 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 + */ + + +trait Trait_DecorateLabelCallback { + protected + $_decorate_label_callback; + + + public function setDecorateLabelCallback(Closure $callback) : self { + $this->_decorate_label_callback = $callback; + return $this; + } +} diff --git a/library/templates/Intonation/Library/View/Wrapper/Record.php b/library/templates/Intonation/Library/View/Wrapper/Record.php index 88dc175ddad287ff9a8ac119eeaa5a9dea755cf5..ae832cf9653faa6d46510292c6f14943d082bc00 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Record.php +++ b/library/templates/Intonation/Library/View/Wrapper/Record.php @@ -23,6 +23,8 @@ class Intonation_Library_View_Wrapper_Record extends Intonation_Library_View_Wrapper_Abstract { + use Trait_DecorateLabelCallback; + protected $_picture_cache, $_selectable_action = false, @@ -30,8 +32,7 @@ class Intonation_Library_View_Wrapper_Record $_secondary_title_cache, $_description, $_badges, - $_allow_XSL = false, - $_decorate_label_callback; + $_allow_XSL = false; public function getMainTitle() : string { @@ -781,12 +782,6 @@ class Intonation_Library_View_Wrapper_Record public function getTimelineEventsDates() : Intonation_Library_TimelineEventsDates { return new Intonation_Library_TimelineEventsDates((string) $this->_model->getAnnee()); } - - - public function setDecorateLabelCallback(Closure $callback) : self { - $this->_decorate_label_callback = $callback; - return $this; - } } diff --git a/library/templates/Intonation/Library/View/Wrapper/Work.php b/library/templates/Intonation/Library/View/Wrapper/Work.php index 7cd94d2a6643feaf2b534b3a78507dbdedf547ad..35c45b7cb61c107229168d698b1a6400afb7d01b 100644 --- a/library/templates/Intonation/Library/View/Wrapper/Work.php +++ b/library/templates/Intonation/Library/View/Wrapper/Work.php @@ -20,7 +20,11 @@ */ -class Intonation_Library_View_Wrapper_Work extends Intonation_Library_View_Wrapper_Abstract { +class Intonation_Library_View_Wrapper_Work + extends Intonation_Library_View_Wrapper_Abstract { + + use Trait_DecorateLabelCallback; + protected $_record_wrapper; protected function _getRecordWrapper() { diff --git a/tests/scenarios/SearchByWork/SearchResultByWorkTest.php b/tests/scenarios/SearchByWork/SearchResultByWorkTest.php index 06437fccbcdfaf31a6daaf71cf93d42543514561..e29f57ba207bb769783e5d043d4312bcbe8e5d9e 100644 --- a/tests/scenarios/SearchByWork/SearchResultByWorkTest.php +++ b/tests/scenarios/SearchByWork/SearchResultByWorkTest.php @@ -241,6 +241,7 @@ abstract class SearchResultByWorkWithTemplatingWorkTestCase extends SearchResult + class SearchResultByWorkWithTemplatingWorkAccrocDuRocTest extends SearchResultByWorkWithTemplatingWorkTestCase { @@ -516,3 +517,102 @@ class SearchResultByWorkViewWithoutCriteriaTest extends SearchResultByWorkTestCa $this->assertNotXpathContentContains('//span[contains(@class, "btn")]', '1 / 1'); } } + + + + +/* @see https://forge.afi-sa.net/issues/180221 */ +class SearchResultByWorkForLapinWithHighlightedTermTest + extends SearchResultByWorkTestCase { + + public function setUp() { + parent::setUp(); + + $unimarc = (new Class_NoticeUnimarc_Fluent) + ->zoneWithContent('001', '12345') + ->zoneWithChildren('200', ['a' => 'Accroc du roc']) + ->zoneWithChildren('330', ['a' => 'Kreskenn, jeune barde, quitte Ker-Gselzehc pour Ankh-Morpork où il espère devenir un grand musicien.']) + ->zoneWithChildren('700', ['a' => 'Pratchett', 'b' => 'Terry']) + ; + + $this->fixture(Class_Notice::class, + ['id' => 1, + 'type_doc' => Class_TypeDoc::LIVRE, + 'clef_oeuvre' => 'ACCROCDUROC-PRATCHETTT', + 'unimarc' => $unimarc->render()]); + + $this->fixture(Class_Exemplaire::class, + ['id' => 1, + 'id_notice' => 1, + 'id_bib' => 1]); + + $unimarc = (new Class_NoticeUnimarc_Fluent) + ->zoneWithContent('001', '987654') + ->zoneWithChildren('200', ['a' => 'Le conte de Jeannot Lapin']) + ->zoneWithChildren('330', ['a' => 'L\'histoire de Jeannot Lapin.']) + ->zoneWithChildren('700', ['a' => 'Potter', 'b' => 'Beatrix']) + ; + + $this->fixture(Class_Notice::class, + ['id' => 4, + 'type_doc' => Class_TypeDoc::LIVRE, + 'clef_oeuvre' => 'LECONTEDEJEANNOTLAPIN-POTTERBEATRIX', + 'unimarc' => $unimarc->render()]); + + $this->fixture(Class_Exemplaire::class, + ['id' => 4, + 'id_notice' => 4, + 'id_bib' => 1]); + + Zend_Registry::set('sql', $this->mock() + ->whenCalled('fetchOne') + ->with('select count(*) from stats_notices where annee=2020 and mois=10') + ->answers(1) + + ->whenCalled('execute') + ->with('update stats_notices set nb_visu = nb_visu + 1 where annee=2020 and mois=10') + ->answers(1) + + ->whenCalled('fetchAll') + ->with("select id_notice, facettes, clef_oeuvre from notices Where (MATCH(titres, auteurs, editeur, collection, matieres, dewey, other_terms) AGAINST('+(LAPIN LAPINS)' IN BOOLEAN MODE)) and type=1 order by MATCH(auteurs) AGAINST('P_LAPIN') desc, MATCH(titres) AGAINST('P_LAPIN') desc, MATCH(titres) AGAINST('LAPIN') desc, MATCH(auteurs) AGAINST('LAPIN') desc, date_creation desc", + true, + false) + ->answers([[1, 'T1', 'ACCROCDUROC-PRATCHETTT'], + [2, 'T2', 'ACCROCDUROC-PRATCHETTT'], + [4, 'T1', 'LECONTEDEJEANNOTLAPIN-POTTERBEATRIX']]) + ); + + $this->_buildTemplateProfil(['id' => 1]); + (new Class_Profil_Preferences()) + ->setModulePref(Class_Profil::find(1), + (new Class_Profil_ModuleDefinition('recherche', + 'resultat', + 'simple')), + ['highlight_search_terms' => '1']); + $this->dispatch('/opac/recherche/simple/by_work/1/tri/*/expressionRecherche/lapin'); + } + + + /** @test */ + public function liResultCountShouldContains2Documents() { + $this->assertXPathContentContains('//li[contains(@class,"result_count")]', '2 documents'); + } + + + /** @test */ + public function oneDivCardTitleShouldContainsAccrocDuRoc() { + $this->assertXPathContentContains('//div[contains(@class,"card-title")]', 'Accroc du roc'); + } + + + /** @test */ + public function oneDivCardTitleShouldContainsConteDeJeannotLapin() { + $this->assertXPathContentContains('//div[contains(@class,"card-title")]', 'Le conte de Jeannot Lapin'); + } + + + /** @test */ + public function resultsShouldContainsLapinWithHighlightClass() { + $this->assertXPathContentContains('//div//span[@class="highlight font-weight-bold text_decoration_underline"]', 'Lapin'); + } +}