diff --git a/VERSIONS_HOTLINE/128200 b/VERSIONS_HOTLINE/128200 new file mode 100644 index 0000000000000000000000000000000000000000..ce51880ff4465579696ebe07328fcbcd6546a866 --- /dev/null +++ b/VERSIONS_HOTLINE/128200 @@ -0,0 +1 @@ + - ticket #128200 : Gestion des favoris en résultat de recherche : correction de la fermeture / réouverture de la popup selon le résultat de la validation du formulaire \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 28eefc4e706ddb52acdbfdf261babb8c7da41faa..e1dead96884d90c6b0927ef6fe6540c3e443e542 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -1161,24 +1161,27 @@ class AbonneController extends ZendAfi_Controller_Action { public function manageSettingsAction() { - if ($this->_request->isPost() && !$this->_getParam('library_ids') - && Class_AdminVar::isModuleEnabled('ENABLE_BOOKMARKABLE_LIBRARIES')) { - $this->_helper->notify($this->_('Au moins une bibliothèque favorite doit être sélectionnée!')); - return $this->_redirectToReferer(); - } + $this->view->titre = $this->view->_('Gérer mes favoris'); + $this->view->form = $form = ZendAfi_Form_User_Settings::forUser($this->_user); - if ($this->_request->isPost()) - return $this->_saveUserPreferencesWithPost(); + if (!$this->_request->isPost()) + return; - $this->view->form = $form = ZendAfi_Form_User_Settings::forUser($this->_user); - $this->view->titre = $this->view->_('Gérer mes favoris'); + if (Class_AdminVar::isModuleEnabled('ENABLE_BOOKMARKABLE_LIBRARIES') + && + !$this->_getParam('library_ids')) + return $form + ->getElement('library_ids') + ->addError($this->_('Au moins une bibliothèque favorite doit être sélectionnée!')); + + return $this->_saveUserPreferencesWithPost(); } public function managePreferencesAction() { return $this->_request->isPost() ? $this->_saveUserPreferencesWithPost() - : $this->_redirectToReferer(); + : $this->_redirectClose($this->_getReferer()); } @@ -1191,8 +1194,7 @@ class AbonneController extends ZendAfi_Controller_Action { Class_User_Settings::clearCache(); $this->_helper->notify($this->_('Mes paramètres ont bien été sauvegardé')); - - return $this->_redirectToReferer(); + return $this->_redirectClose($this->_getReferer()); } diff --git a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php index 007149db1d0618f1177b451aeb1e8464f641c6f9..1cc9a995dc0c97ebc381cd37f4abf5b5c22e1725 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php @@ -213,12 +213,12 @@ class AbonneControllerSettingsFormTest extends AbonneControllerSettingsTestCase -class AbonneControllerSettingsFormPostTest extends AbonneControllerSettingsTestCase { +class AbonneControllerSettingsFormPostTest extends AbonneControllerSettingsTestCase { public function setUp() { parent::setUp(); - $this->fixture('Class_Bib', + $this->fixture(Class_Bib::class, ['id' => 59, 'libelle' => 'ANNECY']); @@ -242,16 +242,16 @@ class AbonneControllerSettingsFormPostTest extends AbonneControllerSettingsTestC -class AbonneControllerPreferencesFormPostTest extends AbonneControllerSettingsTestCase { +class AbonneControllerPreferencesFormPostInPopupTest extends AbonneControllerSettingsTestCase { public function setUp() { parent::setUp(); - $this->fixture('Class_Bib', + $this->fixture(Class_Bib::class, ['id' => 59, 'libelle' => 'ANNECY']); - $this->postDispatch('/abonne/manage-preferences', + $this->postDispatch('/abonne/manage-preferences/render/popup', ['library_ids' => '56', 'domain_ids' => '1-2']); } @@ -267,17 +267,30 @@ class AbonneControllerPreferencesFormPostTest extends AbonneControllerSettingsTe public function userSettingsShouldHaveBeenUpdatedWithLibs() { $this->assertEquals('MEL', $this->_user->getBookmarkedLibraries()[0]->getLibelle()); } + + + /** @test */ + public function flashMessengerShouldNotContainsPopup() { + $this->assertNotFlashMessengerPopup(); + } + + + /** @test */ + public function responseShouldNotRedirect() { + $this->assertNotRedirect(); + } } class AbonneControllerSettingsBookmarkedLibDisabledTest extends AbonneControllerSettingsTestCase { - public function setUp() { parent::setUp(); - $this->fixture('Class_Bib', + $_SERVER['HTTP_REFERER'] = '/recherche/simple'; + + $this->fixture(Class_Bib::class, ['id' => 59, 'libelle' => 'ANNECY']); @@ -288,9 +301,16 @@ class AbonneControllerSettingsBookmarkedLibDisabledTest extends AbonneController } + public function tearDown() { + unset($_SERVER['HTTP_REFERER']); + parent::tearDown(); + } + + /** @test */ public function userSettingsShouldHaveBeenUpdated() { - $this->assertEquals([$this->_music, $this->_sport], $this->_user->getBookmarkedDomains()); + $this->assertEquals([$this->_music, $this->_sport], + $this->_user->getBookmarkedDomains()); } @@ -298,9 +318,14 @@ class AbonneControllerSettingsBookmarkedLibDisabledTest extends AbonneController public function userSettingsShouldHaveBeenUpdatedWithNoLibs() { $this->assertEquals(0, count($this->_user->getBookmarkedLibraries())); } -} + /** @test */ + public function responseShouldRedirectToReferer() { + $this->assertRedirectTo('/recherche/simple'); + } +} + @@ -309,7 +334,7 @@ class AbonneControllerSettingsFormChangeTest extends AbonneControllerSettingsTes public function setUp() { parent::setUp(); - $this->fixture('Class_Bib', + $this->fixture(Class_Bib::class, ['id' => 59, 'libelle' => 'ANNECY']); @@ -319,7 +344,6 @@ class AbonneControllerSettingsFormChangeTest extends AbonneControllerSettingsTes ->setBookmarkedLibraries([56]) ->save(); - $post2 = ['library_ids' => '']; $this->postDispatch('/abonne/manage-settings', $post2); } @@ -338,12 +362,21 @@ class AbonneControllerSettingsFormChangeTest extends AbonneControllerSettingsTes /** @test */ - public function notificationShouldContainsAuMoinsUneBibliotheque() { - $this->assertFlashMessengerContentContains("Au moins une bibliothèque"); + public function pageShouldDisplayErrorAuMoinsUneBibliotheque() { + $this->assertXPathContentContains('//ul[@class="errors"]/li', + 'Au moins une bibliothèque'); + } + + + /** @test */ + public function responseShouldNotRedirect() { + $this->assertNotRedirect(); } } + + class AbonneControllerSettingsViewableDomainTest extends AbonneControllerSettingsTestCase { public function setUp() { parent::setUp();