2013-08-07 17:14:58 +02:00
|
|
|
<?php
|
2015-02-03 15:49:34 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | http://www.gnu.org/licenses/gpl-2.0.txt */
|
2013-08-07 17:14:58 +02:00
|
|
|
|
2014-04-09 14:18:14 +02:00
|
|
|
namespace Tests\Icinga\Web\Form\Element;
|
2013-08-07 17:14:58 +02:00
|
|
|
|
2014-09-17 12:40:41 +02:00
|
|
|
use DateTime;
|
2014-04-09 14:18:14 +02:00
|
|
|
use Icinga\Test\BaseTestCase;
|
|
|
|
use Icinga\Web\Form\Element\DateTimePicker;
|
2013-08-07 17:14:58 +02:00
|
|
|
|
2014-04-11 15:31:29 +02:00
|
|
|
class DateTimePickerTest extends BaseTestCase
|
2013-08-07 17:14:58 +02:00
|
|
|
{
|
2014-09-17 12:40:41 +02:00
|
|
|
public function testLocalDateAndTimeInput()
|
2013-08-07 17:14:58 +02:00
|
|
|
{
|
2014-09-17 12:40:41 +02:00
|
|
|
$dateTime = new DateTimePicker(
|
|
|
|
'name'
|
2013-08-27 16:00:45 +02:00
|
|
|
);
|
2014-09-17 12:40:41 +02:00
|
|
|
$now = new DateTime();
|
|
|
|
$this->assertTrue(
|
|
|
|
$dateTime->isValid($now->format('Y-m-d\TH:i:s')),
|
|
|
|
'A string representing a local date and time (with no timezone information) must be considered valid input'
|
2013-08-27 16:00:45 +02:00
|
|
|
);
|
2014-09-17 12:40:41 +02:00
|
|
|
$this->assertTrue(
|
|
|
|
$dateTime->getValue() instanceof DateTime,
|
|
|
|
'DateTimePicker::getValue() must return an instance of DateTime if its input is valid'
|
2013-08-07 17:14:58 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-09-17 12:40:41 +02:00
|
|
|
public function testRFC3339Input()
|
2013-08-07 17:14:58 +02:00
|
|
|
{
|
2014-09-17 12:40:41 +02:00
|
|
|
$dateTime = new DateTimePicker(
|
|
|
|
'name',
|
2013-08-27 16:00:45 +02:00
|
|
|
array(
|
2014-09-17 12:40:41 +02:00
|
|
|
'local' => false
|
2013-08-27 16:00:45 +02:00
|
|
|
)
|
|
|
|
);
|
2014-09-17 12:40:41 +02:00
|
|
|
$now = new DateTime();
|
2013-08-27 16:00:45 +02:00
|
|
|
$this->assertTrue(
|
2014-09-17 12:40:41 +02:00
|
|
|
$dateTime->isValid($now->format(DateTime::RFC3339)),
|
|
|
|
'A string representing a global date and time (with timezone information) must be considered valid input'
|
2013-08-07 17:14:58 +02:00
|
|
|
);
|
|
|
|
$this->assertTrue(
|
2014-09-17 12:40:41 +02:00
|
|
|
$dateTime->getValue() instanceof DateTime,
|
|
|
|
'DateTimePicker::getValue() must return an instance of DateTime if its input is valid'
|
2013-08-07 17:14:58 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|