diff --git a/VERSIONS_HOTLINE/142936 b/VERSIONS_HOTLINE/142936 new file mode 100644 index 0000000000000000000000000000000000000000..bdd32818184a27026caa283e08b4ceda246f5ec8 --- /dev/null +++ b/VERSIONS_HOTLINE/142936 @@ -0,0 +1 @@ + - ticket #142936 : Résultat de recherche : correction des liens des articles indexés. \ No newline at end of file diff --git a/library/Class/Notice.php b/library/Class/Notice.php index bdfed845d960637fbc88fbec5a618c8356dd2f93..bc5eb20e969b51cbb74c628227181de76d10f48f 100644 --- a/library/Class/Notice.php +++ b/library/Class/Notice.php @@ -580,12 +580,12 @@ class Class_Notice extends Storm_Model_Abstract { public function isArticleCms() { - return ($this->getTypeDoc() == Class_TypeDoc::ARTICLE); + return ((int) $this->getTypeDoc() === (int) Class_TypeDoc::ARTICLE); } public function isRSS() { - return ($this->getTypeDoc() == Class_TypeDoc::RSS); + return ((int) $this->getTypeDoc() === (int) Class_TypeDoc::RSS); } @@ -600,7 +600,7 @@ class Class_Notice extends Storm_Model_Abstract { public function isSite() { - return ($this->getTypeDoc() == Class_TypeDoc::SITE); + return ((int) $this->getTypeDoc() === (int) Class_TypeDoc::SITE); } @@ -614,6 +614,11 @@ class Class_Notice extends Storm_Model_Abstract { } + public function isPage() { + return (string) $this->getTypeDoc() === (string) Class_TypeDoc::PAGE; + } + + public function isSigb() { return ($type = Class_TypeDoc::find($this->getTypeDoc())) ? $type->isSigb() diff --git a/library/Class/Notice/Permalink.php b/library/Class/Notice/Permalink.php index 7e386a6f2241d509b8be8cecd0cef5604de270d7..71c3525ee881075004c1ce91087f13cf70724e00 100644 --- a/library/Class/Notice/Permalink.php +++ b/library/Class/Notice/Permalink.php @@ -31,23 +31,25 @@ class Class_Notice_Permalink { if (!$record) return $this->_searchUrl(); - $doc_type = $record->getTypeDoc(); - if ($doc_type === Class_TypeDoc::ARTICLE) - return $this->paramsForArticle($record); + if ($record->isArticleCms()) + return ['module' => 'opac', + 'controller' => 'cms', + 'action' => 'articleview', + 'id' => $record->getChamp856b()]; - if ($doc_type === Class_TypeDoc::RSS) + if ($record->isRSS()) return ['module' => 'opac', 'controller' => 'rss', 'action' => 'main', 'id_flux' => $record->getChamp856b()]; - if ($doc_type === Class_TypeDoc::SITE) + if ($record->isSite()) return ['module' => 'opac', 'controller' => 'sito', 'action' => 'sitoview', 'id_items' => $record->getChamp856b()]; - if ((string)$doc_type === Class_TypeDoc::PAGE) { + if ($record->isPage()) { $subfield = $record->get_subfield('956', 'u'); return $subfield ? $subfield[0] @@ -58,7 +60,7 @@ class Class_Notice_Permalink { $defaults = $this->paramsForRecord($record); - $params = ($config = Class_DigitalResource::getInstance()->configFor($doc_type)) + $params = ($config = Class_DigitalResource::getInstance()->configFor($record->getTypeDoc())) ? $config->getSearchUrlForRecord($record) : []; @@ -77,14 +79,6 @@ class Class_Notice_Permalink { } - public function paramsForArticle($record) { - return ['module' => 'opac', - 'controller' => 'cms', - 'action' => 'articleview', - 'id' => $record->getChamp856b()]; - } - - protected function _searchUrl() { return ['module' => 'opac', 'controller'=>'recherche', diff --git a/library/ZendAfi/View/Helper/UrlNotice.php b/library/ZendAfi/View/Helper/UrlNotice.php index 6b85693a5c476087fb3ac3cc76a3d0bfe10560ba..1e2e657423a0f2d1454a5dae5fe46497df578c72 100644 --- a/library/ZendAfi/View/Helper/UrlNotice.php +++ b/library/ZendAfi/View/Helper/UrlNotice.php @@ -32,8 +32,9 @@ class ZendAfi_View_Helper_UrlNotice extends Zend_View_Helper_HtmlElement { if (is_array($notice)) $notice = Class_Notice::find($notice['id_notice']); - $options = (new Class_Notice_Permalink())->paramsFor($notice); - if ((string)$notice->getTypeDoc() === Class_TypeDoc::PAGE) + $options = (new Class_Notice_Permalink)->paramsFor($notice); + + if ($notice->isPage()) return Class_Url::relative($options, $name, true); $options = array_merge($options, diff --git a/tests/application/modules/opac/controllers/JavaControllerTest.php b/tests/application/modules/opac/controllers/JavaControllerTest.php index 0d727de194ba0e1c5cb162a1cfc930fdfeeeeb94..40e9dd765610ce3ab045bed8627a25dea7bf4295 100644 --- a/tests/application/modules/opac/controllers/JavaControllerTest.php +++ b/tests/application/modules/opac/controllers/JavaControllerTest.php @@ -249,6 +249,14 @@ class JavaControllerKiosqueSlideShowWithRedirectSettingsTest extends AbstractCon ->answers(10) ->whenCalled('getTypeDoc') ->answers(Class_TypeDoc::LIVRE) + ->whenCalled('isArticleCms') + ->answers(false) + ->whenCalled('isRSS') + ->answers(false) + ->whenCalled('isSite') + ->answers(false) + ->whenCalled('isPage') + ->answers(false) ->whenCalled('getTitrePrincipal') ->answers('Programmers <br> Hell\'s "code"') ->whenCalled('fetchUrlLocalVignette') @@ -264,6 +272,12 @@ class JavaControllerKiosqueSlideShowWithRedirectSettingsTest extends AbstractCon ->whenCalled('getTypeDoc') ->answers(Class_TypeDoc::ARTICLE) + ->whenCalled('isArticleCms') + ->answers(true) + + ->whenCalled('isPage') + ->answers(false) + ->whenCalled('getTitrePrincipal') ->answers('Return of Harlock') @@ -355,4 +369,4 @@ class JavaControllerKiosqueSlideShowWithRedirectSettingsTest extends AbstractCon foreach($xpaths as $xpath) $this->assertXPath($xpath, $this->_response->getBody()); } -} \ No newline at end of file +} diff --git a/tests/library/Class/Notice/PermalinkTest.php b/tests/library/Class/Notice/PermalinkTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2da2ec239af5eb08a18d1b4bed78b9a6437bd2ea --- /dev/null +++ b/tests/library/Class/Notice/PermalinkTest.php @@ -0,0 +1,86 @@ +<?php +/** + * Copyright (c) 2012-2021, 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 + */ + + +class NoticePermalinkTest extends ModelTestCase { + + /** @test */ + public function permalinkForArticleRecordShouldBeArticeView() { + $record = $this + ->fixture(Class_Notice::class, + ['id' => 596, + 'type_doc' => '8']) + ->set_subfield('856', 'b', '12'); + + $this->assertEquals(['module' => 'opac', + 'controller' => 'cms', + 'action' => 'articleview', + 'id' => 12], + (new Class_Notice_Permalink())->paramsFor($record)); + } + + + /** @test */ + public function permalinkForRSSRecordShouldBeRssView() { + $record = $this + ->fixture(Class_Notice::class, + ['id' => 596, + 'type_doc' => '9']) + ->set_subfield('856', 'b', '12'); + + $this->assertEquals(['module' => 'opac', + 'controller' => 'rss', + 'action' => 'main', + 'id_flux' => 12], + (new Class_Notice_Permalink())->paramsFor($record)); + } + + + /** @test */ + public function permalinkForWebSiteRecordShouldBeSitoView() { + $record = $this + ->fixture(Class_Notice::class, + ['id' => 596, + 'type_doc' => '10']) + ->set_subfield('856', 'b', '12'); + + $this->assertEquals(['module' => 'opac', + 'controller' => 'sito', + 'action' => 'sitoview', + 'id_items' => 12], + (new Class_Notice_Permalink())->paramsFor($record)); + } + + + /** @test */ + public function permalinkForPageRecordShouldBeATable() { + $record = $this + ->fixture(Class_Notice::class, + ['id' => 596, + 'type_doc' => 'bokeh_page']) + ->set_subfield('856', 'b', '12') + //set_subfield $valeur is limited to string + ->set_subfield('956', 'u', 'a table'); + + $this->assertEquals('a table', (new Class_Notice_Permalink()) + ->paramsFor($record)); + } +}