This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1704 from njam/formfield-date-timezone
Make sure date formfield renders and validates in the environment's timezone
- Loading branch information
Showing
3 changed files
with
41 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{select name="{$name}[year]" optionList=$years placeholder={translate 'Year'} selectedValue=$yy} | ||
{select name="{$name}[month]" optionList=$months placeholder={translate 'Month'} selectedValue=$mm translate=true translatePrefix='.date.month.'} | ||
{select name="{$name}[day]" optionList=$days placeholder={translate 'Day'} selectedValue=$dd} | ||
{select class="year" name="{$name}[year]" optionList=$years placeholder={translate 'Year'} selectedValue=$yy} | ||
{select class="month" name="{$name}[month]" optionList=$months placeholder={translate 'Month'} selectedValue=$mm translate=true translatePrefix='.date.month.'} | ||
{select class="day" name="{$name}[day]" optionList=$days placeholder={translate 'Day'} selectedValue=$dd} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
class CM_FormField_DateTest extends CMTest_TestCase { | ||
|
||
public function testRenderWithEnvironmentTimezone() { | ||
$field = new CM_FormField_Date(['name' => 'foo']); | ||
$field->setValue(new DateTime('2015-03-02 01:00:00', new DateTimeZone('UTC'))); | ||
|
||
$environment = new CM_Frontend_Environment(null, null, null, new DateTimeZone('America/New_York')); | ||
$render = new CM_Frontend_Render($environment); | ||
$doc = $this->_renderFormField($field, null, $render); | ||
|
||
$this->assertSame('selected', $doc->find('select.year option[value="2015"]')->getAttribute('selected')); | ||
$this->assertSame('selected', $doc->find('select.month option[value="3"]')->getAttribute('selected')); | ||
$this->assertSame('selected', $doc->find('select.day option[value="1"]')->getAttribute('selected')); | ||
} | ||
|
||
public function testValidateWithEnvironmentTimezone() { | ||
$formField = new CM_FormField_Date(); | ||
|
||
$environment = new CM_Frontend_Environment(null, null, null, new DateTimeZone('Asia/Tokyo')); | ||
$value = $formField->validate($environment, ['year' => 2015, 'month' => 03, 'day' => 02]); | ||
$this->assertEquals(new DateTime('2015-03-02 00:00:00', new DateTimeZone('Asia/Tokyo')), $value); | ||
} | ||
} |