From f87be17f05867bb3e1166867239ba87ed8aee5df Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Fri, 31 Mar 2017 10:01:25 +0200
Subject: [PATCH] CIP #57952 add test to widget delete action

---
 .../admin/controllers/WidgetController.php    | 19 +++++++++++++
 .../ZendAfi/View/Helper/FonctionsAdmin.php    |  1 +
 .../controllers/WidgetControllerTest.php      | 27 +++++++++++++++++--
 3 files changed, 45 insertions(+), 2 deletions(-)

diff --git a/application/modules/admin/controllers/WidgetController.php b/application/modules/admin/controllers/WidgetController.php
index 58c9d3ae93f..f5cd084f44e 100644
--- a/application/modules/admin/controllers/WidgetController.php
+++ b/application/modules/admin/controllers/WidgetController.php
@@ -66,6 +66,25 @@ class Admin_WidgetController extends ZendAfi_Controller_Action {
   }
 
 
+  public function deleteAction() {
+    if(!$division = $this->_getParam('division'))
+      return $this->_redirectClose($this->_getReferer());
+
+    $widget = new Class_Systeme_Widget_Widget();
+    if(!$widget
+       ->setId($this->_getParam('id'))
+       ->setProfileId($this->_getParam('id_profil'))
+       ->load())
+      return $this->_redirectClose($this->_getReferer());
+
+    $this->view->titre = $widget->getTitle();
+    $widget->getProfile()->removeBoiteFromDiv($widget->getId(), $division)->save();
+
+    $this->_helper->notify($this->_('La boite %s a été supprimée', $widget->getTitle()));
+    return $this->_redirectClose($this->_getReferer());
+  }
+
+
   public function editMenuAction() {
     return $this->_edit(new Class_Systeme_Widget_Menu());
   }
diff --git a/library/ZendAfi/View/Helper/FonctionsAdmin.php b/library/ZendAfi/View/Helper/FonctionsAdmin.php
index 1e4d5630013..808f9410bc4 100644
--- a/library/ZendAfi/View/Helper/FonctionsAdmin.php
+++ b/library/ZendAfi/View/Helper/FonctionsAdmin.php
@@ -121,6 +121,7 @@ class ZendAfi_View_Helper_FonctionsAdmin extends ZendAfi_View_Helper_BaseHelper
                              'controller' => 'widget',
                              'action' => 'delete',
                              'id' => $this->id_module,
+                             'division' => $this->division,
                              'id_profil' => $this->_getIdProfil()],
                             null, true);
 
diff --git a/tests/application/modules/admin/controllers/WidgetControllerTest.php b/tests/application/modules/admin/controllers/WidgetControllerTest.php
index 9e80324eb25..c8264663213 100644
--- a/tests/application/modules/admin/controllers/WidgetControllerTest.php
+++ b/tests/application/modules/admin/controllers/WidgetControllerTest.php
@@ -1495,14 +1495,14 @@ 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/id_profil/2")]');
+    $this->assertXpath('//div//a[contains(@href, "admin/widget/add/after/2/division/4/id_profil/2")]');
   }
 
 
   /** @test */
   public function deleteWidgetLinkShouldUseParentProfil() {
     $this->dispatch('/opac/index/index/id_profil/6', true);
-    $this->assertXpath('//div//a[contains(@href, "admin/widget/delete/id/2/id_profil/2")]');
+    $this->assertXpath('//div//a[contains(@href, "admin/widget/delete/id/2/division/4/id_profil/2")]');
   }
 
 
@@ -1951,4 +1951,27 @@ class WidgetControllerAddActionPostDispatchTest extends WidgetControllerWidgetCo
   public function currentProfilShouldHaveNbNotices() {
     $this->assertEquals(20, $this->_profil->getCfgAccueilAsArray()['modules'][1]['preferences']['nb_notices']);
   }
+}
+
+
+
+
+class WidgetControllerDeleteActionTest extends WidgetControllerWidgetConfigurationTestCase {
+  public function setUp() {
+    parent::setUp();
+    $this->dispatch('admin/widget/delete/id/6/division/3/id_profil/5',  true);
+    Class_Profil::clearCache();
+  }
+
+
+  /** @test */
+  public function shouldRedirect() {
+    $this->assertRedirect();
+  }
+
+
+  /** @test */
+  public function widgetSixShouldHaveBeenRemoved() {
+    $this->assertEquals([], $this->_profil->getCfgAccueilAsArray()['modules']);
+  }
 }
\ No newline at end of file
-- 
GitLab