From d2adf40cfadc0896154fb421f3fba0ed9b40669d Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-sa.fr>
Date: Tue, 20 Mar 2018 10:04:25 +0100
Subject: [PATCH] hotline #72655 fix redirectToReferer when called from popup
 action

---
 VERSIONS_HOTLINE/72655                             |  2 ++
 .../modules/opac/controllers/AbonneController.php  |  1 +
 library/ZendAfi/Controller/Action.php              |  7 ++++---
 .../opac/controllers/AbonneControllerAvisTest.php  | 14 +++++++++++++-
 4 files changed, 20 insertions(+), 4 deletions(-)
 create mode 100644 VERSIONS_HOTLINE/72655

diff --git a/VERSIONS_HOTLINE/72655 b/VERSIONS_HOTLINE/72655
new file mode 100644
index 00000000000..465b1dc9841
--- /dev/null
+++ b/VERSIONS_HOTLINE/72655
@@ -0,0 +1,2 @@
+ - ticket #72655 : Avis : correction de l'affichage après un ajout depuis la vue notice.
+ 
\ No newline at end of file
diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php
index 7a30d6aa066..89f4a2c4e41 100644
--- a/application/modules/opac/controllers/AbonneController.php
+++ b/application/modules/opac/controllers/AbonneController.php
@@ -177,6 +177,7 @@ class AbonneController extends ZendAfi_Controller_Action {
         $this->_user
           ->setPseudo($this->_request->getParam('avisSignature'))
           ->save();
+        $this->_helper->notify($this->_('Votre avis à bien été enregistré'));
         return $this->_redirectToReferer();
       }
 
diff --git a/library/ZendAfi/Controller/Action.php b/library/ZendAfi/Controller/Action.php
index cc7ebae462e..e9014d7ea8c 100644
--- a/library/ZendAfi/Controller/Action.php
+++ b/library/ZendAfi/Controller/Action.php
@@ -116,7 +116,6 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
   }
 
 
-
   protected function _popupJavascriptRedirectTo($url, $message = null) {
     if($message)
       $this->_helper->notify($message);
@@ -211,7 +210,7 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
     $this->getHelper('flashMessenger')
          ->addMessage([ZendAfi_Controller_Action_Helper_FlashMessenger::POPUP => ['url' => $popup_url]]);
 
-    parent::_redirect($location ? $location :$this->_getReferer());
+    parent::_redirect($location ? $location : $this->_getReferer());
     return $this;
   }
 
@@ -232,7 +231,9 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
 
 
   public function _redirectToReferer() {
-    return $this->_redirect($this->_getReferer());
+    return $this->isPopupRequest()
+      ? $this->_javascriptRedirectToReferrer()
+      : parent::_redirect($this->_getReferer());
   }
 
 
diff --git a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php
index cd7f75bc502..a1aff68f680 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerAvisTest.php
@@ -1052,7 +1052,7 @@ class AbonneControllerAddAvisNoticeAdminLoggedPostActionTest extends AbstractCon
                                     'clef_alpha' => 'GARCONNIERELA--GREMILLONH--FLAMMARION-2013-1',
                                     'type_doc' => Class_TypeDoc::LIVRE]);
 
-    $this->postDispatch('/opac/abonne/avis/id_notice/1190178',
+    $this->postDispatch('/opac/abonne/avis/id_notice/1190178/render/popup',
                         ['avisEntete' => 'bye',
                          'avisTexte' => 'ceci n\'est pas le contenu',
                          'avisNote' => 4,
@@ -1067,4 +1067,16 @@ class AbonneControllerAddAvisNoticeAdminLoggedPostActionTest extends AbstractCon
   public function avisTypeDocShouldBeBook() {
     $this->assertEquals(Class_TypeDoc::LIVRE, $this->avis->getTypeDoc());
   }
+
+
+  /** @test */
+  public function shouldRedirectWithJavascript() {
+    $this->assertXPathContentContains('//script', 'location.reload()');
+  }
+
+
+  /** @test */
+  public function shouldNotifySuccessfulSave() {
+    $this->assertFlashMessengerContentContains('Votre avis à bien été enregistré');
+  }
 }
\ No newline at end of file
-- 
GitLab