Skip to content
Snippets Groups Projects
Commit aad7cfe1 authored by llaffont's avatar llaffont
Browse files

Un panier partagé n'apparaît qu'une seule fois dans la liste

On ne peut pas supprimer un panier qui ne nous appartient pas
parent aca7a8ad
Branches
Tags
No related merge requests found
......@@ -94,7 +94,8 @@ function indexAction() {
// Suppression d'un panier
//------------------------------------------------------------------------------------------------------
function supprimerpanierAction() {
if ($panier = Class_PanierNotice::find($this->_getParam('id_panier'))) {
if (($panier = Class_PanierNotice::find($this->_getParam('id_panier')))
&& $panier->isUserEquals($this->_user)) {
$panier->delete();
$this->_helper->notify($this->_("Panier %s supprimé", $panier->getLibelle()));
}
......@@ -107,15 +108,15 @@ function indexAction() {
//------------------------------------------------------------------------------------------------------
function panierajouternoticeAction() {
if (!$panier = Class_PanierNotice::find($this->_getParam('id_panier'))) {
$id_panier = Class_PanierNotice::maxIdPanierForUser(Class_Users::getIdentity()) + 1;
$id_panier = Class_PanierNotice::maxIdPanierForUser($this->_user) + 1;
$panier = (new Class_PanierNotice())
->setUser($this->_user)
->setLibelle($this->_('Panier no %d', $id_panier))
->setIdPanier($id_panier);
}
if ($notice = Class_Notice::find($this->_getParam('id_notice'))) {
$panier
->setUser(Class_Users::getIdentity())
->addNotice($notice)
->save();
......
......@@ -44,9 +44,9 @@ class PanierNoticeLoader extends Storm_Model_Loader {
public function findAllWithCatalogue() {
return array_map(
function($association) {return $association->getPanierNotice();},
Class_PanierNoticeCatalogue::findAll());
return array_unique(array_map(
function($association) {return $association->getPanierNotice();},
Class_PanierNoticeCatalogue::findAll()));
}
}
......
......@@ -30,7 +30,7 @@ abstract class PanierControllerTestCase extends AbstractControllerTestCase {
public function setUp() {
$this->manon = Class_Users::newInstanceWithId(23, ['pseudo' => 'ManonL']);
$this->manon = Class_Users::newInstanceWithId(23, ['pseudo' => 'ManonL', 'nom' => 'Afond']);
parent::setUp();
......@@ -93,8 +93,9 @@ abstract class PanierControllerTestCase extends AbstractControllerTestCase {
->setCatalogue(Class_Catalogue::newInstanceWithId(97, ['libelle' => 'histoire']));
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_PanierNoticeCatalogue')
->whenCalled('findAll')
->answers([$panier_domaine_histoire]);
->whenCalled('save')->answers(true)
->whenCalled('findAll')->answers([$panier_domaine_histoire,
$panier_domaine_histoire]);
}
}
......@@ -154,7 +155,7 @@ class PanierControllerIndexAsRedacteurActionTest extends PanierControllerTestCas
/** @test */
public function panierDomaineHistoireShouldBeVisible() {
$this->assertXPathContentContains('//td', 'selection jeunesse');
$this->assertXPathCount('//td//a[contains(text(), "selection jeunesse")]', 1);
}
......@@ -269,6 +270,22 @@ class PanierControllerSupprimerBDTest extends PanierControllerTestCase {
class PanierControllerSupprimerPanierDomaineHistoireTest extends PanierControllerTestCase {
public function setUp() {
parent::setUp();
$this->dispatch('/panier/supprimerpanier/id_panier/38', true);
}
/** @test */
public function panierShouldNotHaveBeenDeleted() {
$this->assertFalse(Class_PanierNotice::methodHasBeenCalled('delete'));
}
}
class PanierControllerAjoutNoticeBlackSadToUndefinedPanierTest extends PanierControllerTestCase {
protected $_new_panier;
......@@ -366,6 +383,29 @@ class PanierControllerAjoutNoticeBlackSadToPanierMesRomansTest extends PanierCon
class PanierControllerAjoutNoticeBlackSadToPanierDomaineHistoireTest extends PanierControllerTestCase {
public function setUp() {
parent::setUp();
$this->manon->changeRoleTo(ZendAfi_Acl_AdminControllerRoles::MODO_PORTAIL);
$this->dispatch('/panier/panierajouternotice/id_panier/38/id_notice/12', true);
}
/** @test */
public function panierShouldHaveBeenSaved() {
$this->assertTrue(Class_PanierNotice::methodHasBeenCalled('save'));
}
/** @test */
public function panierUserShouldStillBeDupont() {
$this->assertEquals('Dupont', Class_PanierNotice::find(38)->getUser()->getNom());
}
}
class PanierControllerModifierTitrePanierMesRomansToMesLivresTest extends PanierControllerTestCase {
public function setUp() {
parent::setUp();
......
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