diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 5e31291e51e2bc7d92bf9a54839eaea6506a4496..bfd756e0233dec41cddfeb03f37d193a09f3884f 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -492,17 +492,24 @@ class AbonneController extends ZendAfi_Controller_Action { if (empty($password)) $password = $this->_user->getPassword(); + $this->_user->updateSIGBOnSave(); + + $fields_to_save = Class_AdminVar::getChampsFicheUtilisateur(); + $attributes = []; + foreach($fields_to_save as $field) + $attributes[$field] = $this->_request->getParam($field); + $this->_user - ->updateSIGBOnSave() - ->setNom($this->_request->getParam('nom')) - ->setPrenom($this->_request->getParam('prenom')) - ->setMail($this->_request->getParam('mail')) - ->setPseudo($this->_request->getParam('pseudo')) - ->setPassword($password) - ->setNewsletters($newsletters) - ->save(); + ->updateAttributes($attributes) + ->setPassword($password) + ->setNewsletters($newsletters); + + if ($this->_user->save()) { + $this->_redirect('/abonne/fiche'); + } - $this->_redirect('/abonne/fiche'); + foreach($this->_user->getErrors() as $error) + $form->addError($error); } catch(Exception $e) { $form->addError($e->getMessage()); $form->addDecorator('Errors'); diff --git a/library/Class/Profil.php b/library/Class/Profil.php index 549bc838b1109e7e021f40cc7568dcf32caa26c9..b4c2f6a5cb91a01213d0ffdc28c1bc4e8de1ddf2 100644 --- a/library/Class/Profil.php +++ b/library/Class/Profil.php @@ -1010,7 +1010,8 @@ class Class_Profil extends Storm_Model_Abstract { $cfg_accueil = $this->getCfgAccueilAsArray(); $boites = array(); - foreach ($cfg_accueil['modules'] as $id => $module) { + $modules = $cfg_accueil['modules'] ? $cfg_accueil['modules'] : []; + foreach ($modules as $id => $module) { if (!$module) $module = array(); $module = array_merge(array('type_module' => null, 'preferences' => array()), diff --git a/library/Class/WebService/SIGB/Emprunteur.php b/library/Class/WebService/SIGB/Emprunteur.php index ce1803bcad111ff16672be7e7b07420f3e0dfa7f..fa38d6a6d2754b568dcbf6eac1aedf09cf586664 100644 --- a/library/Class/WebService/SIGB/Emprunteur.php +++ b/library/Class/WebService/SIGB/Emprunteur.php @@ -575,7 +575,10 @@ class Class_WebService_SIGB_Emprunteur { ->setNom($user->getNom()) ->setPrenom($user->getPrenom()) ->setEMail($user->getMail()) - ->setPassword($user->getPassword()); + ->setPassword($user->getPassword()) + ->setTelephone($user->getTelephone()) + ->setIsContactSms($user->getIsContactSms()) + ->setIsContactEmail($user->getIsContactMail()); if (!$this->_service) $this->_service = $user->getSIGBComm(); diff --git a/library/Class/WebService/SIGB/Opsys/Service.php b/library/Class/WebService/SIGB/Opsys/Service.php index 81d25793e40ad5dbf0ea81939ae2c5991810e18b..c94c65b6fea3a7243ad338a5667fc6d5e8c56c52 100644 --- a/library/Class/WebService/SIGB/Opsys/Service.php +++ b/library/Class/WebService/SIGB/Opsys/Service.php @@ -141,7 +141,6 @@ class Class_WebService_SIGB_Opsys_Service extends Class_WebService_SIGB_Abstract return $emprunteur; $entite_result = $this->search_client->EmprListerEntite(EmprListerEntite::infos($this->guid)); - if ($date_fin_abonnement = $entite_result->findAttribute('FinAbo')) { $date_fin_abonnement = implode('-', array_reverse(explode('/', $date_fin_abonnement))); $emprunteur->setEndDate($date_fin_abonnement); @@ -156,9 +155,13 @@ class Class_WebService_SIGB_Opsys_Service extends Class_WebService_SIGB_Abstract if ($is_contact_email = $entite_result->findAttribute('Contacter par email')) $emprunteur->setIsContactEmail($is_contact_email == '1'); - return $emprunteur - ->setNom($entite_result->findAttribute('nom')) - ->setPrenom($entite_result->findAttribute('prenom')); + $emprunteur->setNom($entite_result->findAttribute('nom')); + + if (!$prenom = $entite_result->findAttribute('prenom')) + $prenom = $entite_result->findAttribute('Prénom'); + + $emprunteur->updateUser($user); + return $emprunteur; } @@ -1650,8 +1653,6 @@ class MaNotice { public $Champs; // ArrayOfImportChamp public function __construct() { - // $this->Champs = new StdClass(); - // $this->Champs->ImportChamp = array(); $this->Champs = array(); } @@ -1664,12 +1665,12 @@ class MaNotice { $this ->addChamp('115') ->addSousChamp('115$e', $emprunteur->getEmail()) - ->addSousChamp('115$x', $emprunteur->isContactEmail()); + ->addSousChamp('115$x', $emprunteur->isContactEmail() ? '1' : '0'); $this ->addChamp('119') ->addSousChamp('119$a', $emprunteur->getTelephone()) - ->addSousChamp('119$x', $emprunteur->isContactSms()); + ->addSousChamp('119$x', $emprunteur->isContactSms() ? '1' : '0'); $this ->addChamp('120') @@ -1680,7 +1681,6 @@ class MaNotice { public function addChamp($etiquette) { $champ = new ImportChamp(); $champ->setEtiquette($etiquette); - // $this->Champs->ImportChamp []= $champ; $this->Champs []= $champ; return $champ; } diff --git a/tests/application/modules/opac/controllers/AbonneControllerEditTest.php b/tests/application/modules/opac/controllers/AbonneControllerEditTest.php index 8a65db94bb5465e4314b1fc98387bb18c8c22bcc..29a11fab3ad428fc29ae63dcd4949c33f7faa962 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerEditTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerEditTest.php @@ -26,9 +26,64 @@ abstract class AbonneControllerEditActionWithAbonneSIGBTestCase extends Abstract public function setUp() { parent::setUp(); - $this->_jerome = Class_Users::newInstanceWithId(4, ['prenom' => 'Jerome', - 'is_contact_sms' => true])->beAbonneSIGB(); + $this->_jerome = Class_Users::newInstanceWithId(4, ['login' => 'jm', + 'prenom' => 'Jerome', + 'is_contact_sms' => true, + 'idabon' => '12345', + 'id_site' => 1, + 'password' => 'secret'])->beAbonneSIGB(); ZendAfi_Auth::getInstance()->logUser($this->_jerome); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Users') + ->whenCalled('save') + ->answers(true); + + } +} + + + + +class AbonneControllerEditWithContactMailSmsPostTest extends AbonneControllerEditActionWithAbonneSIGBTestCase { + public function setUp() { + parent::setUp(); + + Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', + ['valeur' => 'prenom;is_contact_mail;is_contact_sms;telephone']); + + $this->postDispatch('/abonne/edit', + ['telephone' => '12 34 56', + 'is_contact_mail' => true, + 'prenom' => 'Marcel', + 'nom' => 'Mazout']); + } + + + /** @test */ + public function telephoneShouldBe123456() { + $this->assertEquals('12 34 56', $this->_jerome->getTelephone()); + } + + + /** @test */ + public function nomShouldStayEmpty() { + $this->assertEquals('', $this->_jerome->getNom()); + } + + + /** @test */ + public function isContactByMailShouldBeTrue() { + $this->assertTrue($this->_jerome->getIsContactMail()); + } + + /** @test */ + public function userShouldBeSaved() { + $this->assertTrue(Class_Users::methodHasBeenCalled('save'), implode(',', $this->_jerome->getErrors())); + } + + /** @test */ + public function responseShouldRedirectToFiche() { + $this->assertRedirectTo('/abonne/fiche'); } }