ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
DateTimeInputTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../libs/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../../Base.php");
23 
26 use ILIAS\UI\Component as C;
27 use ILIAS\Data;
30 
32 {
34  protected Data\Factory $data_factory;
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 testWithFormat(): 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 testWithMinValue(): 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 testWithMaxValue(): 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 testWithUseTime(): 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 testWithTimeOnly(): 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 testWithTimeZone(): 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 testWithInvalidTimeZone(): 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 testWithValueThatIsDateTimeImmutable(): void
152  {
153  $string_value = "1985-05-04 00:00";
154  $value = new \DateTimeImmutable($string_value);
155  $datetime = $this->factory->datetime('label', 'byline')
156  ->withValue($value);
157  $this->assertEquals(
158  $string_value,
159  $datetime->getValue()
160  );
161  }
162 
163  public function testWithInvalidValue(): void
164  {
165  $this->expectException(InvalidArgumentException::class);
166  $datetime = $this->factory->datetime('label', 'byline')
167  ->withValue("this is no datetime...");
168  }
169 }
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 .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$datetime
I Input Field Factory $factory
DefNamesource $name_source
Provides common functionality for UI tests.
Definition: Base.php:310
Data Factory $data_factory
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...