Commit 685bfae0 authored by Henri-Damien LAURENT's avatar Henri-Damien LAURENT
Browse files

hotline#92312 : UserSettings : Prevent last library to be deleted from Settings

parent 91632d18
Pipeline #7381 passed with stage
in 36 minutes and 36 seconds
- ticket #92312 : Favoris Utilisateurs : Interdire la suppression d'une bibliothèque si c'est la seule en favori
\ No newline at end of file
......@@ -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
}
......@@ -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;
......
......@@ -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() {
......
......@@ -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());
}
}
......
......@@ -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() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment