123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- <?php
- namespace OCA\WorkflowEngine\Tests\Check;
- use OCP\IL10N;
- class RequestTimeTest extends \Test\TestCase {
-
- protected $timeFactory;
-
- protected function getL10NMock() {
- $l = $this->getMockBuilder(IL10N::class)
- ->disableOriginalConstructor()
- ->getMock();
- $l->expects($this->any())
- ->method('t')
- ->willReturnCallback(function ($string, $args) {
- return sprintf($string, $args);
- });
- return $l;
- }
- protected function setUp(): void {
- parent::setUp();
- $this->timeFactory = $this->getMockBuilder('OCP\AppFramework\Utility\ITimeFactory')
- ->getMock();
- }
- public function dataExecuteCheck() {
- return [
- [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467870105, false],
- [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467873705, true],
- [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467902505, true],
- [json_encode(['08:00 Europe/Berlin', '17:00 Europe/Berlin']), 1467906105, false],
- [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467870105, true],
- [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467873705, false],
- [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467902505, false],
- [json_encode(['17:00 Europe/Berlin', '08:00 Europe/Berlin']), 1467906105, true],
- [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467843105, false],
- [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467846705, true],
- [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467875505, true],
- [json_encode(['08:00 Australia/Adelaide', '17:00 Australia/Adelaide']), 1467879105, false],
- [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467843105, true],
- [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467846705, false],
- [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467875505, false],
- [json_encode(['17:00 Australia/Adelaide', '08:00 Australia/Adelaide']), 1467879105, true],
- [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467916905, false],
- [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467920505, true],
- [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467949305, true],
- [json_encode(['08:00 Pacific/Niue', '17:00 Pacific/Niue']), 1467952905, false],
- [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467916905, true],
- [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467920505, false],
- [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467949305, false],
- [json_encode(['17:00 Pacific/Niue', '08:00 Pacific/Niue']), 1467952905, true],
- ];
- }
-
- public function testExecuteCheckIn($value, $timestamp, $expected) {
- $check = new \OCA\WorkflowEngine\Check\RequestTime($this->getL10NMock(), $this->timeFactory);
- $this->timeFactory->expects($this->once())
- ->method('getTime')
- ->willReturn($timestamp);
- $this->assertEquals($expected, $check->executeCheck('in', $value));
- }
-
- public function testExecuteCheckNotIn($value, $timestamp, $expected) {
- $check = new \OCA\WorkflowEngine\Check\RequestTime($this->getL10NMock(), $this->timeFactory);
- $this->timeFactory->expects($this->once())
- ->method('getTime')
- ->willReturn($timestamp);
- $this->assertEquals(!$expected, $check->executeCheck('!in', $value));
- }
- public function dataValidateCheck() {
- return [
- ['in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]'],
- ['!in', '["08:00 Europe/Berlin","17:00 America/North_Dakota/Beulah"]'],
- ['in', '["08:00 America/Port-au-Prince","17:00 America/Argentina/San_Luis"]'],
- ];
- }
-
- public function testValidateCheck($operator, $value) {
- $check = new \OCA\WorkflowEngine\Check\RequestTime($this->getL10NMock(), $this->timeFactory);
- $check->validateCheck($operator, $value);
- $this->addToAssertionCount(1);
- }
- public function dataValidateCheckInvalid() {
- return [
- ['!!in', '["08:00 Europe/Berlin","17:00 Europe/Berlin"]', 1, 'The given operator is invalid'],
- ['in', '["28:00 Europe/Berlin","17:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
- ['in', '["08:00 Europe/Berlin","27:00 Europe/Berlin"]', 2, 'The given time span is invalid'],
- ['in', '["08:00 Europa/Berlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
- ['in', '["08:00 Europe/Berlin","17:00 Europa/Berlin"]', 4, 'The given end time is invalid'],
- ['in', '["08:00 Europe/Bearlin","17:00 Europe/Berlin"]', 3, 'The given start time is invalid'],
- ['in', '["08:00 Europe/Berlin","17:00 Europe/Bearlin"]', 4, 'The given end time is invalid'],
- ];
- }
-
- public function testValidateCheckInvalid($operator, $value, $exceptionCode, $exceptionMessage) {
- $check = new \OCA\WorkflowEngine\Check\RequestTime($this->getL10NMock(), $this->timeFactory);
- try {
- $check->validateCheck($operator, $value);
- } catch (\UnexpectedValueException $e) {
- $this->assertEquals($exceptionCode, $e->getCode());
- $this->assertEquals($exceptionMessage, $e->getMessage());
- }
- }
- }
|