Commit f9cbc848 authored by Elias Villiger's avatar Elias Villiger
Browse files

Feature #5064 - Add unit tests for doDateTime

parent 4799975f
......@@ -302,7 +302,7 @@ class FillStoreForm {
}
/**
* Check $value as date/datime/time value and convert it to FORMAT_DATE_INTERNATIONAL.
* Check $value as date/datetime/time value and convert it to FORMAT_DATE_INTERNATIONAL.
*
* @param array $formElement - if not set, set $formElement[FE_DATE_FORMAT]
* @param string $value - date/datetime/time value in format FORMAT_DATE_INTERNATIONAL or FORMAT_DATE_GERMAN
......@@ -310,7 +310,7 @@ class FillStoreForm {
* @return string - checked datetime string
* @throws UserFormException
*/
private function doDateTime(array &$formElement, $value) {
public function doDateTime(array &$formElement, $value) {
$regexp = Support::dateTimeRegexp($formElement[FE_TYPE], $formElement[FE_DATE_FORMAT]);
......
......@@ -19,23 +19,44 @@ class FillStoreFormTest extends \PHPUnit_Framework_TestCase {
* @throws CodeException
* @throws UserFormException
*/
public function testFake() {
# Violates SANITIZE class: SANITIZE string is always an empty string.
# Access are cached: use new variables for every test.
public function testDoDateTime() {
$formElement = [ FE_TYPE => FE_TYPE_DATE,
FE_DATE_FORMAT => FORMAT_DATE_INTERNATIONAL,
FE_SHOW_SECONDS => 0 ];
$msg = 'doDateTime fails';
$val = '2010-03-31';
$this->assertEquals($val, FillStoreForm::doDateTime($formElement, $val), $msg);
$val = '2010-02-28';
$this->assertEquals($val, FillStoreForm::doDateTime($formElement, $val), $msg);
$val = '2012-02-29';
$this->assertEquals($val, FillStoreForm::doDateTime($formElement, $val), $msg);
$formElement[FE_DATE_FORMAT] = FORMAT_DATE_GERMAN;
$this->assertEquals($val, FillStoreForm::doDateTime($formElement, '29.02.2012'), $msg);
}
# Check ''
// $this->assertEquals('', Sanitize::sanitize('', SANITIZE_ALLOW_ALNUMX), "SANITIZE_ALNUMX fails");
$this->assertEquals('', '');
/**
* @expectedException \qfq\UserFormException
*/
public function testDoDateTimeInvalidDate() {
$formElement = [ FE_TYPE => FE_TYPE_DATE,
FE_DATE_FORMAT => FORMAT_DATE_INTERNATIONAL,
FE_SHOW_SECONDS => 0 ];
$val = '2010-02-29';
$this->assertEquals($val, FillStoreForm::doDateTime($formElement, $val), "doDateTime is passing when it shouldn't");
}
/**
* @expectedException \qfq\UserFormException
*/
public function testDoDateTimeInvalidDateWithTime() {
$formElement = [ FE_TYPE => FE_TYPE_DATE,
FE_DATE_FORMAT => FORMAT_DATE_INTERNATIONAL,
FE_SHOW_SECONDS => 0 ];
$val = '2010-02-31 23:25';
$this->assertEquals($val, FillStoreForm::doDateTime($formElement, $val), "doDateTime is passing when it shouldn't");
}
//
// /**
// * @expectedException \qfq\UserFormException
// */
// public function testSanitizeExceptionMinMaxMissingMin() {
// Sanitize::sanitize(56, SANITIZE_ALLOW_MIN_MAX, '|45');
// }
//
}
Markdown is supported
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