From 5e9e8dca523c65c3e5f00c45190cc9d50aada9d9 Mon Sep 17 00:00:00 2001
From: Ghislain Loas <ghislo@sandbox.pergame.net>
Date: Tue, 22 Dec 2015 11:26:34 +0100
Subject: [PATCH] dev #24849 add link for type doc website

---
 .../View/Helper/ListeNotices/Vignettes.php    | 26 +++++++++++++--
 library/ZendAfi/View/Helper/TagWebSite.php    |  4 +--
 .../RechercheControllerAlbumWebSiteTest.php   | 33 ++++++++++++++++++-
 .../controllers/RechercheControllerTest.php   |  2 +-
 4 files changed, 58 insertions(+), 7 deletions(-)

diff --git a/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php b/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php
index dd848615b90..6ad9c1019c9 100644
--- a/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php
+++ b/library/ZendAfi/View/Helper/ListeNotices/Vignettes.php
@@ -116,13 +116,33 @@ class ZendAfi_View_Helper_ListeNotices_Vignettes extends ZendAfi_View_Helper_Lis
 
 
   protected function _link($record, $type_doc) {
-    if(!$type_doc ==  Class_TypeDoc::SITE || !$type_doc == Class_TypeDoc::WEBSITE)
-      return '';
+    if($type_doc ==  Class_TypeDoc::SITE)
+      return $this->_linkForSite($record);
+
+    if($type_doc == Class_TypeDoc::WEBSITE)
+      return $this->_linkForWebSite($record);
+
+    return '';
+  }
+
 
+  protected function _linkForSite($record) {
     if(!$website = $record->getSite())
       return '';
 
-    return $this->view->tagAnchor($website->getUrl(), $this->view->_('Voir le site'));
+    return $this->view->tagAnchor($website->getUrl(), $this->view->_('Ouvrir le lien dans un nouvel onglet'));
+  }
+
+
+  public function _linkForWebSite($record) {
+    if(!$album = $record->getAlbum())
+      return '';
+
+    $helper = $this->view->getHelper('TagWebSite');
+
+    return implode('',
+                   array_map([$helper, 'renderLink'],
+                             $album->getRessources()));
   }
 
 
diff --git a/library/ZendAfi/View/Helper/TagWebSite.php b/library/ZendAfi/View/Helper/TagWebSite.php
index 79353735a1f..ad3574d76a5 100644
--- a/library/ZendAfi/View/Helper/TagWebSite.php
+++ b/library/ZendAfi/View/Helper/TagWebSite.php
@@ -33,11 +33,11 @@ class ZendAfi_View_Helper_TagWebSite extends ZendAfi_View_Helper_BaseHelper {
       $this->_tag('section',
                   $this->_tag('h3', $site->getTitre())
                   . $this->_tag('p', $site->getDescription())
-                  . $this->_renderLink($site));
+                  . $this->renderLink($site));
   }
 
 
-  protected function _renderLink($site) {
+  public function renderLink($site) {
     $label = $this->_('Ouvrir le site dans un nouvel onglet');
     $options = ['href' => $site->getUrl(),
                 'target' =>  '_blank',
diff --git a/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php b/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php
index d294075c6ca..91aae290b22 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerAlbumWebSiteTest.php
@@ -220,4 +220,35 @@ class RechercheControllerAlbumWebSiteViewBibNumCategoryTest extends RechercheCon
   }
 }
 
-?>
\ No newline at end of file
+
+
+class RechercheControlleWebSiteInResultAndModeThumbnailTest extends RechercheControllerAlbumWebSiteTestCase {
+  public function setUp() {
+    parent::setUp();
+
+    $mock_sql = $this->mock()
+         ->whenCalled('fetchAll')
+         ->with("select id_notice, facettes from notices order by annee desc", true, false)
+         ->answers([  [1, ''] ])
+         ->whenCalled('fetchOne')
+         ->answers(1)
+         ->whenCalled('fetchAll')
+         ->answers([Class_Notice::find(1)->toArray()])
+         ->beStrict();
+
+    Zend_Registry::set('sql', $mock_sql);
+
+    Class_Profil::getCurrentProfil()
+      ->setCfgModules(['recherche' =>
+                       ['resultatsimple' =>
+                        ['liste_format' =>  Class_Systeme_ModulesAppli::LISTE_FORMAT_VIGNETTES]]]);
+
+    $this->dispatch('/recherche/simple/id_catalogue/3/id_module/9/aleatoire/1', true);
+  }
+
+
+  /** @test */
+  public function anchorWithWIkipediaUrlShouldBePresent() {
+    $this->assertXPathContentContains('//div[@class="resultat_recherche"]//a[contains(@href,"://www.wikipedia.org")]', 'Ouvrir le site dans un nouvel onglet');
+  }
+}
\ No newline at end of file
diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php
index 303af44d9af..fb04f997386 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php
@@ -3103,6 +3103,6 @@ class RechercheControlleSiteInResultAndModeThumbnailTest extends RechercheContro
 
   /** @test */
   public function anchorWithMonLienShouldBePresent() {
-    $this->assertXPathContentContains('//div[@class="resultat_recherche"]//a[contains(@href,"://monlien.com")]', 'Voir le site');
+    $this->assertXPathContentContains('//div[@class="resultat_recherche"]//a[contains(@href,"://monlien.com")]', 'Ouvrir le lien dans un nouvel onglet');
   }
 }
\ No newline at end of file
-- 
GitLab