Skip to content
Snippets Groups Projects
Commit 95ddbe94 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'hotline#121676_preinscriptions_par_robots' into 'hotline'

hotline #121676 Nanook / Koha pre-registration : check birth date input field format

See merge request !3768
parents 42916479 7c362685
Branches
Tags
2 merge requests!3782Hotline,!3768hotline #121676 Nanook / Koha pre-registration : check birth date input field format
Pipeline #11905 passed with stage
in 59 minutes and 44 seconds
- ticket #121676 : Nanook / Koha : formulaire de pré-inscriptions : vérification du format de la date de naissance
\ No newline at end of file
......@@ -41,10 +41,9 @@ class ZendAfi_Form_PreRegistration_Koha extends ZendAfi_Form {
['label' => $this->_('Prénom'),
'required' => true])
->addElement('datePicker',
->addElement('date',
'dateofbirth',
['label' => $this->_('Date de naissance'),
'DateFormat' => 'dd-MM-YYYY'])
['label' => $this->_('Date de naissance')])
->addElement('text',
'streetnumber',
......
......@@ -72,11 +72,10 @@ class ZendAfi_Form_PreRegistration_Nanook extends ZendAfi_Form {
'autocomplete' => 'mew-password',
'validators' => [new ZendAfi_Validate_PasswordEquals('password')]])
->addElement('datePicker',
->addElement('date',
'birthDate',
['label' => $this->_('Date de naissance'),
'required' => true,
'DateFormat' => 'YYYY-MM-dd',
'allowEmpty' => false])
->addElement('text',
......
......@@ -21,7 +21,11 @@
class ZendAfi_Validate_DateFormat extends Zend_Validate_Abstract {
protected $_format = 'Y-m-d';
const INVALID_DATE = 'invalidDate';
protected
$_messageTemplates = [self::INVALID_DATE => "'%value%' n'est pas une date au format attendu"],
$_format = 'Y-m-d';
public function setFormat($format) {
$this->_format = $format;
......@@ -33,7 +37,13 @@ class ZendAfi_Validate_DateFormat extends Zend_Validate_Abstract {
if (!$string)
return false;
$this->_setValue($string);
$date = DateTime::createFromFormat($this->_format, $string);
return $date && ($date->format($this->_format) === $string);
if ($date && ($date->format($this->_format) === $string))
return true;
$this->_error(self::INVALID_DATE);
return false;
}
}
\ No newline at end of file
......@@ -125,7 +125,7 @@ abstract class AuthControllerPreRegistrationKohaPostDispatchTestCase extends Aut
array_merge ($values, ['branchcode' => '41|GRA',
'surname' => 'Boulard',
'firstname' => 'Thom',
'dateofbirth' => '15-09-1940',
'dateofbirth' => '1940-09-15',
'streetnumber' => '10',
'address' => 'rue secret',
'zipcode' => '01630',
......@@ -166,8 +166,9 @@ class AuthControllerPreRegistrationKohaPostDispatchTest extends AuthControllerPr
class AuthControllerPreRegistrationKohaWithRequiredCondtionChecked extends AuthControllerPreRegistrationKohaPostDispatchTestCase {
protected $_required_checkbox = true;
protected $_required_value = 1;
protected
$_required_checkbox = true,
$_required_value = 1;
/** @test */
public function responseShouldRedirectToPreRegistrationSuccess() {
......@@ -179,8 +180,9 @@ class AuthControllerPreRegistrationKohaWithRequiredCondtionChecked extends AuthC
class AuthControllerPreRegistrationKohaWithRequiredCondtionNotChecked extends AuthControllerPreRegistrationKohaPostDispatchTestCase {
protected $_required_checkbox = true;
protected $_required_value = 0;
protected
$_required_checkbox = true,
$_required_value = 0;
/** @test */
......@@ -218,6 +220,32 @@ class AuthControllerKohaPreRegistrationSpammedPostDispatchTest extends AuthContr
class AuthControllerKohaPreRegistrationInvalidBirthDatePostDispatchTest extends AuthControllerPreRegistrationKohaTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('auth/pre-registration',
['branchcode' => '41|GRA',
'surname' => 'Boulard',
'firstname' => 'Thom',
'dateofbirth' => 'tamalou bobola',
'address' => 'rue secret',
'zipcode' => '01630',
'email' => 'thom@mail.com',
'website' => ''],
true);
}
/** @test */
public function pageShouldDisplayErrorBirthDateInvalid() {
$this->assertXPathContentContains('//ul[@class="errors"]//li', '\'tamalou bobola\' n\'est pas une date au format attendu');
}
}
class AuthControllerPreRegistrationKohaPostDispatchWithErrorReturnedTest extends AuthControllerPreRegistrationKohaTestCase {
public function setUp() {
parent::setUp();
......@@ -239,7 +267,7 @@ class AuthControllerPreRegistrationKohaPostDispatchWithErrorReturnedTest extends
['branchcode' => '41|GRA',
'surname' => 'Boulard',
'firstname' => 'Thom',
'dateofbirth' => '15/09/1940',
'dateofbirth' => '1940-09-15',
'streetnumber' => '10',
'address' => 'rue secret',
'zipcode' => '01630',
......@@ -365,7 +393,13 @@ class AuthControllerPreRegistrationNanookDispatchTest
/** @test */
public function formShouldContainsEmail() {
$this->assertXpath('//form//input[@name="mail"]');
$this->assertXpath('//form//input[@name="mail"][@required="required"]');
}
/** @test */
public function inputForBirthDateShouldBeRequired() {
$this->assertXPath('//form//input[@name="birthDate"][@required="required"][@type="date"]');
}
......@@ -577,6 +611,36 @@ class AuthControllerPreRegistrationNanookPostDispatchSpamTest
class AuthControllerPreRegistrationNanookInvalidBirthDateTest
extends AuthControllerPreRegistrationNanookTestCase {
public function setUp() {
parent::setUp();
$this->postDispatch('/opac/auth/pre-registration', ['site' => '1',
'lastName' => 'Jiro',
'firstName' => 'Tom',
'mail' => 'test@test.fr',
'mail2' => 'test@test.fr',
'password' => 'pwd123456',
'password2' => 'pwd123456',
'birthDate' => 'pouet',
'town' => 'titi',
'zipcode' => '123456',
'address' => '123',
'website' => '']);
}
/** @test */
public function pageShouldDisplayErrorBirthDateInvalid() {
$this->assertXPathContentContains('//ul[@class="errors"]//li', '\'pouet\' n\'est pas une date au format attendu');
}
}
class AuthControllerPreRegistrationNanookSuccessDispatchTest extends AuthControllerPreRegistrationNanookTestCase {
/** @test */
public function withSiteGivenShouldDisplayLibraryName() {
......
......@@ -77,7 +77,7 @@ class TemplatesFormPreRegistrationWithConditionsPostTest extends TemplatesFormPr
'branchcode' => '41|GRA',
'surname' => 'Boulard',
'firstname' => 'Thom',
'dateofbirth' => '15-09-1940',
'dateofbirth' => '1940-09-15',
'streetnumber' => '10',
'address' => 'rue secret',
'zipcode' => '01630',
......
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