From 0a34bffb6b8a2e91a8616908bfb18d6bc494075f Mon Sep 17 00:00:00 2001 From: Laurent Laffont <llaffont@afi-sa.fr> Date: Tue, 24 Apr 2018 15:30:47 +0200 Subject: [PATCH] dev #72285 keep relative URLS in record link zones --- VERSIONS_WIP/72285 | 1 + library/Class/Notice/Urls.php | 3 ++ .../controllers/RecordCustomLinksTest.php | 36 +++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 VERSIONS_WIP/72285 diff --git a/VERSIONS_WIP/72285 b/VERSIONS_WIP/72285 new file mode 100644 index 00000000000..26b91df9d53 --- /dev/null +++ b/VERSIONS_WIP/72285 @@ -0,0 +1 @@ + - ticket #72285 : correction: si une zone de lien contient une URL relative, le lien reste relatif \ No newline at end of file diff --git a/library/Class/Notice/Urls.php b/library/Class/Notice/Urls.php index 39f674959db..60e06cd2b24 100644 --- a/library/Class/Notice/Urls.php +++ b/library/Class/Notice/Urls.php @@ -146,6 +146,9 @@ class Class_Notice_Urls { protected function _ensureHttp($link) { + if (substr($link, 0, 1) === '/') + return $link; + return (substr(strtoupper($link), 0, 4) != 'HTTP') ? 'http://' . $link : $link; } diff --git a/tests/application/modules/opac/controllers/RecordCustomLinksTest.php b/tests/application/modules/opac/controllers/RecordCustomLinksTest.php index 7ee1bc4cccf..656c119f218 100644 --- a/tests/application/modules/opac/controllers/RecordCustomLinksTest.php +++ b/tests/application/modules/opac/controllers/RecordCustomLinksTest.php @@ -97,7 +97,7 @@ class RecordCustomLinksRechercheControllerTest extends RecordCustomLinksTestCase /** @test */ public function linkToPageDesLibrairesFrShouldBePresent() { - $this->assertXPathContentContains('//a[contains(@href, "www.pagedeslibraires.fr/livre-6236/la-terreur.html")]', + $this->assertXPathContentContains('//a[contains(@href, "http://www.pagedeslibraires.fr/livre-6236/la-terreur.html")]', 'Voir la chronique de Page des libraires', $this->_response->getBody()); } @@ -105,7 +105,7 @@ class RecordCustomLinksRechercheControllerTest extends RecordCustomLinksTestCase /** @test */ public function linkToLePointFrShouldBePresent() { - $this->assertXPathContentContains('//a[contains(@href, "www.lepoint.fr/livres/la-terreur-cinq-meurtres-de-trop")]', + $this->assertXPathContentContains('//a[contains(@href, "http://www.lepoint.fr/livres/la-terreur-cinq-meurtres-de-trop")]', 'Voir la chronique du Point', $this->_response->getBody()); } @@ -140,5 +140,37 @@ class RecordCustomLinksRechercheControllerWithBrazilTest extends RecordCustomLin public function onlyOneLinkShouldContainsFragile() { $this->assertXPathCount('//dd//a[contains(text(), "Fragile")]', 1, $this->_response->getBody()); } +} + + + + +class RecordCustomLinksRechercheControllerWithBackToFutureTest extends RecordCustomLinksTestCase { + public function setUp() { + parent::setUp(); + $record = $this->fixture('Class_Album', + ['id' => 1, + 'titre' => 'Back to future', + 'visible' => 1, + 'type_doc_id' => 100, + 'status' => Class_Album::STATUS_VALIDATED, + 'notes' => [['field' => '933', + 'data' => ['a' => 'external pdf', + '3' => '/userfiles/back.pdf']]]]) + ->index() + ->getNotice(); + Class_Profil::getCurrentProfil() + ->setCfgModules(['recherche' => ['viewnotice100' => ['links_zones' => '933-3-a']]]); + + $this->dispatch('/opac/noticeajax/detail/id_notice/' . $record->getId(), true); + } + + + /** @test */ + public function linkExternalPDFShouldBeRelative() { + $this->assertXPathContentContains('//a[@href="/userfiles/back.pdf"]', + 'external pdf', + $this->_response->getBody()); + } } \ No newline at end of file -- GitLab