diff --git a/VERSIONS_HOTLINE/92312 b/VERSIONS_HOTLINE/92312 new file mode 100644 index 0000000000000000000000000000000000000000..c7a16e5cf8a2b7458eb4a20a09ecf09157896941 --- /dev/null +++ b/VERSIONS_HOTLINE/92312 @@ -0,0 +1 @@ + - ticket #92312 : Favoris Utilisateurs : Interdire la suppression d'une bibliothèque si c'est la seule en favori \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index dd1feffa2639dc791f2fc03523fd5dd1aca80574..74a009166168b6707bda711ab49b2262c9e93fd7 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -1127,6 +1127,11 @@ class AbonneController extends ZendAfi_Controller_Action { $this->view->form = $form = ZendAfi_Form_User_Settings::forUser($this->_user); + if ($this->_request->isPost() && !$this->_getParam('library_ids')) { + $this->_helper->notify($this->_('Au moins une bibliothèque favorite doit être sélectionnée!')); + return; + } + if ($this->_request->isPost()) { $data = $this->_request->getPost(); unset($data['id_items']); @@ -1539,4 +1544,4 @@ class AbonneController extends ZendAfi_Controller_Action { $form->addDecorator('Errors'); } } -} \ No newline at end of file +} diff --git a/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php b/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php index 88bef4092646196d856056bbb78d5c2db3844bc9..48f18a284a0afdcd0282745aa697d4ebc90f25f5 100644 --- a/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php +++ b/library/ZendAfi/View/Helper/Notice/ExemplairesTable.php @@ -108,8 +108,13 @@ abstract class ZendAfi_View_Helper_Notice_ExemplairesTable_LibraryOrAnnex extend if(!$user = Class_Users::getIdentity()) return $this->_bookmarkLink($this->_getId()); - foreach($user->getBookmarkedLibraries() as $annex_or_lib) { + $bookmarked_libraries = $user->getBookmarkedLibraries(); + + foreach($bookmarked_libraries as $annex_or_lib) { $annex_or_lib_id = $annex_or_lib->getId(); + if (count($bookmarked_libraries)<2) + continue; + if($this->_getId() == $annex_or_lib_id) return $this->_unbookmarkLink($annex_or_lib_id); continue; diff --git a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php index 755fa014781a76da9d07b61a6951e27d811d3431..ef7c68cc7f260e3fb4bff7594858af943ac3a722 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerSettingsTest.php @@ -241,6 +241,43 @@ class AbonneControllerSettingsFormPostTest extends AbonneControllerSettingsTestC } +class AbonneControllerSettingsFormChangeTest extends AbonneControllerSettingsTestCase { + + public function setUp() { + parent::setUp(); + + $this->fixture('Class_Bib', + ['id' => 59, + 'libelle' => 'ANNECY']); + + $this->_user + ->setBookmarkedLibraries([56]) + ->save(); + + + $post2 = ['library_ids' => '']; + $this->postDispatch('/abonne/manage-settings', $post2); + } + + + /** @test */ + public function userSettingsShouldNotHaveBeenCleared() { + $this->assertEquals(1, count($this->_user->getBookmarkedLibraries())); + } + + + /** @test */ + public function userSettingsLibraryIdShouldBe56() { + $this->assertEquals(56, $this->_user->getBookmarkedLibraries()[0]->getId()); + } + + + /** @test */ + public function notificationShouldContainsAuMoinsUneBibliotheque() { + $this->assertFlashMessengerContentContains("Au moins une bibliothèque"); + } +} + class AbonneControllerSettingsViewableDomainTest extends AbonneControllerSettingsTestCase { public function setUp() { diff --git a/tests/library/Class/UsersTest.php b/tests/library/Class/UsersTest.php index 0e8c278a66950458461d50dc0e0cf3a47d7540a7..a734409c6c52988f8c0d273709d75daddb3dc28f 100644 --- a/tests/library/Class/UsersTest.php +++ b/tests/library/Class/UsersTest.php @@ -557,7 +557,7 @@ class UserGetBookmarkedLibraryTest extends ModelTestCase { 'libelle' => 'Médiathèque de Valleiry']); $annex = $this->fixture('Class_CodifAnnexe', - ['id' => 56, + ['id' => 58, 'libelle' => 'Médiathèque de Valleiry']); $this->fixture('Class_Bib', @@ -576,8 +576,8 @@ class UserGetBookmarkedLibraryTest extends ModelTestCase { /** @test */ - public function stephBookmarkedLibraryShouldBeVallery() { - $this->assertContains('56', Class_Users::find(15)->getSettings()); + public function stephBookmarkedLibraryShouldBe58() { + $this->assertContains('58', Class_Users::find(15)->getSettings()); } } diff --git a/tests/scenarios/bookmarks/LibrariesTest.php b/tests/scenarios/bookmarks/LibrariesTest.php index 543ca61aea79922da91125c1361a6455b89a7b78..545d874fb9db67cdeef80091ed9bb4b7c981f586 100644 --- a/tests/scenarios/bookmarks/LibrariesTest.php +++ b/tests/scenarios/bookmarks/LibrariesTest.php @@ -267,6 +267,21 @@ abstract class Bookmarks_LibrariesItemsTableWithAnnexTestCase extends AbstractCo +class Bookmarks_LibrariesItemsTableWithOneDefaultAnnexTest extends Bookmarks_LibrariesItemsTableWithAnnexTestCase { + + public function setUp() { + parent::setUp(); + Class_Users::find(89)->setBookmarkedLibraries([654321])->save(); + $this->buildItems(); + $this->dispatch('/noticeajax/exemplaires/id/24765'); + } + + /** @test */ + public function linkToUnbookmarkLibraryAdmoShouldBePresent() { + $this->assertNotXPath('//a[contains(@href, "/remove-library-from-bookmarks/library_id/654321")]'); + } +} + class Bookmarks_LibrariesItemsTableWithAnnexTest extends Bookmarks_LibrariesItemsTableWithAnnexTestCase { public function setUp() {