From ab0d013070db58fd83425a956e05d7b2a7311b40 Mon Sep 17 00:00:00 2001
From: llaffont <llaffont@git-test.afi-sa.fr>
Date: Tue, 4 Jun 2013 12:57:52 +0000
Subject: [PATCH] =?UTF-8?q?Fiche=20abonn=C3=A9:=20prise=20en=20charge=20mo?=
 =?UTF-8?q?de=20de=20contact=20exclusif=20(Alo=C3=A8s)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../opac/controllers/AbonneController.php     |  1 +
 library/Class/Users.php                       |  9 +++-
 .../controllers/AbonneControllerEditTest.php  | 43 ++++++++++++++++++-
 .../AbonneControllerFormationsTest.php        | 16 ++++---
 .../AbonneControllerNewslettersTest.php       |  6 ++-
 5 files changed, 64 insertions(+), 11 deletions(-)

diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php
index af56ef3a611..855bd63f660 100644
--- a/application/modules/opac/controllers/AbonneController.php
+++ b/application/modules/opac/controllers/AbonneController.php
@@ -506,6 +506,7 @@ class AbonneController extends ZendAfi_Controller_Action {
 					$this->_redirect('/abonne/fiche');
 				}
 
+				$form->addDecorator('Errors');
 				foreach($this->_user->getErrors() as $error)
 				  $form->addError($error);
 			} catch(Exception $e) {
diff --git a/library/Class/Users.php b/library/Class/Users.php
index 8475790b605..05fa08ad381 100644
--- a/library/Class/Users.php
+++ b/library/Class/Users.php
@@ -298,7 +298,7 @@ class Class_Users extends Storm_Model_Abstract {
 		switch ($mode_contact) {
 		case self::MODE_CONTACT_MAIL: $this->setIsContactMail(true)->setIsContactSms(false); break;
 		case self::MODE_CONTACT_SMS: $this->setIsContactMail(false)->setIsContactSms(true); break;
-		default: $user->setIsContactMail(false)->setIsContactSms(false);
+		default: $this->setIsContactMail(false)->setIsContactSms(false);
 		}
 		return $this;
 	}
@@ -622,6 +622,13 @@ class Class_Users extends Storm_Model_Abstract {
 
 		$this->check($this->hasRightDirigerFormation() or (count($this->getSessionInterventions()) === 0),
 								 $this->_translate->_('Vous n\'avez pas les droits suffisants pour diriger une formation'));
+
+
+		$this->check(($this->getMail() || !$this->getIsContactMail()),
+								 $this->_translate->_('Vous devez fournir une adresse mail valide'));
+
+		$this->check(($this->getTelephone() || !$this->getIsContactSms()),
+								 $this->_translate->_('Vous devez saisir un numéro de téléphone'));
 	}
 
 
diff --git a/tests/application/modules/opac/controllers/AbonneControllerEditTest.php b/tests/application/modules/opac/controllers/AbonneControllerEditTest.php
index 2544d6eb37c..caa1912c139 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerEditTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerEditTest.php
@@ -52,7 +52,7 @@ class AbonneControllerEditWithContactMailSmsPostTest extends AbonneControllerEdi
 		parent::setUp();
 
 		Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', 
-																			['valeur' => 'prenom;mode_contact;telephone']);
+																			['valeur' => 'prenom;mode_contact;telephone;mail']);
 
 		$this->postDispatch('/abonne/edit',
 												['telephone' => '12 34 56',
@@ -82,7 +82,8 @@ class AbonneControllerEditWithContactMailSmsPostTest extends AbonneControllerEdi
 
 	/** @test */
 	public function userShouldBeSaved() {
-		$this->assertTrue(Class_Users::methodHasBeenCalled('save'), implode(',', $this->_jerome->getErrors()));
+		$this->assertTrue(Class_Users::methodHasBeenCalled('save'), 
+											implode(',', $this->_jerome->getErrors()));
 	}
 
 	/** @test */
@@ -94,6 +95,44 @@ class AbonneControllerEditWithContactMailSmsPostTest extends AbonneControllerEdi
 
 
 
+class AbonneControllerEditWithContactMailPostErrorsTest extends AbonneControllerEditActionWithAbonneSIGBTestCase {
+	/** @test */
+	public function pageShouldDisplayErrorNoMailProvided() {
+
+		Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', 
+																			['valeur' => 'prenom;mode_contact;telephone;mail']);
+
+		$this->postDispatch('/abonne/edit',
+												['telephone' => '12 34 56',
+												 'mail' => '',
+												 'mode_contact' => 'is_contact_mail',
+												 'prenom' => 'Marcel',
+												 'nom' => 'Mazout']);
+
+		$this->assertXPathContentContains('//ul[@class="errors"]//li', 
+																			'Vous devez fournir une adresse mail valide');
+	}
+
+
+	/** @test */
+	public function pageShouldDisplayErrorNoTelephoneProvided() {
+		Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', 
+																			['valeur' => 'prenom;mode_contact;telephone']);
+
+		$this->postDispatch('/abonne/edit',
+												['telephone' => '',
+												 'mode_contact' => 'is_contact_sms',
+												 'prenom' => 'Marcel',
+												 'nom' => 'Mazout']);
+
+		$this->assertXPathContentContains('//ul[@class="errors"]//li', 
+																			'Vous devez saisir un numéro de téléphone');
+	}
+}
+
+
+
+
 class AbonneControllerEditWithContactMailSmsTest extends AbonneControllerEditActionWithAbonneSIGBTestCase {
 	public function setUp() {
 		parent::setUp();
diff --git a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php
index d67621d642f..eae90106e4f 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerFormationsTest.php
@@ -237,40 +237,40 @@ class AbonneControllerFormationsListTest extends AbstractAbonneControllerFormati
 
 	/** @test */
 	function session_fevrier_17_ShouldBeDisplayedUnderLearnJavaInSecondPosition() {
-		$this->assertXPathContentContains('//tr[2]//td', '17 février 2022 au 19 février 2022', $this->_response->getBody());
+		$this->assertXPathContentContains('//tbody//tr[2]//td', '17 février 2022 au 19 février 2022', $this->_response->getBody());
 	}
 
 
 	/** @test */
 	function session_fevrier_17_lieuBonlieuShouldBeDisplayed() {
-		$this->assertXPathContentContains('//tr[2]//td', 'Bonlieu');
+		$this->assertXPathContentContains('//tbody//tr[2]//td', 'Bonlieu');
 	}
 
 
 	/** @test */
 	function session_fevrier_17_ShouldHaveLinkForInscrire() {
-		$this->assertXPathContentContains('//tr[2]//a[contains(@href, "abonne/inscrire_session/id/31")]',
+		$this->assertXPathContentContains('//tbody//tr[2]//a[contains(@href, "abonne/inscrire_session/id/31")]',
 																			"S'inscrire");
 	}
 
 
 	/** @test */
 	function session_fevrier_17_ShouldDisplayDateLimite15Fevrier() {
-		$this->assertXPathContentContains('//tr[2]',
+		$this->assertXPathContentContains('//tbody//tr[2]',
 																			"Limite: 15 février 2022");
 	}
 
 
 	/** @test */
 	function session_fevrier_17_ShouldHaveLinkForDetailSessionFormation() {
-		$this->assertXPathContentContains('//tr[2]//a[contains(@href, "abonne/detail_session/id/31")]', 
+		$this->assertXPathContentContains('//tbody//tr[2]//a[contains(@href, "abonne/detail_session/id/31")]', 
 																			'Détails de la session');
 	}
 
 
 	/** @test */
 	function session_mars_27_ShouldBeDisplayedUnderLearnJavaInFirstPosition() {
-		$this->assertXPathContentContains('//tr[1]', '27 mars 2022');
+		$this->assertXPathContentContains('//tbody//tr[1]', '27 mars 2022');
 	}
 
 
@@ -440,6 +440,8 @@ abstract class AbonneControllerFormationsSessionJavaFevrierFullTestCase extends
 class AbonneControllerFormationsSessionJavaFevrierFullListTest extends AbonneControllerFormationsSessionJavaFevrierFullTestCase {
 	public function setUp() {
 		parent::setUp();
+		Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', 
+																			['valeur' => 'pseudo;nom;prenom;mail']);
 		$this->dispatch('/opac/abonne/formations');
 	}
 
@@ -452,7 +454,7 @@ class AbonneControllerFormationsSessionJavaFevrierFullListTest extends AbonneCon
 
 	/** @test */
 	public function sessionShouldDisplayFull() {
-		$this->assertXPathContentContains('//tr[2]//span', 'Effectif maximum atteint');
+		$this->assertXPathContentContains('//tbody//tr[2]//span', 'Effectif maximum atteint');
 	}
 }
 
diff --git a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php
index 3ab38128a1a..d3a239295e2 100644
--- a/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php
+++ b/tests/application/modules/opac/controllers/AbonneControllerNewslettersTest.php
@@ -30,6 +30,10 @@ abstract class AbstractAbonneControllerNewslettersTestCase extends AbstractContr
 	}
 
 	public function setUp() {
+		Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', 
+																			['valeur' => 'pseudo;nom;prenom;mail;password']);
+
+
 		$this->marcus = Class_Users::getLoader()->newInstanceWithId(10)
 			->setPrenom('Marcus')
 			->setNom('Miller')
@@ -457,7 +461,7 @@ class AbonneControllerNewslettersValidationsTest extends AbonneControllerWithTwo
 			->setMethod('POST')
 			->setPost($data);
 
-		$this->dispatch('/opac/abonne/edit');
+		$this->dispatch('/opac/abonne/edit', true);
 		$this->assertAction('edit');
 	}
 
-- 
GitLab