Skip to content

Commit

Permalink
Fixed yiisoft#15140 DateValidator tests for specific ICU versions (yi…
Browse files Browse the repository at this point in the history
  • Loading branch information
schmunk42 authored and samdark committed Jan 19, 2018
1 parent 8d50844 commit 2484154
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions tests/framework/validators/DateValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ public function testTimestampAttributeFormat($format, $date, $expectedDate, $tim
*/
public function testIntlValidationWithTime($timezone)
{
// prepare data for specific ICU version, see https://github.com/yiisoft/yii2/issues/15140
switch (true) {
case (version_compare(INTL_ICU_VERSION, '57.1', '>=')):
$enGB_dateTime_valid = '31/05/2017, 12:30';
$enGB_dateTime_invalid = '05/31/2017, 12:30';
$deDE_dateTime_valid = '31.05.2017, 12:30';
$deDE_dateTime_invalid = '05.31.2017, 12:30';
break;
default:
$enGB_dateTime_valid = '31/5/2017 12:30';
$enGB_dateTime_invalid = '5/31/2017 12:30';
$deDE_dateTime_valid = '31.5.2017 12:30';
$deDE_dateTime_invalid = '5.31.2017 12:30';
}

$this->testValidationWithTime($timezone);

$this->mockApplication([
Expand All @@ -314,12 +329,13 @@ public function testIntlValidationWithTime($timezone)
],
],
]);

$val = new DateValidator(['type' => DateValidator::TYPE_DATETIME]);
$this->assertTrue($val->validate('31/5/2017 12:30'));
$this->assertFalse($val->validate('5/31/2017 12:30'));
$this->assertTrue($val->validate($enGB_dateTime_valid));
$this->assertFalse($val->validate($enGB_dateTime_invalid));
$val = new DateValidator(['format' => 'short', 'locale' => 'en-GB', 'type' => DateValidator::TYPE_DATETIME]);
$this->assertTrue($val->validate('31/5/2017 12:30'));
$this->assertFalse($val->validate('5/31/2017 12:30'));
$this->assertTrue($val->validate($enGB_dateTime_valid));
$this->assertFalse($val->validate($enGB_dateTime_invalid));
$this->mockApplication([
'language' => 'de-DE',
'components' => [
Expand All @@ -330,11 +346,11 @@ public function testIntlValidationWithTime($timezone)
],
]);
$val = new DateValidator(['type' => DateValidator::TYPE_DATETIME]);
$this->assertTrue($val->validate('31.5.2017 12:30'));
$this->assertFalse($val->validate('5.31.2017 12:30'));
$this->assertTrue($val->validate($deDE_dateTime_valid));
$this->assertFalse($val->validate($deDE_dateTime_invalid));
$val = new DateValidator(['format' => 'short', 'locale' => 'de-DE', 'type' => DateValidator::TYPE_DATETIME]);
$this->assertTrue($val->validate('31.5.2017 12:30'));
$this->assertFalse($val->validate('5.31.2017 12:30'));
$this->assertTrue($val->validate($deDE_dateTime_valid));
$this->assertFalse($val->validate($deDE_dateTime_invalid));
}

/**
Expand Down

0 comments on commit 2484154

Please sign in to comment.