Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'date-validator-format' of git://github.com/skoop/zf2 in…
Browse files Browse the repository at this point in the history
…to hotfix/3328
  • Loading branch information
weierophinney committed Jan 2, 2013
2 parents 236c092 + 0ac8133 commit 3db16fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
12 changes: 1 addition & 11 deletions library/Zend/Form/Element/Date.php
Expand Up @@ -39,16 +39,6 @@ class Date extends DateTimeElement
*/
protected $format = 'Y-m-d';

/**
* Retrieves a Date Validator configured for a DateTime Input type
*
* @return \Zend\Validator\ValidatorInterface
*/
protected function getDateValidator()
{
return new DateValidator(array('format' => 'Y-m-d'));
}

/**
* Retrieves a DateStep Validator configured for a Date Input type
*
Expand All @@ -63,7 +53,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"),
));
Expand Down
20 changes: 20 additions & 0 deletions tests/ZendTest/Form/Element/DateTest.php
Expand Up @@ -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 3db16fa

Please sign in to comment.