Commit 07a9ea20 authored by Laurent's avatar Laurent
Browse files

dev #48981 multi cards: handle user save failure in add card process

parent 7804fb54
......@@ -1139,6 +1139,7 @@ class AbonneController extends ZendAfi_Controller_Action {
if ((!$child = Class_Users::findFirstBy(['login' => $this->_getPost('login'),
'password' => $this->_getPost('password')]))
|| !$child->isAbonne()) {
$this->_helper->notify($this->_('Identifiant et/ou mot de passe incorrect'));
return $this->_redirect('/abonne/add-card');
}
......@@ -1155,13 +1156,16 @@ class AbonneController extends ZendAfi_Controller_Action {
return $this->_redirect('/abonne/add-card');
}
$this->_user
->addChildCard($child)
->save();
if($this->_user->addChildCard($child)->save()) {
$this->_helper->notify($this->_('Carte de "%s" ajoutée',
$child->getNomComplet()));
return $this->_javascriptRedirectToReferrer();
}
$this->_helper->notify($this->_('Une erreur s\'est produite en ajoutant la carte de "%s" : %s',
$child->getNomComplet(),
implode(' ', $this->_user->getErrors())));
$this->_redirect('/abonne/add-card');
$this->_helper->notify($this->_('Carte de "%s" ajoutée',
$child->getNomComplet()));
}
......
......@@ -357,6 +357,19 @@ class Scenario_AbonneMultiCardsImpossiblePostActionTest extends Scenario_AbonneM
ZendAfi_Auth::getInstance()->logUser(Class_Users::find(1));
}
/** @test */
public function addWithCorruptedUserShouldReturnError() {
$user = Class_Users::getIdentity();
$user->setPassword(null);
$user->saveWithoutValidation();
$this->postDispatch('/abonne/add-card',
['login' => 'luke',
'password' => 'ilovelightsabers']);
$this->assertFlashMessengerContentContains('Une erreur s\'est produite en ajoutant la carte de "Luke Skywalker" : Vous devez compléter le champ \'Mot de passe\'');
}
/** @test */
public function darkyShouldNotAddHimself() {
......
......@@ -472,7 +472,7 @@ class Bookmarks_LibrariesAbonneControllerRemoveLibraryFromBookmarksTest extends
/** @test */
public function userShouldHaveOnlyOneBookmarkedLybrary() {
public function userShouldHaveOnlyOneBookmarkedLibrary() {
$this->assertCount(1, Class_Users::getIdentity()->getBookmarkedLibraries());
}
}
\ 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