Permalink
Browse files

pass on the configured format to the DateValidator instead of hardcod…

…ing it
  • Loading branch information...
skoop committed Jan 2, 2013
1 parent 1675abc commit 86ff02795b3333546caf7f15018fb8216e319e9a
Showing with 22 additions and 2 deletions.
  1. +2 −2 library/Zend/Form/Element/Date.php
  2. +20 −0 tests/ZendTest/Form/Element/DateTest.php
@@ -46,7 +46,7 @@ class Date extends DateTimeElement
*/
protected function getDateValidator()
{
- return new DateValidator(array('format' => 'Y-m-d'));
+ return new DateValidator(array('format' => $this->getFormat()));
}
/**
@@ -63,7 +63,7 @@ protected function getStepValidator()
? $this->attributes['min'] : '1970-01-01';
return new DateStepValidator(array(
- 'format' => 'Y-m-d',
+ 'format' => $this->getFormat(),
'baseValue' => $baseValue,
'step' => new \DateInterval("P{$stepValue}D"),
));
@@ -94,4 +94,24 @@ public function testValueReturnedFromComposedDateTimeIsRfc3339FullDateFormat()
$value = $element->getValue();
$this->assertEquals($date->format('Y-m-d'), $value);
}
+
+ public function testCorrectFormatPassedToDateValidator()
+ {
+ $element = new DateElement('foo');
+ $element->setAttributes(array(
+ 'min' => '2012-01-01',
+ 'max' => '2012-12-31',
+ ));
+ $element->setFormat('d-m-Y');
+
+ $inputSpec = $element->getInputSpecification();
+ foreach ($inputSpec['validators'] as $validator) {
+ switch (get_class($validator)) {
+ case 'Zend\Validator\DateStep':
+ case 'Zend\Validator\Date':
+ $this->assertEquals('d-m-Y', $validator->getFormat());
+ break;
+ }
+ }
+ }
}

0 comments on commit 86ff027

Please sign in to comment.