Commit 4485e824 authored by Laurent's avatar Laurent
Browse files

dev #48981 multi cards: handles unlink errors

parent 560ea761
......@@ -1070,30 +1070,46 @@ class AbonneController extends ZendAfi_Controller_Action {
public function unlinkCardAction() {
$child = Class_Users::find((int)$this->_getParam('id'));
$lc = Class_LinkedCard::findFirstBy(['parent_id' => $this->_user->getId(),
'child_id' => $child->getId()]);
$lc->delete();
$this->_helper->notify($this->_('Vous n\'utilisez plus la carte de %s',
$child->getNomComplet()));
$this->_redirect('/abonne/cards');
return $this->_unlinkCard(['parent_id' => $this->_user->getId(),
'child_id' => (int)$this->_getParam('id')],
function($child)
{
return $this->_('Vous n\'utilisez plus la carte de %s',
$child->getNomComplet());
});
}
public function unlinkParentCardAction() {
$parent = Class_Users::find((int)$this->_getParam('id'));
return $this->_unlinkCard(['parent_id' => (int)$this->_getParam('id'),
'child_id' => $this->_user->getId()],
function($parent)
{
return $this->_('Votre carte a été retirée à %s',
$parent->getNomComplet());
});
}
$lc = Class_LinkedCard::findFirstBy(['parent_id' => $parent->getId(),
'child_id' => $this->_user->getId()]);
protected function _unlinkCard($params, $message_callback) {
if (!$user = Class_Users::find((int)$this->_getParam('id')))
return $this->_unlinkResponseNotFound();
if (!$lc = Class_LinkedCard::findFirstBy($params))
return $this->_unlinkResponseNotFound();
$lc->delete();
$this->_unlinkResponseDone($message_callback($user));
}
protected function _unlinkResponseNotFound() {
return $this->_unlinkResponseDone($this->_('Carte introuvable'));
}
$this->_helper->notify($this->_('Votre carte a été retirée à %s',
$parent->getNomComplet()));
protected function _unlinkResponseDone($message) {
$this->_helper->notify($message);
$this->_redirect('/abonne/cards');
}
......
......@@ -752,3 +752,43 @@ class Scenario_AbonneMultiCardsLukeWithParentCardUnlinkActionTest extends Scenar
$this->assertFlashMessengerContentContains('Votre carte a été retirée à darky');
}
}
class Scenario_AbonneMultiCardsErrorsOnUnlinkActionsTest extends Scenario_AbonneMultiCardsTestCase {
public function setUp() {
parent::setUp();
ZendAfi_Auth::getInstance()->logUser(Class_Users::find(1));
}
/** @test */
public function unlinkCardWithUnexistingUserIdShouldDisplayError() {
$this->dispatch('/abonne/unlink-card/id/345', true);
$this->assertFlashMessengerContentContains('Carte introuvable');
}
/** @test */
public function unlinkCardWithUnexistingRelationShouldDisplayError() {
$this->dispatch('/abonne/unlink-card/id/1', true);
$this->assertFlashMessengerContentContains('Carte introuvable');
}
/** @test */
public function unlinkParentCartWithUnexistingUserIdShouldDisplayError() {
$this->dispatch('/abonne/unlink-parent-card/id/345', true);
$this->assertFlashMessengerContentContains('Carte introuvable');
}
/** @test */
public function unlinkParentCartWithUnexistingRelationShouldDisplayError() {
$this->dispatch('/abonne/unlink-parent-card/id/1', true);
$this->assertFlashMessengerContentContains('Carte introuvable');
}
}
\ No newline at end of file
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