Commit 5c686919 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #69826 : implement delete bookmarked search

parent 708e3adb
Pipeline #3320 failed with stage
in 25 minutes and 35 seconds
......@@ -1245,4 +1245,26 @@ class AbonneController extends ZendAfi_Controller_Action {
return array_pop($searches);
}
public function deleteBookmarkedSearchAction() {
$this->view->titre = $this->_('Supprimer la recherche de mes favoris');
if(!$this->_user)
return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]);
if(!$search = Class_User_BookmarkedSearch::find($this->_getParam('id', 0))) {
$this->_helper->_notify($this->_('La recherche demandée est introuvable.'));
return $this->_redirectClose($this->_getReferer());
}
if(!$search->belongsTo($this->_user)) {
$this->_helper->_notify($this->_('Vous n\'avez pas les droits pour supprimer cette recherche.'));
return $this->_redirectClose($this->_getReferer());
}
$search->delete();
$this->_helper->_notify($this->_('La recherche "%s" a été supprimée.', $search->getLabel()));
return $this->_redirectClose($this->_getReferer());
}
}
\ No newline at end of file
......@@ -56,4 +56,9 @@ class Class_User_BookmarkedSearch extends Storm_Model_Abstract {
return '/recherche/simple';
return $criterias->getUrlCriteresWithFacettes();
}
public function belongsTo($user) {
return $this->getIdUser() == $user->getId();
}
}
\ No newline at end of file
......@@ -83,7 +83,7 @@ class Bookmarks_SearchAbonneBookmarkSearchDispatchTest extends Bookmarks_Search
/** @test */
public function formShouldContainsLabel() {
$this->assertXPath('//form//input[@type="text"][@name="label"]');
$this->assertXPath('//form//input[@type="text"][@name="label"]');
}
}
......@@ -173,7 +173,6 @@ class Bookmarks_SearchAbonneFicheTest extends Bookmarks_SearchWithSessionAbstrac
class Bookmarks_SearchAbonneSettingsTest extends Bookmarks_SearchWithSessionAbstract {
protected $_storm_default_to_volatile = true;
......@@ -203,14 +202,47 @@ class Bookmarks_SearchAbonneSettingsTest extends Bookmarks_SearchWithSessionAbst
$this->assertXPathContentContains('//td', 'Miles Davis');
}
/** @test */
public function tableShouldContainsDeleteButton() {
$this->assertXPath('//td//a[contains(@href,"/abonne/delete-bookmarked-search/id/5")]');
}
/** @test */
public function tableShouldContainsLinkToSearch() {
$this->assertXPath('//td//a[contains(@href,"/recherche/simple")]',$this->_response->getBody());
$this->assertXPath('//td//a[contains(@href,"/recherche/simple")]');
}
}
}
\ No newline at end of file
class Bookmarks_SearchDeleteBookmarkedSearchTest extends Bookmarks_SearchWithSessionAbstract {
protected $_storm_default_to_volatile = true;
public function setUp() {
parent::setUp();
$this->fixture('Class_User_BookmarkedSearch',
['id' => 5,
'id_user' => $this->_user->getId(),
'label' => 'Miles Davis',
'criterias' => '',
'creation_date' => '2018-01-17 15:05:57']);
$this->dispatch('/abonne/delete-bookmarked-search/id/5', true);
}
/** @test */
public function milesDavisSearchShouldHabeBeenDeleted() {
$this->assertNull(Class_User_BookmarkedSearch::find(5));
}
/** @test */
public function notifyMessageShouldBeRechercheSupprimee() {
$this->assertFlashMessengerContentContains('La recherche "Miles Davis" a été supprimée.');
}
}
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