ILIAS  release_7 Revision v7.30-3-g800a261c036
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;
16
18{
19 public function setUp() : void
20 {
21 $this->name_source = new DefNamesource();
22 $this->data_factory = new Data\Factory();
23 $this->factory = $this->buildFactory();
24 }
25
26 public function getUIFactory()
27 {
28 $factory = new class extends NoUIFactory {
29 public function symbol() : \ILIAS\UI\Component\Symbol\Factory
30 {
31 return new S\Factory(
32 new S\Icon\Factory(),
33 new S\Glyph\Factory(),
34 new S\Avatar\Factory()
35 );
36 }
37 };
38 return $factory;
39 }
40
41 public function getLanguage()
42 {
43 $languageMock = new class extends ilLanguageMock {
44 public function getLangKey() : string
45 {
46 return 'en';
47 }
48 };
49 return new $languageMock();
50 }
51
52 protected function buildFactory()
53 {
54 $df = new Data\Factory();
55 $language = $this->createMock(\ilLanguage::class);
56
58 new SignalGenerator(),
59 $this->data_factory,
60 new \ILIAS\Refinery\Factory($df, $language),
61 $language
62 );
63 }
64
65 public function test_withFormat()
66 {
67 $format = $this->data_factory->dateFormat()->germanShort();
68 $datetime = $this->factory->datetime('label', 'byline')
69 ->withFormat($format);
70
71 $this->assertEquals(
72 $format,
73 $datetime->getFormat()
74 );
75 }
76
77 public function test_withMinValue()
78 {
79 $dat = new \DateTimeImmutable('2019-01-09');
80 $datetime = $this->factory->datetime('label', 'byline')
81 ->withMinValue($dat);
82
83 $this->assertEquals(
84 $dat,
85 $datetime->getMinValue()
86 );
87 }
88
89 public function test_withMaxValue()
90 {
91 $dat = new \DateTimeImmutable('2019-01-09');
92 $datetime = $this->factory->datetime('label', 'byline')
93 ->withMaxValue($dat);
94
95 $this->assertEquals(
96 $dat,
97 $datetime->getMaxValue()
98 );
99 }
100
101 public function test_withUseTime()
102 {
103 $datetime = $this->factory->datetime('label', 'byline');
104 $this->assertFalse($datetime->getUseTime());
105 $this->assertTrue($datetime->withUseTime(true)->getUseTime());
106 }
107
108 public function test_withTimeOnly()
109 {
110 $datetime = $this->factory->datetime('label', 'byline');
111 $this->assertFalse($datetime->getTimeOnly());
112 $this->assertTrue($datetime->withTimeOnly(true)->getTimeOnly());
113 }
114
115 public function test_withTimeZone()
116 {
117 $datetime = $this->factory->datetime('label', 'byline');
118 $this->assertNull($datetime->getTimeZone());
119 $tz = 'Europe/Moscow';
120 $this->assertEquals(
121 $tz,
122 $datetime->withTimeZone($tz)->getTimeZone()
123 );
124 }
125
126 public function test_withInvalidTimeZone()
127 {
128 $this->expectException(\InvalidArgumentException::class);
129 $datetime = $this->factory->datetime('label', 'byline');
130 $tz = 'NOT/aValidTZ';
131 $datetime->withTimeZone($tz);
132 }
133
134 public function test_jsConfigRendering()
135 {
136 $datetime = $this->factory->datetime('label', 'byline');
137 $js_binding = $this->getJavaScriptBinding();
138 $html = $this->getDefaultRenderer($js_binding)->render($datetime);
139
140 $expected = '$("#id_1").datetimepicker({'
141 . '"showClear":true,'
142 . '"sideBySide":true,'
143 . '"format":"YYYY-MM-DD",'
144 . '"locale":"en"'
145 . '});';
146
147 $onload_js = array_shift($js_binding->on_load_code);
148 $this->assertEquals($expected, $onload_js);
149 }
150}
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:263
getJavaScriptBinding()
Definition: Base.php:294
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
$factory
Definition: metadata.php:58
$format
Definition: metadata.php:218
Class ChatMainBarProvider \MainMenu\Provider.