ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DateTimeInputTest.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2018 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4
5require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../../Base.php");
7
8
10use \ILIAS\UI\Implementation\Component\Input\NameSource;
11use \ILIAS\UI\Component\Input\Field;
12use \ILIAS\Data;
13use \ILIAS\Refinery\Validation;
14use \ILIAS\Refinery\Transformation;
15
17{
18 public function setUp() : void
19 {
20 $this->name_source = new DefNamesource();
21 $this->data_factory = new Data\Factory();
22 $this->factory = $this->buildFactory();
23 }
24
25 protected function buildFactory()
26 {
27 $df = new Data\Factory();
28 $language = $this->createMock(\ilLanguage::class);
29
31 new SignalGenerator(),
32 $this->data_factory,
33 new \ILIAS\Refinery\Factory($df, $language),
34 $language
35 );
36 }
37
38 public function test_withFormat()
39 {
40 $format = $this->data_factory->dateFormat()->germanShort();
41 $datetime = $this->factory->datetime('label', 'byline')
42 ->withFormat($format);
43
44 $this->assertEquals(
45 $format,
46 $datetime->getFormat()
47 );
48 }
49
50 public function test_withMinValue()
51 {
52 $dat = new \DateTimeImmutable('2019-01-09');
53 $datetime = $this->factory->datetime('label', 'byline')
54 ->withMinValue($dat);
55
56 $this->assertEquals(
57 $dat,
58 $datetime->getMinValue()
59 );
60 }
61
62 public function test_withMaxValue()
63 {
64 $dat = new \DateTimeImmutable('2019-01-09');
65 $datetime = $this->factory->datetime('label', 'byline')
66 ->withMaxValue($dat);
67
68 $this->assertEquals(
69 $dat,
70 $datetime->getMaxValue()
71 );
72 }
73
74 public function test_withUseTime()
75 {
76 $datetime = $this->factory->datetime('label', 'byline');
77 $this->assertFalse($datetime->getUseTime());
78 $this->assertTrue($datetime->withUseTime(true)->getUseTime());
79 }
80
81 public function test_withTimeOnly()
82 {
83 $datetime = $this->factory->datetime('label', 'byline');
84 $this->assertFalse($datetime->getTimeOnly());
85 $this->assertTrue($datetime->withTimeOnly(true)->getTimeOnly());
86 }
87
88 public function test_withTimeZone()
89 {
90 $datetime = $this->factory->datetime('label', 'byline');
91 $this->assertNull($datetime->getTimeZone());
92 $tz = 'Europe/Moscow';
93 $this->assertEquals(
94 $tz,
95 $datetime->withTimeZone($tz)->getTimeZone()
96 );
97 }
98 public function test_withInvalidTimeZone()
99 {
100 $this->expectException(\InvalidArgumentException::class);
101 $datetime = $this->factory->datetime('label', 'byline');
102 $tz = 'NOT/aValidTZ';
103 $datetime->withTimeZone($tz);
104 }
105}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Provides common functionality for UI tests.
Definition: Base.php:225
$format
Definition: metadata.php:218
Class ChatMainBarProvider \MainMenu\Provider.