From f9eb9e14ca04688a9b72518e793e8590ef7f51eb Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@afi-sa.fr>
Date: Thu, 4 Feb 2016 11:51:34 +0100
Subject: [PATCH] dev #37100 permalink refactoring + test fix

---
 .../modules/opac/views/scripts/head.phtml      |  1 -
 library/ZendAfi/View/Helper/Permalink.php      | 18 +++++-------------
 public/admin/js/onload_utils.js                | 12 +++++++++++-
 public/opac/js/calendrier.js                   |  1 -
 .../controllers/CatalogueControllerTest.php    |  4 ++--
 .../admin/controllers/CmsControllerTest.php    |  4 ++--
 .../opac/controllers/CmsControllerTest.php     |  6 +++---
 .../controllers/RechercheControllerTest.php    |  2 +-
 8 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/application/modules/opac/views/scripts/head.phtml b/application/modules/opac/views/scripts/head.phtml
index f04ea184171..9005e147654 100644
--- a/application/modules/opac/views/scripts/head.phtml
+++ b/application/modules/opac/views/scripts/head.phtml
@@ -38,7 +38,6 @@
        initializeImgHover();
        initializePopups();
        initializeDivisionFive();
-       initializeReseauxSociaux();
        initializeReloadModule();')
     ->addJQueryBackEnd(sprintf('$("#select_clef_profil").parent().prepend(\'%s\')',
                                $this->tagImg(URL_ADMIN_IMG.'ico/lock.png',
diff --git a/library/ZendAfi/View/Helper/Permalink.php b/library/ZendAfi/View/Helper/Permalink.php
index fa85d052b98..27d93130b2f 100644
--- a/library/ZendAfi/View/Helper/Permalink.php
+++ b/library/ZendAfi/View/Helper/Permalink.php
@@ -28,21 +28,13 @@ class ZendAfi_View_Helper_Permalink extends ZendAfi_View_Helper_BaseHelper {
 
     $lien_permanent = $this->view->_('Lien permanent');
 
-    $dialog = $this->view->tag('div',
-                               $this->view->tag('p', $this->view->_('Copiez le lien suivant') . ':')
-                               . $this->view->tag('input',
-                                                '',
-                                                ['type' => 'url',
-                                                 'readonly' => 'readonly',
-                                                 'value' => $url,
-                                                 'style' => 'width: 100%']),
-                               ['title' => $lien_permanent]);
-
     return $this->view->tagImgHover($icon_url,
-                                    ['class' => 'permalien-img',
-                                     'title' => $lien_permanent,
+                                    ['class' => 'permalink permalien-img', //permalien-img kept for previous skins compatibility
                                      'alt' => $lien_permanent,
-                                     'onclick' => '$(\'' . htmlentities($dialog) . '\').dialog({width:500, height:150})']);
+                                     'title' => $lien_permanent,
+                                     'data-url' => $url,
+                                     'data-helptext' => $this->view->_('Copiez le lien suivant'),
+                                     'onclick' => 'popupPermalink(this)']);
   }
 }
 
diff --git a/public/admin/js/onload_utils.js b/public/admin/js/onload_utils.js
index bf5407578d2..41a04fb58a1 100644
--- a/public/admin/js/onload_utils.js
+++ b/public/admin/js/onload_utils.js
@@ -77,9 +77,9 @@ var autoHideShowConfigurationModule = function() {
   autoHideShowTagOnParentHover('.select_kiosque_form', 'div.boite');
   autoHideShowTagOnParentHover('.edit_menu', '#menu_horizontal');
   autoHideShowTagOnParentHover('.newsadd', 'div.boite');
-
 }
 
+
 var autoHideShowTagOnParentHover = function (child_selector, parent_selector) {
   hide_selector = parent_selector + ' ' + child_selector;
   $(hide_selector).hide();
@@ -112,3 +112,13 @@ var initializeImgHover = function() {
 																 function(){image.attr('src', image.data('out'));});
   });
 }
