diff --git a/.gitattributes b/.gitattributes index e5df418c8d6ad47a2c7a2b3927d3728c5955ab93..5f73540234676ac94882942b51204d85c640fe18 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6116,6 +6116,7 @@ tests/library/ZendAfi/Form/Element/ImageDeleteTest.php -text tests/library/ZendAfi/Form/Element/ImageTest.php -text tests/library/ZendAfi/TranslateTest.php -text tests/library/ZendAfi/Validate/IsbnTest.php -text +tests/library/ZendAfi/Validate/PhoneNumberTest.php -text tests/library/ZendAfi/View/Helper/Abonne/AbonnementTest.php -text tests/library/ZendAfi/View/Helper/Abonne/ResumeTest.php -text tests/library/ZendAfi/View/Helper/Accueil/BibNumeriqueTest.php -text diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 8442e30552589be6e4ebc54487fdcb1aef4058b5..c18fc1b0cd7396692670cf155b0c571c82c78921 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -393,6 +393,10 @@ class AbonneController extends ZendAfi_Controller_Action { if ($mail_element = $form->getElement('mail')) $mail_element->addValidator(new ZendAfi_Validate_EmailAddress()); + if ($phone_element = $form->getElement('telephone')) + $phone_element->addValidator(new ZendAfi_Validate_PhoneNumber()); + + if (in_array('password', $fields_to_show)) { $fields_to_show []= 'confirm_password'; $new_password = new Zend_Form_Element_Password('password'); diff --git a/tests/application/modules/opac/controllers/AbonneControllerEditTest.php b/tests/application/modules/opac/controllers/AbonneControllerEditTest.php index 231c906d6c2fa096794e583e615ba67f4f2dea86..18587d65831eff246bede2c950c281cb0856f778 100644 --- a/tests/application/modules/opac/controllers/AbonneControllerEditTest.php +++ b/tests/application/modules/opac/controllers/AbonneControllerEditTest.php @@ -98,7 +98,23 @@ 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 78 98', + '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 pageShouldDisplayErrorInvalidPhone() { Class_AdminVar::newInstanceWithId('CHAMPS_FICHE_UTILISATEUR', ['valeur' => 'prenom;mode_contact;telephone;mail']); @@ -110,7 +126,7 @@ class AbonneControllerEditWithContactMailPostErrorsTest extends AbonneController 'nom' => 'Mazout']); $this->assertXPathContentContains('//ul[@class="errors"]//li', - 'Vous devez fournir une adresse mail valide'); + "'12 34 56' n'est pas un numÊro de tÊlÊphone"); } @@ -143,7 +159,7 @@ class AbonneControllerEditWithContactMailPostErrorsTest extends AbonneController 'nom' => 'Mazout']); $this->assertXPathContentContains('//ul[@class="errors"]//li', - "'glouglou' n'est pas un courriel valide", + "'glouglou' n'est pas un email valide", $this->_response->getBody()); } diff --git a/tests/library/ZendAfi/Validate/PhoneNumberTest.php b/tests/library/ZendAfi/Validate/PhoneNumberTest.php new file mode 100644 index 0000000000000000000000000000000000000000..12ffb7695841b72686fa5a19e8f1c1739dc0fe12 --- /dev/null +++ b/tests/library/ZendAfi/Validate/PhoneNumberTest.php @@ -0,0 +1,66 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class ZendAfi_Validate_PhoneNumberTest extends PHPUnit_Framework_TestCase { + public function setUp() { + $this->_validator = new ZendAfi_Validate_PhoneNumber(); + } + + + public function validPhoneNumbers() { + return [ + ['06 12 34 87 98'], + ['0612348798'], + ['+33-6-12-34-87-98'], + ['(33) 6 12 348 798'], + ['06/12/34/87/98'] + ]; + } + + + public function invalidPhoneNumbers() { + return [ ['234'], + ['23-98,34'], + ['123456789012345678901'], + ['23 (98) 06 18 34'], + ['xz'] ]; + } + + + /** + * @test + * @dataProvider validPhoneNumbers + */ + public function phoneShouldBeValid($phone) { + $this->assertTrue($this->_validator->isValid($phone)); + } + + + /** + * @test + * @dataProvider invalidPhoneNumbers + */ + public function phonehouldNotBeValid($phone) { + $this->assertFalse($this->_validator->isValid($phone)); + } +} + +?> \ No newline at end of file