Added Solar_Filter_ValidateMinIsoDate and Solar_Filter_ValidateMaxIsoDate with tests and locales #52

Merged
merged 4 commits into from Sep 12, 2012
@@ -29,6 +29,8 @@
'INVALID_IPV4' => 'Bitte geben Sie eine gültige IPv4 Adresse ein.',
'INVALID_IPV6' => 'Bitte geben Sie eine gültige IPv6 Adresse ein.',
'INVALID_ISO_DATE' => 'Bitte geben Sie ein Datum im "JJJJ-MM-TT" Format ein.',
+ 'INVALID_MIN_ISO_DATE' => 'Bitte geben Sie ein spaeteres Datum ein .',
+ 'INVALID_MAX_ISO_DATE' => 'Bitte geben Sie ein früheres Datum ein .',
'INVALID_ISO_TIME' => 'Bitte geben Sie eine Zeit im "HH:MM:SS" Format ein.',
'INVALID_ISO_TIMESTAMP' => 'Bitte geben Sie einen Zeitstempel im "JJJJ-MM-TTThh:HH:SS" Format ein.',
'INVALID_LOCALE_CODE' => 'Bitte geben Sie ein gültiges Sprachcode im ISO 639 Format ein (z.B de_DE).',
@@ -33,6 +33,9 @@
'INVALID_IPV4' => 'Please use a valid IPv4 address.',
'INVALID_IPV6' => 'Please use a valid IPv6 address.',
'INVALID_ISO_DATE' => 'Please enter a date in "yyyy-mm-dd" format.',
+ 'INVALID_MIN_ISO_DATE' => 'Please enter an older date .',
+ 'INVALID_MAX_ISO_DATE' => 'Please enter an younger date .',
+ 'INVALID_ISO_TIME' => 'Bitte geben Sie eine Zeit im "HH:MM:SS" Format ein.',
'INVALID_ISO_TIME' => 'Please enter a time in "hh:ii:ss" format.',
'INVALID_ISO_TIMESTAMP' => 'Please enter a timestamp in "yyyy-mm-ddThh:ii:ss" format.',
'INVALID_LOCALE_CODE' => 'Please use a valid language-and-contry code in "ll_CC" format.',
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Validates that an ISO 8601 date is not after a certain date.
+ *
+ * @category Solar
+ *
+ * @package Solar_Filter
+ *
+ * @author Bahtiar `kalkin` Gadimov <bahtiar@gadimov.de>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $id$
+ */
+class Solar_Filter_ValidateMaxIsoDate extends Solar_Filter_ValidateIsoTimestamp
+{
+ /**
+ *
+ * Validates that an ISO 8601 date is not after a certain date.
+ *
+ * The format is "yyyy-mm-dd". Does not check if the date is a valide ISO
+ * 8601 use Solar_Filter_ValidateIsoDate for that.
+ *
+ * @param mixed $value The value to validate.
+ *
+ * @param mixed $minDate The value must be at most this date.
+ *
+ * @return bool True if valid, false if not.
+ *
+ */
+ public function validateMaxIsoDate($value, $minDate)
+ {
+ if ($this->_filter->validateBlank($value)) {
+ return ! $this->_filter->getRequire();
+ }
+
+ // look for Ymd keys?
+ if (is_array($value)) {
+ $value = $this->_arrayToDate($value);
+ }
+
+ if ( strtotime($value) <= strtotime($minDate)) {
+ return true;
+ }
+
+ return false;
+ }
+}
+
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Validates that an ISO 8601 is at least a certain date.
+ *
+ * @category Solar
+ *
+ * @package Solar_Filter
+ *
+ * @author Bahtiar `kalkin` Gadimov <bahtiar@gadimov.de>
+ *
+ * @license http://opensource.org/licenses/bsd-license.php BSD
+ *
+ * @version $id$
+ */
+class Solar_Filter_ValidateMinIsoDate extends Solar_Filter_ValidateIsoTimestamp
+{
+ /**
+ *
+ * Validates that an ISO 8601 is at least a certain date.
+ *
+ * The format is "yyyy-mm-dd". Does not check if the date is a valide ISO
+ * 8601 use Solar_Filter_ValidateIsoDate for that.
+ *
+ * @param mixed $value The value to validate.
+ *
+ * @param mixed $minDate The value must be at least this date.
+ *
+ * @return bool True if valid, false if not.
+ *
+ */
+ public function validateMinIsoDate($value, $minDate)
+ {
+ if ($this->_filter->validateBlank($value)) {
+ return ! $this->_filter->getRequire();
+ }
+
+ // look for Ymd keys?
+ if (is_array($value)) {
+ $value = $this->_arrayToDate($value);
+ }
+
+ if ( strtotime($value) >= strtotime($minDate)) {
+ return true;
+ }
+
+ return false;
+ }
+}
@@ -0,0 +1,64 @@
+<?php
+/**
+ *
+ * Concrete class test.
+ *
+ */
+class Test_Solar_Filter_ValidateMaxIsoDate extends Test_Solar_Filter_Abstract {
+
+ /**
+ *
+ * Configuration values.
+ *
+ * @var array
+ *
+ */
+ protected $_Test_Solar_Filter_ValidateMaxIsoDate = array(
+ );
+
+ public function testValidateMaxIsoDate()
+ {
+ $minDate = "1987-04-19";
+ $test = array(
+ "1968-05-12",
+ "1975-12-23",
+ "1987-04-18",
+ );
+ foreach ($test as $val) {
+ $this->assertTrue($this->_filter->validateMaxIsoDate($val, $minDate));
+ }
+ }
+
+ public function testValidateMaxIsoDate_badOrBlank()
+ {
+ $minDate = "1987-04-19";
+ $test = array(
+ "",
+ "1987-07-29",
+ "1999-02-23",
+ "2010-11-29",
+ null,
+ );
+ foreach ($test as $val) {
+ $this->assertFalse($this->_filter->validateMaxIsoDate($val, $minDate));
+ }
+ }
+
+ public function testValidateIsoDate_notRequired()
+ {
+ $minDate = "1987-04-19";
+ $this->_filter->setRequire(false);
+ $test = array(
+ "",
+ null,
+ "1968-05-12",
+ "1975-12-23",
+ "1987-04-18",
+ );
+ foreach ($test as $val) {
+ $this->assertTrue($this->_filter->validateMaxIsoDate($val, $minDate));
+ }
+ }
+}
+
+
@@ -0,0 +1,63 @@
+<?php
+/**
+ *
+ * Concrete class test.
+ *
+ */
+class Test_Solar_Filter_ValidateMinIsoDate extends Test_Solar_Filter_Abstract {
+
+ /**
+ *
+ * Configuration values.
+ *
+ * @var array
+ *
+ */
+ protected $_Test_Solar_Filter_ValidateMinIsoDate = array(
+ );
+
+ public function testValidateMinIsoDate()
+ {
+ $minDate = "1987-04-19";
+ $test = array(
+ "1987-07-29",
+ "1999-02-23",
+ "2010-11-29",
+ );
+ foreach ($test as $val) {
+ $this->assertTrue($this->_filter->validateMinIsoDate($val, $minDate));
+ }
+ }
+
+ public function testValidateMinIsoDate_badOrBlank()
+ {
+ $minDate = "1987-04-19";
+ $test = array(
+ "",
+ "1968-05-12",
+ "1975-12-23",
+ "1987-04-18",
+ null,
+ );
+ foreach ($test as $val) {
+ $this->assertFalse($this->_filter->validateMinIsoDate($val, $minDate));
+ }
+ }
+
+ public function testValidateIsoDate_notRequired()
+ {
+ $minDate = "1987-04-19";
+ $this->_filter->setRequire(false);
+ $test = array(
+ "",
+ null,
+ "1987-07-29",
+ "1999-02-23",
+ "2010-11-29",
+ );
+ foreach ($test as $val) {
+ $this->assertTrue($this->_filter->validateMinIsoDate($val, $minDate));
+ }
+ }
+}
+