|
@@ -91,17 +91,27 @@ class TimeTypeTest extends LocalizedTestCase
|
|
|
'minute' => '4',
|
|
|
);
|
|
|
|
|
|
- $data = array(
|
|
|
- 'hour' => '3',
|
|
|
- 'minute' => '4',
|
|
|
- );
|
|
|
-
|
|
|
$form->bind($input);
|
|
|
|
|
|
- $this->assertEquals($data, $form->getData());
|
|
|
+ $this->assertEquals($input, $form->getData());
|
|
|
$this->assertEquals($input, $form->getClientData());
|
|
|
}
|
|
|
|
|
|
+ public function testSubmit_datetimeSingleText()
|
|
|
+ {
|
|
|
+ $form = $this->factory->create('time', null, array(
|
|
|
+ 'data_timezone' => 'UTC',
|
|
|
+ 'user_timezone' => 'UTC',
|
|
|
+ 'input' => 'datetime',
|
|
|
+ 'widget' => 'single_text',
|
|
|
+ ));
|
|
|
+
|
|
|
+ $form->bind('03:04:05');
|
|
|
+
|
|
|
+ $this->assertEquals(new \DateTime('03:04:00 UTC'), $form->getData());
|
|
|
+ $this->assertEquals('03:04:00', $form->getClientData());
|
|
|
+ }
|
|
|
+
|
|
|
public function testSubmit_arraySingleText()
|
|
|
{
|
|
|
$form = $this->factory->create('time', null, array(
|
|
@@ -144,21 +154,6 @@ class TimeTypeTest extends LocalizedTestCase
|
|
|
$this->assertEquals('03:04:05', $form->getClientData());
|
|
|
}
|
|
|
|
|
|
- public function testSubmit_datetimeSingleText()
|
|
|
- {
|
|
|
- $form = $this->factory->create('time', null, array(
|
|
|
- 'data_timezone' => 'UTC',
|
|
|
- 'user_timezone' => 'UTC',
|
|
|
- 'input' => 'datetime',
|
|
|
- 'widget' => 'single_text',
|
|
|
- ));
|
|
|
-
|
|
|
- $form->bind('03:04:05');
|
|
|
-
|
|
|
- $this->assertEquals(new \DateTime('03:04:05 UTC'), $form->getData());
|
|
|
- $this->assertEquals('03:04:05', $form->getClientData());
|
|
|
- }
|
|
|
-
|
|
|
public function testSubmit_stringSingleText()
|
|
|
{
|
|
|
$form = $this->factory->create('time', null, array(
|
|
@@ -168,12 +163,10 @@ class TimeTypeTest extends LocalizedTestCase
|
|
|
'widget' => 'single_text',
|
|
|
));
|
|
|
|
|
|
- $time = '03:04:05';
|
|
|
-
|
|
|
- $form->bind($time);
|
|
|
+ $form->bind('03:04:05');
|
|
|
|
|
|
- $this->assertEquals($time, $form->getData());
|
|
|
- $this->assertEquals($time, $form->getClientData());
|
|
|
+ $this->assertEquals('03:04:00', $form->getData());
|
|
|
+ $this->assertEquals('03:04:00', $form->getClientData());
|
|
|
}
|
|
|
|
|
|
public function testSetData_withSeconds()
|
|
@@ -194,25 +187,52 @@ class TimeTypeTest extends LocalizedTestCase
|
|
|
{
|
|
|
$form = $this->factory->create('time', null, array(
|
|
|
'data_timezone' => 'America/New_York',
|
|
|
- 'user_timezone' => 'Pacific/Tahiti',
|
|
|
- // don't do this test with DateTime, because it leads to wrong results!
|
|
|
+ 'user_timezone' => 'Asia/Hong_Kong',
|
|
|
'input' => 'string',
|
|
|
'with_seconds' => true,
|
|
|
));
|
|
|
|
|
|
- $dateTime = new \DateTime('03:04:05 America/New_York');
|
|
|
+ $dateTime = new \DateTime('12:04:05');
|
|
|
+ $dateTime->setTimezone(new \DateTimeZone('America/New_York'));
|
|
|
|
|
|
$form->setData($dateTime->format('H:i:s'));
|
|
|
|
|
|
- $dateTime = clone $dateTime;
|
|
|
- $dateTime->setTimezone(new \DateTimeZone('Pacific/Tahiti'));
|
|
|
+ $outputTime = clone $dateTime;
|
|
|
+ $outputTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
|
|
|
+
|
|
|
+ $displayedData = array(
|
|
|
+ 'hour' => (int)$outputTime->format('H'),
|
|
|
+ 'minute' => (int)$outputTime->format('i'),
|
|
|
+ 'second' => (int)$outputTime->format('s')
|
|
|
+ );
|
|
|
+
|
|
|
+ $this->assertEquals($displayedData, $form->getClientData());
|
|
|
+ }
|
|
|
+
|
|
|
+ public function testSetData_differentTimezonesDateTime()
|
|
|
+ {
|
|
|
+ $form = $this->factory->create('time', null, array(
|
|
|
+ 'data_timezone' => 'America/New_York',
|
|
|
+ 'user_timezone' => 'Asia/Hong_Kong',
|
|
|
+ 'input' => 'datetime',
|
|
|
+ 'with_seconds' => true,
|
|
|
+ ));
|
|
|
+
|
|
|
+ $dateTime = new \DateTime('12:04:05');
|
|
|
+ $dateTime->setTimezone(new \DateTimeZone('America/New_York'));
|
|
|
+
|
|
|
+ $form->setData($dateTime);
|
|
|
+
|
|
|
+ $outputTime = clone $dateTime;
|
|
|
+ $outputTime->setTimezone(new \DateTimeZone('Asia/Hong_Kong'));
|
|
|
|
|
|
$displayedData = array(
|
|
|
- 'hour' => (int)$dateTime->format('H'),
|
|
|
- 'minute' => (int)$dateTime->format('i'),
|
|
|
- 'second' => (int)$dateTime->format('s')
|
|
|
+ 'hour' => (int)$outputTime->format('H'),
|
|
|
+ 'minute' => (int)$outputTime->format('i'),
|
|
|
+ 'second' => (int)$outputTime->format('s')
|
|
|
);
|
|
|
|
|
|
+ $this->assertDateTimeEquals($dateTime, $form->getData());
|
|
|
$this->assertEquals($displayedData, $form->getClientData());
|
|
|
}
|
|
|
|