Permalink
Browse files

extends when it can :DateStep extends Date

  • Loading branch information...
1 parent 17c7687 commit c42d34edb5470b5b743a11b39701c278d54f6de2 @samsonasik samsonasik committed Oct 9, 2012
Showing with 12 additions and 29 deletions.
  1. +1 −29 library/Zend/Validator/DateStep.php
  2. +11 −0 tests/ZendTest/Validator/DateStepTest.php
@@ -21,18 +21,14 @@
* @category Zend
* @package Zend_Validate
*/
-class DateStep extends AbstractValidator
+class DateStep extends Date
{
- const INVALID = 'dateStepInvalid';
- const INVALID_DATE = 'dateStepInvalidDate';
const NOT_STEP = 'dateStepNotStep';
/**
* @var array
*/
protected $messageTemplates = array(
- self::INVALID => "Invalid type given. String, integer, array or DateTime expected",
- self::INVALID_DATE => "The input does not appear to be a valid date",
self::NOT_STEP => "The input is not a valid step"
);
@@ -156,28 +152,6 @@ public function getStep()
}
/**
- * Returns the format option
- *
- * @return string
- */
- public function getFormat()
- {
- return $this->format;
- }
-
- /**
- * Sets the format option
- *
- * @param string $format
- * @return DateStep
- */
- public function setFormat($format)
- {
- $this->format = $format;
- return $this;
- }
-
- /**
* Returns the timezone option
*
* @return DateTimeZone
@@ -245,7 +219,6 @@ public function isValid($value)
&& !is_int($value)
&& !($value instanceof DateTime)
) {
- $this->error(self::INVALID);
return false;
}
@@ -258,7 +231,6 @@ public function isValid($value)
try {
$valueDate = $this->convertToDateTime($value);
} catch (Exception\InvalidArgumentException $ex) {
- $this->error(self::INVALID_DATE);
return false;
}
@@ -110,4 +110,15 @@ public function testEqualsMessageTemplates()
$this->assertObjectHasAttribute('messageTemplates', $validator);
$this->assertAttributeEquals($validator->getOption('messageTemplates'), 'messageTemplates', $validator);
}
+
+ public function testStepError()
+ {
+ $validator = new Validator\DateStep(array(
+ 'format' => 'Y-m-d',
+ 'baseValue' => '2012-01-23',
+ 'step' => new DateInterval("P10D"),
+ ));
+
+ $this->assertFalse($validator->isValid('2012-13-13'));
+ }
}

0 comments on commit c42d34e

Please sign in to comment.