From 4b68af77d5dcb992c65bf76fda7f925fe128f9f2 Mon Sep 17 00:00:00 2001
From: Laurent Laffont <llaffont@afi-sa.fr>
Date: Sat, 2 Sep 2017 11:54:55 +0200
Subject: [PATCH] dev #64069 replace add widget on modules by add-from-template

---
 .../ZendAfi/View/Helper/FonctionsAdmin.php    |  2 +-
 .../View/Helper/RenderWidgetTemplates.php     |  6 +-----
 .../controllers/WidgetControllerTest.php      | 21 +++++++++++--------
 3 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/library/ZendAfi/View/Helper/FonctionsAdmin.php b/library/ZendAfi/View/Helper/FonctionsAdmin.php
index b5fba366173..59f6abdcf7b 100644
--- a/library/ZendAfi/View/Helper/FonctionsAdmin.php
+++ b/library/ZendAfi/View/Helper/FonctionsAdmin.php
@@ -137,7 +137,7 @@ class ZendAfi_View_Helper_FonctionsAdmin extends ZendAfi_View_Helper_BaseHelper
 
     $url = $this->view->url(['module' => 'admin',
                              'controller' => 'widget',
-                             'action' => 'add',
+                             'action' => 'add-from-template',
                              'after' => $this->id_module,
                              'division' => $this->division,
                              'id_profil' => $this->_getIdProfil()],
diff --git a/library/ZendAfi/View/Helper/RenderWidgetTemplates.php b/library/ZendAfi/View/Helper/RenderWidgetTemplates.php
index e4c5cf47e6e..076fa1514b6 100644
--- a/library/ZendAfi/View/Helper/RenderWidgetTemplates.php
+++ b/library/ZendAfi/View/Helper/RenderWidgetTemplates.php
@@ -21,7 +21,6 @@
 
 
 class ZendAfi_View_Helper_RenderWidgetTemplates extends ZendAfi_View_Helper_BaseHelper {
-
   public function renderWidgetTemplates($templates) {
     Class_ScriptLoader::getInstance()
       ->addJQueryReady('var widget = $(".widget_templates");'
@@ -63,10 +62,7 @@ class ZendAfi_View_Helper_RenderWidgetTemplates extends ZendAfi_View_Helper_Base
                                     'controller' => 'widget',
                                     'action' => 'add',
                                     'template' => $section_key,
-                                    'template_no' => $template_index,
-                                    'id_profil' => Class_Profil::getCurrentProfil()->getId()],
-                                   null,
-                                   true);
+                                    'template_no' => $template_index]);
     return
       $this->_tag('a',
                   $this->_tag('h4', $template['title']) .
diff --git a/tests/application/modules/admin/controllers/WidgetControllerTest.php b/tests/application/modules/admin/controllers/WidgetControllerTest.php
index 16bdfa5cbfa..0a6c762ed08 100644
--- a/tests/application/modules/admin/controllers/WidgetControllerTest.php
+++ b/tests/application/modules/admin/controllers/WidgetControllerTest.php
@@ -1597,7 +1597,7 @@ class WidgetControllerParentLoginDispatchTest extends WidgetControllerLoginInPar
   /** @test */
   public function addWidgetLinkShouldUseParentProfil() {
     $this->dispatch('/opac/index/index/id_profil/6', true);
-    $this->assertXpath('//div//a[contains(@href, "admin/widget/add/after/2/division/4/id_profil/2")]');
+    $this->assertXpath('//div//a[contains(@href, "admin/widget/add-from-template/after/2/division/4/id_profil/2")]');
   }
 
 
@@ -1988,7 +1988,7 @@ class WidgetControllerLibrarySimpleDispatchTest extends WidgetControllerDispatch
 
 
 
-class WidgetControllerAddActionLinkTest extends WidgetControllerWidgetConfigurationTestCase {
+class WidgetControllerAddFromTemplateActionLinkTest extends WidgetControllerWidgetConfigurationTestCase {
   public function setUp() {
     $this->_type_module = 'LOGIN';
     parent::setUp();
@@ -1998,24 +1998,27 @@ class WidgetControllerAddActionLinkTest extends WidgetControllerWidgetConfigurat
 
   /** @test */
   public function linkAddWidgetShouldBePresent() {
-    $this->assertXPath('//a[contains(@href, "admin/widget/add/after/6/division/3/id_profil/5")]');
+    $this->assertXPath('//a[contains(@href, "admin/widget/add-from-template/after/6/division/3/id_profil/5")]');
   }
 }
 
 
 
 
-class WidgetControllerAddActionDispatchTest extends WidgetControllerWidgetConfigurationTestCase {
+class WidgetControllerAddFromTemplateAfterModuleInDivisionThreeActionDispatchTest extends WidgetControllerWidgetConfigurationTestCase {
   public function setUp() {
     parent::setUp();
-    $this->dispatch('/admin/widget/add/after/6/division/3/id_profil/5', true);
+    $this->dispatch('/admin/widget/add-from-template/after/6/division/3/id_profil/5', true);
   }
 
 
   /** @test */
-  public function submitButtonShouldBePresent() {
-    $this->assertXpath('//button[@type="submit"]');
+  public function addWidgetLinkShouldContainsAfterSixDivisionThreeIdProfilFive() {
+    $this->assertXPathContentContains('//div[@class="widget_templates"]//div/a[contains(@href, "admin/widget/add/after/6/division/3/id_profil/5/template/articles/template_no/3")]/h4',
+                                      'Diaporama',
+                                      $this->_response->getBody());
   }
+
 }
 
 
@@ -2139,7 +2142,7 @@ class WidgetControllerAddActionEmptyPostDispatchTest extends WidgetControllerWid
 class WidgetControllerWidgetAddFromTemplateTest extends WidgetControllerWidgetConfigurationTestCase {
   public function setUp() {
     parent::setUp();
-    $this->dispatch('admin/widget/add-from-template',  true);
+    $this->dispatch('admin/widget/add-from-template/id_profil/2',  true);
   }
 
 
@@ -2157,7 +2160,7 @@ class WidgetControllerWidgetAddFromTemplateTest extends WidgetControllerWidgetCo
 
   /** @test */
   public function articlesSectionShouldContainsDiaporamaWithUrlAddWidgetTemplateArticlesZero() {
-    $this->assertXPathContentContains('//div[@class="widget_templates"]//div/a[contains(@href, "admin/widget/add/template/articles/template_no/3/id_profil/2")]/h4',
+    $this->assertXPathContentContains('//div[@class="widget_templates"]//div/a[contains(@href, "admin/widget/add/id_profil/2/template/articles/template_no/3")]/h4',
                                       'Diaporama');
   }
 
-- 
GitLab