ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
DurationInputTest.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
11use ILIAS\Data;
12use ILIAS\Refinery\Validation;
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 buildLanguage()
26 {
27 if (!isset($this->lng)) {
28 $this->lng = $this->createMock(\ilLanguage::class);
29 }
30 return $this->lng;
31 }
32
33 protected function buildRefinery()
34 {
35 return new \ILIAS\Refinery\Factory($this->data_factory, $this->buildLanguage());
36 }
37
38 protected function buildFactory()
39 {
41 new SignalGenerator(),
42 $this->data_factory,
43 $this->buildRefinery(),
44 $this->buildLanguage()
45 );
46 }
47 public function getUIFactory()
48 {
49 $factory = new class extends NoUIFactory {
50 public function symbol() : \ILIAS\UI\Component\Symbol\Factory
51 {
52 return new S\Factory(
53 new S\Icon\Factory(),
54 new S\Glyph\Factory(),
55 new S\Avatar\Factory()
56 );
57 }
58 };
59 return $factory;
60 }
61
62 public function test_withFormat()
63 {
64 $format = $this->data_factory->dateFormat()->germanShort();
65 $duration = $this->factory->duration('label', 'byline')
66 ->withFormat($format);
67
68 $this->assertEquals(
69 $format,
70 $duration->getFormat()
71 );
72 }
73
74 public function test_withMinValue()
75 {
76 $dat = new \DateTimeImmutable('2019-01-09');
77 $duration = $this->factory->duration('label', 'byline')
78 ->withMinValue($dat);
79
80 $this->assertEquals(
81 $dat,
82 $duration->getMinValue()
83 );
84 }
85
86 public function test_withMaxValue()
87 {
88 $dat = new \DateTimeImmutable('2019-01-09');
89 $duration = $this->factory->duration('label', 'byline')
90 ->withMaxValue($dat);
91
92 $this->assertEquals(
93 $dat,
94 $duration->getMaxValue()
95 );
96 }
97
98 public function test_withUseTime()
99 {
100 $datetime = $this->factory->duration('label', 'byline');
101 $this->assertFalse($datetime->getUseTime());
102 $this->assertTrue($datetime->withUseTime(true)->getUseTime());
103 }
104
105 public function test_withTimeOnly()
106 {
107 $datetime = $this->factory->duration('label', 'byline');
108 $this->assertFalse($datetime->getTimeOnly());
109 $this->assertTrue($datetime->withTimeOnly(true)->getTimeOnly());
110 }
111
112 public function test_withTimeZone()
113 {
114 $datetime = $this->factory->duration('label', 'byline');
115 $this->assertNull($datetime->getTimeZone());
116 $tz = 'Europe/Moscow';
117 $this->assertEquals(
118 $tz,
119 $datetime->withTimeZone($tz)->getTimeZone()
120 );
121 }
122
123 public function test_withInvalidTimeZone()
124 {
125 $this->expectException(\InvalidArgumentException::class);
126 $datetime = $this->factory->duration('label', 'byline');
127 $tz = 'NOT/aValidTZ';
128 $datetime->withTimeZone($tz);
129 }
130}
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
A transformation is a function from one datatype to another.
Describes a source for input names.
Definition: NameSource.php:11
$factory
Definition: metadata.php:58
$format
Definition: metadata.php:218
$lng