diff --git a/VERSIONS_HOTLINE/205425 b/VERSIONS_HOTLINE/205425 new file mode 100644 index 0000000000000000000000000000000000000000..03886e9a1d8aa10c83047aceadb4321ac0dc7584 --- /dev/null +++ b/VERSIONS_HOTLINE/205425 @@ -0,0 +1 @@ +- correctif #205425 : Magasin de thèmes: La description affiche qu'une seule fois le lien internet avec le bon libellé \ No newline at end of file diff --git a/library/Class/Notice/Urls.php b/library/Class/Notice/Urls.php index 265d7014cc462b4ac7263997bf08d5ab0cb5f148..6266dffe2b48a93a634a4b87977f7815950d95f5 100644 --- a/library/Class/Notice/Urls.php +++ b/library/Class/Notice/Urls.php @@ -96,13 +96,35 @@ class Class_Notice_Urls { $link_label = $data['valeur']; } - return $link_url + return ($link_url && !$this->_hasBeenReplacedOrIgnored($link_url, $link_label)) ? (new Class_Notice_Field)->setUrl($this->_ensureHttp($link_url)) ->setLabel($link_label) : null; } + protected function _hasBeenReplacedOrIgnored(string $url, ?string $label): bool + { + if (!$existing = $this->_getExisting($url)) + return false; + + if (!$existing->getLabel() && $label) + $existing->setLabel($label); + + return true; + } + + + protected function _getExisting(string $url): ?Class_Notice_Field + { + foreach ($this->_urls as $key => $existing) + if ($url == $existing->get('Url') ?? '') + return $existing; + + return null; + } + + public function _get856a() : array { if ($this->_notice->isCvs()) return []; diff --git a/tests/scenarios/Templates/TemplatesRecordsWithUrlsTest.php b/tests/scenarios/Templates/TemplatesRecordsWithUrlsTest.php index 19a68de13290d53362a1d006d92ccba78216d25d..c60b1f9386dc15ef7ae46af760850fea0b61cdbe 100644 --- a/tests/scenarios/Templates/TemplatesRecordsWithUrlsTest.php +++ b/tests/scenarios/Templates/TemplatesRecordsWithUrlsTest.php @@ -62,8 +62,7 @@ class TemplatesRecordsWithUrlsWithTextReplacementTest public function pageShouldContainsUrlMonSiteWebDotFrWithCliquezMoiAsText() { $this->assertXPathContentContains('//div[contains(@class, "jumbotron_section_content")]//dt[contains(@class,"liens internet")]/following-sibling::dd//a[@href="https://monsiteweb.fr"]', - 'Cliquez moi pour aller sur', - $this->_response->getBody()); + 'Cliquez moi pour aller sur'); } @@ -73,4 +72,24 @@ class TemplatesRecordsWithUrlsWithTextReplacementTest $this->assertXPathContentContains('//div[contains(@class, "jumbotron_section_content")]//dt[contains(@class,"liens internet")]/following-sibling::dd//a[@href="https://autresite.fr"]', 'Follow me'); } + + + /** @test */ + public function linkMonSiteWebDotFrShouldBePresentOnlyOnce() + { + $this->assertXPathCount('//div[contains(@class, "jumbotron_section_content")]/' + . '/dt[contains(@class,"liens internet")]/following-sibling' + . '::dd//a[@href="https://monsiteweb.fr"]', 1); + + } + + + /** @test */ + public function linkAutreSiteDotFrShouldBePresentOnlyOnce() + { + $this->assertXPathCount('//div[contains(@class, "jumbotron_section_content")]/' + . '/dt[contains(@class,"liens internet")]/following-sibling' + . '::dd//a[@href="https://autresite.fr"]', 1); + + } }