mirror of
https://github.com/Icinga/icingaweb2.git
synced 2025-04-08 17:15:08 +02:00
monitoring: Fix DateTimePicker test
This commit is contained in:
parent
8afdc3db1a
commit
f640874865
@ -4,102 +4,44 @@
|
||||
|
||||
namespace Tests\Icinga\Web\Form\Element;
|
||||
|
||||
use DateTime;
|
||||
use Icinga\Test\BaseTestCase;
|
||||
use Icinga\Web\Form\Element\DateTimePicker;
|
||||
|
||||
class DateTimePickerTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* Test that DateTimePicker::isValid() returns false if the input is not valid in terms of being a date/time string
|
||||
* or a timestamp
|
||||
*/
|
||||
public function testValidateInvalidInput()
|
||||
public function testLocalDateAndTimeInput()
|
||||
{
|
||||
$dt = new DateTimePicker(
|
||||
'foo',
|
||||
array(
|
||||
'patterns' => array(
|
||||
'd/m/Y g:i A',
|
||||
'd.m.Y H:i:s'
|
||||
)
|
||||
)
|
||||
$dateTime = new DateTimePicker(
|
||||
'name'
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$dt->isValid('08/27/2013 12:40 PM'),
|
||||
'Wrong placed month/day must not be valid input'
|
||||
$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'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$dt->isValid('bar'),
|
||||
'Arbitrary strings must not be valid input'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$dt->isValid('12:40 AM'),
|
||||
'Time strings must not be valid input'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$dt->isValid('27/08/2013'),
|
||||
'Date strings must not be valid input'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$dt->isValid('13736a16223'),
|
||||
'Invalid Unix timestamps must not be valid input'
|
||||
$this->assertTrue(
|
||||
$dateTime->getValue() instanceof DateTime,
|
||||
'DateTimePicker::getValue() must return an instance of DateTime if its input is valid'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that DateTimePicker::isValid() returns true if the input is valid in terms of being a date/time string
|
||||
* or a timestamp
|
||||
*/
|
||||
public function testValidateValidInput()
|
||||
public function testRFC3339Input()
|
||||
{
|
||||
$dt = new DateTimePicker(
|
||||
'foo',
|
||||
$dateTime = new DateTimePicker(
|
||||
'name',
|
||||
array(
|
||||
'patterns' => array(
|
||||
'd/m/Y g:i A',
|
||||
'd.m.Y H:i:s'
|
||||
)
|
||||
'local' => false
|
||||
)
|
||||
);
|
||||
|
||||
$now = new DateTime();
|
||||
$this->assertTrue(
|
||||
$dt->isValid('27/08/2013 12:40 PM'),
|
||||
'Using a valid date/time string must not fail'
|
||||
$dateTime->isValid($now->format(DateTime::RFC3339)),
|
||||
'A string representing a global date and time (with timezone information) must be considered valid input'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$dt->isValid('12.07.2013 08:03:43'),
|
||||
'Using a valid date/time string must not fail'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$dt->isValid(1373616223),
|
||||
'Using valid Unix timestamps must not fail'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$dt->isValid('1373616223'),
|
||||
'Using strings as Unix timestamps must not fail'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that DateTimePicker::getValue() returns a timestamp after a successful call to isValid
|
||||
*/
|
||||
public function testGetValueReturnsUnixTimestampAfterSuccessfulIsValidCall()
|
||||
{
|
||||
$dt = new DateTimePicker(
|
||||
'foo',
|
||||
array(
|
||||
'patterns' => array(
|
||||
'd.m.Y H:i:s'
|
||||
)
|
||||
)
|
||||
);
|
||||
$dt->isValid('12.07.2013 08:03:43');
|
||||
|
||||
$this->assertEquals(
|
||||
1373616223,
|
||||
$dt->getValue(),
|
||||
'getValue did not return the correct Unix timestamp according to the given date/time string'
|
||||
$dateTime->getValue() instanceof DateTime,
|
||||
'DateTimePicker::getValue() must return an instance of DateTime if its input is valid'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user