+
+
+var popupPermalink = function(link) {
+  var link = $(link);
+  $("<div title='" + link.attr("title") + "'>"
+    + "<p>" + link.attr("data-helptext") + "</p>"
+    + "<input type='url' style='width:100%' value='" + link.attr("data-url") + "' readonly>"
+    + "</div>"
+   ).dialog({width:500, height:150});
+}
diff --git a/public/opac/js/calendrier.js b/public/opac/js/calendrier.js
index 1fd15d79981..9da8ae5fcc9 100644
--- a/public/opac/js/calendrier.js
+++ b/public/opac/js/calendrier.js
@@ -48,7 +48,6 @@ var ajaxify_calendars = function () {
 
   if (typeof jQuery != "undefined") {
     $(document).ready(resize_func);
-    $(document).ready(initializeReseauxSociaux());
   }
 
   initializePopups();
diff --git a/tests/application/modules/admin/controllers/CatalogueControllerTest.php b/tests/application/modules/admin/controllers/CatalogueControllerTest.php
index c00f210df2e..065ace0fd40 100644
--- a/tests/application/modules/admin/controllers/CatalogueControllerTest.php
+++ b/tests/application/modules/admin/controllers/CatalogueControllerTest.php
@@ -355,7 +355,7 @@ class CatalogueControllerWithModoPortailTotalAccessIndexTest extends AdminCatalo
 
   /** @test */
   public function pageShouldContainsPermalinkForCataloguePolitique() {
-    $this->assertXPathContentContains('//div//span', "recherche/simple/id_catalogue/200");
+    $this->assertXPath('//img[contains(@class, "permalink")][contains(@data-url, "recherche/simple/id_catalogue/200")]');
   }
 
 
@@ -1266,7 +1266,7 @@ class CatalogueControllerPaniersHistoireTest extends AdminCatalogueControllerTes
 
   /** @test */
   public function pageShouldContainsPermalinkForPanier() {
-    $this->assertXPathContentContains('//div//span', "recherche/simple/id_panier/8");
+    $this->assertXPath('//img[contains(@class, "permalink")][contains(@data-url, "recherche/simple/id_panier/8")]');
   }
 
 
diff --git a/tests/application/modules/admin/controllers/CmsControllerTest.php b/tests/application/modules/admin/controllers/CmsControllerTest.php
index d41c4be3ae5..f0436652121 100644
--- a/tests/application/modules/admin/controllers/CmsControllerTest.php
+++ b/tests/application/modules/admin/controllers/CmsControllerTest.php
@@ -724,7 +724,7 @@ class CmsControllerArticleConcertEditActionTest extends CmsControllerWithPermiss
 
   /** @test */
   public function permalinkShouldContainsArticleAbsoluteUrl() {
-    $this->assertXPathContentContains('//div//span', "cms/articleview/id/4");
+    $this->assertXPath('//img[contains(@class, "permalink")][@data-url="http://localhost' . BASE_URL . '/cms/articleview/id/4"]');
   }
 
 
@@ -2546,7 +2546,7 @@ class CmsControllerArticleExistingTraductionEditTest extends CmsControllerWithPe
 
   /** @test */
   function permalinkShouldContainsArticleUrl() {
-    $this->assertXPathContentContains('//div//span', "cms/articleview/id/41");
+    $this->assertXPath('//img[contains(@class, "permalink")][@data-url="http://localhost' . BASE_URL . '/cms/articleview/id/41"]');
   }
 
 
diff --git a/tests/application/modules/opac/controllers/CmsControllerTest.php b/tests/application/modules/opac/controllers/CmsControllerTest.php
index c366143b22a..258b481a962 100644
--- a/tests/application/modules/opac/controllers/CmsControllerTest.php
+++ b/tests/application/modules/opac/controllers/CmsControllerTest.php
@@ -998,14 +998,14 @@ class CmsControllerArticleViewTest extends CmsControllerWithFeteDeLaFriteTestCas
   /** @test */
   public function socialNetworksContainerShouldBePresent() {
     //on garde le @id="reseaux-sociaux-224" pour la compatibilité avec les persos graphiques
-    $this->assertXpath('//div[@class="reseaux-sociaux"][contains(@data-article-url, "cms/reseau/id_article/224")]/img[contains(@src, "patience.gif")]');
+    $this->assertXpath('//div[contains(@class, "reseaux-sociaux")]//img[contains(@data-url, "cms/articleview/id/224")]');
   }
 
 
   /** @test */
-  public function initializeResauxSociauxScriptShouldBePresent() {
+  public function initializePermalinkScriptShouldBePresent() {
     $this->assertXPathContentContains('//script',
-                                      "initializeReseauxSociaux");
+                                      "initializePermalink");
   }
 
 
diff --git a/tests/application/modules/opac/controllers/RechercheControllerTest.php b/tests/application/modules/opac/controllers/RechercheControllerTest.php
index e5af13439f9..d217f1be291 100644
--- a/tests/application/modules/opac/controllers/RechercheControllerTest.php
+++ b/tests/application/modules/opac/controllers/RechercheControllerTest.php
@@ -2281,7 +2281,7 @@ class RechercheControllerAjoutNoticePanierUrlWithMurConfigTest extends Recherche
 
   /** @test **/
   public function permalinkShouldBeDisplay() {
-    $this->assertXPathContentContains('//span', "recherche/viewnotice/expressionRecherche/potter/facettes/T1/facette/B1/page/2/clef/PETITESSCENESDEBALCONTERRASSE-SUIVIDE100PLANTESPO---RUSTICA-2009-1/id/42225?id_profil=2",$this->_response->getBody());
+    $this->assertXPath('//img[contains(@class, "permalink")][contains(@data-url, "recherche/viewnotice/expressionRecherche/potter/facettes/T1/facette/B1/page/2/")]');
   }
 
 
-- 
GitLab