From bc9baad258903b58aade45fb354ae7307377c00b Mon Sep 17 00:00:00 2001 From: gloas <gloas@afi-sa.fr> Date: Mon, 10 Apr 2017 15:14:50 +0200 Subject: [PATCH] dev #59152 fix fonctionnal tests + tests failures --- .../admin/controllers/WidgetController.php | 24 ++++++++++++------- .../controllers/AnnexeControllerTest.php | 1 + .../Controller/Plugin/Manager/Annexe.php | 6 +++++ .../Controller/Plugin/Manager/Manager.php | 2 +- .../ZendAfi/Form/Configuration/Widget/Add.php | 4 +++- .../controllers/WidgetControllerTest.php | 20 ++++++++++++++++ 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/application/modules/admin/controllers/WidgetController.php b/application/modules/admin/controllers/WidgetController.php index 443b3ea7170..9dd126b6c49 100644 --- a/application/modules/admin/controllers/WidgetController.php +++ b/application/modules/admin/controllers/WidgetController.php @@ -41,7 +41,7 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { || (!$profil = Class_Profil::find($this->_getParam('id_profil')))) return $this->_redirectClose($this->_getReferer()); - if ($this->_request->isPost()) { + if ($this->_request->isPost() && ('' != $this->_getParam('module_type'))) { $new_id = $profil->createNewModuleAccueilId(); $profil->updateModuleConfigAccueil($new_id, ['type_module' => $this->_getParam('module_type'), @@ -53,11 +53,11 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { $profil->getModulePositionInDiv($sibling, $division) + 1); $profil->save(); $this->_setParam('id', $new_id); - return $this->_edit(new Class_Systeme_Widget_Widget()); + return $this->_redirectCloseWithReload(); } $this->view->form = ZendAfi_Form_Configuration_Widget_Add::newWith([]); - $this->view->form->setAction($this->view->url()); + $this->view->form->setAction($this->view->url(['styles_reload' => null])); $this->renderScript('render-form.phtml'); } @@ -84,7 +84,7 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { public function addMenuAction() { (new Class_Systeme_ModulesAccueil_MenuVertical())->addMenu(); $this->_helper->notify($this->_('Menu ajouté')); - return $this->_redirectClose($this->_getReferer()); + return $this->_redirectCloseWithReload($this->_getReferer()); } @@ -127,7 +127,7 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { protected function _render($widget) { $this->view->titre = $widget->getTitle(); $this->view->form = $form = call_user_func_array([$widget->getForm(), 'newWith'], [$widget->forForm()]); - $form->setAction($this->view->url()); + $form->setAction($this->view->url(['styles_reload' => null])); if ($this->_request->isPost() && $form->isValid($this->_getParams($widget))) return $this->_update($widget->setNewDatas($this->_request->getPost())); @@ -149,9 +149,17 @@ class Admin_WidgetController extends ZendAfi_Controller_Action { ? $this->_helper->notify($widget->getSuccessSaveMessage()) : $this->_helper->notify($this->_('Echec de la sauvegarde de la configuration de %s', $widget->getLabel())); + return $this->_redirectCloseWithReload(); + } + + + protected function _redirectCloseWithReload() { + $url = Class_Url::absolute(['styles_reload' => null]); + if('1' === $this->_getParam('styles_reload')) { + return $this->_redirect($url); + } - return ('1' === $this->_getParam('styles_reload')) - ? $this->_redirect(Class_Url::absolute()) - : $this->_redirectClose(Class_Url::absolute()); + $this->_request->setParam('styles_reload' , null); + return $this->_redirectClose($url); } } \ No newline at end of file diff --git a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php index 49621af5514..279d4d0525c 100644 --- a/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php +++ b/cosmogramme/cosmozend/tests/application/modules/cosmo/controllers/AnnexeControllerTest.php @@ -201,6 +201,7 @@ class AnnexeControllerPostEditActionTest extends AnnexeControllerTestCase { /** @test */ public function shouldRedirectToEdit() { + $this->assertRedirect(); $this->assertRedirectTo('/cosmo/annexe/edit/id/98'); } diff --git a/library/ZendAfi/Controller/Plugin/Manager/Annexe.php b/library/ZendAfi/Controller/Plugin/Manager/Annexe.php index 2a845497d24..47a73019831 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Annexe.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Annexe.php @@ -33,5 +33,11 @@ class ZendAfi_Controller_Plugin_Manager_Annexe extends ZendAfi_Controller_Plugin 'anchorOptions' => ['onclick' => sprintf('return confirm(\'%s\')', $this->_('Etes-vous sûr de vouloir supprimer cette annexe ?'))]]]; } + + + protected function _redirectToEdit($model) { + $this->_redirectClose(sprintf('/cosmo/%s/edit/id/%s', + $this->_request->getControllerName(), $model->getId())); + } } ?> \ No newline at end of file diff --git a/library/ZendAfi/Controller/Plugin/Manager/Manager.php b/library/ZendAfi/Controller/Plugin/Manager/Manager.php index 0dc6c802871..da4180eb6c7 100644 --- a/library/ZendAfi/Controller/Plugin/Manager/Manager.php +++ b/library/ZendAfi/Controller/Plugin/Manager/Manager.php @@ -191,7 +191,7 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi array_merge($this->_getFormValues($model), $this->_request->getParams()), $custom_form ); - $form->setAction($this->_view->url()); + $form->setAction($this->_view->url(['styles_reload' => null])); return $form; } diff --git a/library/ZendAfi/Form/Configuration/Widget/Add.php b/library/ZendAfi/Form/Configuration/Widget/Add.php index 5410991ff28..f56116b4001 100644 --- a/library/ZendAfi/Form/Configuration/Widget/Add.php +++ b/library/ZendAfi/Form/Configuration/Widget/Add.php @@ -29,8 +29,10 @@ class ZendAfi_Form_Configuration_Widget_Add extends ZendAfi_Form_Configuration_W $this->addElement('select', 'module_type', ['label' => $this->_('Type de boite à ajouter'), + 'required' => true, 'registerInArrayValidator' => false, - 'multiOptions' => $widgets]) + 'multiOptions' => array_merge(['' => $this->_('Veuillez sélectionner une boite')], + $widgets)]) ->addToSelectionGroup(['module_type']); } } diff --git a/tests/application/modules/admin/controllers/WidgetControllerTest.php b/tests/application/modules/admin/controllers/WidgetControllerTest.php index 235fec88887..25d33040816 100644 --- a/tests/application/modules/admin/controllers/WidgetControllerTest.php +++ b/tests/application/modules/admin/controllers/WidgetControllerTest.php @@ -2002,3 +2002,23 @@ class WidgetControllerAddMenuActionTest extends WidgetControllerWidgetConfigurat $this->assertRedirect(); } } + + + + +class WidgetControllerAddActionEmptyPostDispatchTest extends WidgetControllerWidgetConfigurationTestCase { + public function setUp() { + parent::setUp(); + $this->postDispatch('/admin/widget/add/after/6/division/3/id_profil/5', + ['titre' => 'mon titre', + 'boite' => 'red_widget', + 'module_type' => '']); + Class_Profil::clearCache(); + } + + + /** @test */ + public function formShouldBeReload() { + $this->assertXPath('//form'); + } +} -- GitLab