Commit 16a26eb2 authored by Laurent's avatar Laurent
Browse files

dev #48981 linked cards: add delete action

parent ba8471e9
......@@ -1054,8 +1054,21 @@ class AbonneController extends ZendAfi_Controller_Action {
public function cardsAction() {
$this->view->titre = $this->_('Mes cartes');
$this->view->child_cards = ($this->_user->isAbonne() ? [$this->_user] : [])
+ $this->_user->getChildCards();;
$child_cards = $this->_user->getChildCards();
if ($this->_user->isAbonne())
array_unshift($child_cards, $this->_user);
$this->view->child_cards = $child_cards;
}
public function unlinkCardAction() {
$lc = Class_LinkedCard::findFirstBy(['parent_id' => $this->_user->getId(),
'child_id' => $this->_getParam('id')]);
xdebug_break();
$lc->delete();
$this->_redirect('/abonne/cards');
}
......
......@@ -9,7 +9,12 @@ echo $this->child_cards
'nom',
'prenom',
'subscription_end'],
[],
[ function($user) {
if ($user->getId() == Class_Users::getIdentity()->getId())
return '';
return $this->tagAnchor(['action' => 'unlink-card', 'id' => $user->getId()],
$this->boutonIco('type=del'));
} ],
'child_cards',
null,
['login' => function($user) {
......
......@@ -121,6 +121,12 @@ class Scenario_AbonneMultiCardsCardsActionTest extends Scenario_AbonneMultiCards
public function darkyCardShouldBeInCardList() {
$this->assertXPathContentContains('//table//td', 'darky (ma carte)');
}
/** @test */
public function darkyShouldNotHaveUnlinkLink() {
$this->assertNotXPath('//table//td//a[contains(@href, "unlink-card")]');
}
}
......@@ -180,6 +186,12 @@ class Scenario_AbonneMultiCardsWithCardsActionTest extends Scenario_AbonneMultiC
}
/** @test */
public function lukeShouldHaveUnlinkLink() {
$this->assertXPath('//table//td//a[contains(@href, "abonne/unlink-card/id/2")]');
}
/** @test */
public function noParagraphShouldContainsNoLinkedCardsMessage() {
$this->assertNotXPathContentContains('//p', 'Vous n\'avez ajouté aucune carte');
......@@ -223,6 +235,33 @@ class Scenario_AbonneMultiCardsAddCardActionTest extends Scenario_AbonneMultiCar
class Scenario_AbonneMultiCardsWithCardsUnlinkActionTest extends Scenario_AbonneMultiCardsTestCase {
public function setUp() {
parent::setUp();
Class_Users::getIdentity()
->addChildCard(Class_Users::find(2))
->save();
$this->dispatch('/abonne/unlink-card/id/2', true);
}
/** @test */
public function lukeShouldNoLongerBeLinkedToDarky() {
$this->assertEmpty(Class_LinkedCard::findAll());
}
/** @test */
public function responseShouldRedirectToCards() {
$this->assertRedirectTo('/abonne/cards');
}
}
class Scenario_AbonneMultiCardsAddCardPostActionTest extends Scenario_AbonneMultiCardsTestCase {
public function setUp() {
parent::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