ILIAS  release_8 Revision v8.24
DateTimeInputTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../../Base.php");
23
27use ILIAS\Data;
28use ILIAS\Refinery\Factory as Refinery;
30
32{
35 protected I\Input\Field\Factory $factory;
36
37 public function setUp(): void
38 {
39 $this->name_source = new DefNamesource();
40 $this->data_factory = new Data\Factory();
41 $this->factory = $this->buildFactory();
42 }
43
44 public function getUIFactory(): NoUIFactory
45 {
46 return new class () extends NoUIFactory {
47 public function symbol(): C\Symbol\Factory
48 {
49 return new S\Factory(
50 new S\Icon\Factory(),
51 new S\Glyph\Factory(),
52 new S\Avatar\Factory()
53 );
54 }
55 };
56 }
57
58 public function getLanguage(): ilLanguageMock
59 {
60 return new class () extends ilLanguageMock {
61 public function getLangKey(): string
62 {
63 return 'en';
64 }
65 };
66 }
67
68 protected function buildFactory(): I\Input\Field\Factory
69 {
70 $df = new Data\Factory();
71 $language = $this->createMock(ilLanguage::class);
72
73 return new I\Input\Field\Factory(
74 $this->createMock(\ILIAS\UI\Implementation\Component\Input\UploadLimitResolver::class),
75 new SignalGenerator(),
76 $this->data_factory,
77 new Refinery($df, $language),
78 $language
79 );
80 }
81
82 public function test_withFormat(): void
83 {
84 $format = $this->data_factory->dateFormat()->germanShort();
85 $datetime = $this->factory->datetime('label', 'byline')
86 ->withFormat($format);
87
88 $this->assertEquals(
89 $format,
90 $datetime->getFormat()
91 );
92 }
93
94 public function test_withMinValue(): void
95 {
96 $dat = new DateTimeImmutable('2019-01-09');
97 $datetime = $this->factory->datetime('label', 'byline')
98 ->withMinValue($dat);
99
100 $this->assertEquals(
101 $dat,
102 $datetime->getMinValue()
103 );
104 }
105
106 public function test_withMaxValue(): void
107 {
108 $dat = new DateTimeImmutable('2019-01-09');
109 $datetime = $this->factory->datetime('label', 'byline')
110 ->withMaxValue($dat);
111
112 $this->assertEquals(
113 $dat,
114 $datetime->getMaxValue()
115 );
116 }
117
118 public function test_withUseTime(): void
119 {
120 $datetime = $this->factory->datetime('label', 'byline');
121 $this->assertFalse($datetime->getUseTime());
122 $this->assertTrue($datetime->withUseTime(true)->getUseTime());
123 }
124
125 public function test_withTimeOnly(): void
126 {
127 $datetime = $this->factory->datetime('label', 'byline');
128 $this->assertFalse($datetime->getTimeOnly());
129 $this->assertTrue($datetime->withTimeOnly(true)->getTimeOnly());
130 }
131
132 public function test_withTimeZone(): void
133 {
134 $datetime = $this->factory->datetime('label', 'byline');
135 $this->assertNull($datetime->getTimeZone());
136 $tz = 'Europe/Moscow';
137 $this->assertEquals(
138 $tz,
139 $datetime->withTimeZone($tz)->getTimeZone()
140 );
141 }
142
143 public function test_withInvalidTimeZone(): void
144 {
145 $this->expectException(InvalidArgumentException::class);
146 $datetime = $this->factory->datetime('label', 'byline');
147 $tz = 'NOT/aValidTZ';
148 $datetime->withTimeZone($tz);
149 }
150
151 public function test_jsConfigRendering(): void
152 {
153 $datetime = $this->factory->datetime('label', 'byline');
154 $js_binding = $this->getJavaScriptBinding();
155 $this->getDefaultRenderer($js_binding)->render($datetime);
156
157 $expected = '$("#id_1").datetimepicker({'
158 . '"showClear":true,'
159 . '"sideBySide":true,'
160 . '"format":"YYYY-MM-DD",'
161 . '"locale":"en"'
162 . '});';
163
164 $onload_js = array_shift($js_binding->on_load_code);
165 $this->assertEquals($expected, $onload_js);
166 }
167
169 {
170 $string_value = "1985-05-04";
171 $value = new \DateTimeImmutable($string_value);
172 $datetime = $this->factory->datetime('label', 'byline')
173 ->withValue($value);
174 $this->assertEquals(
175 $string_value,
176 $datetime->getValue()
177 );
178 }
179}
Data Factory $data_factory
I Input Field Factory $factory
DefNamesource $name_source
Builds data types.
Definition: Factory.php:21
Provides common functionality for UI tests.
Definition: Base.php:299
getJavaScriptBinding()
Definition: Base.php:330
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
$format
Definition: metadata.php:235
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.