ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ViewControlContainerTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once './vendor/composer/vendor/autoload.php';
22require_once './components/ILIAS/UI/tests/Base.php';
23
29use ILIAS\Data;
30use ILIAS\Refinery\Factory as Refinery;
31use Psr\Http\Message\ServerRequestInterface;
34
36{
37 protected function buildDataFactory(): Data\Factory
38 {
39 return new Data\Factory();
40 }
41 protected function buildRefinery(): Refinery
42 {
43 return new Refinery(
44 $this->buildDataFactory(),
45 $this->createMock(ILIAS\Language\Language::class)
46 );
47 }
48 protected function buildContainerFactory(): VC\Factory
49 {
50 return new VC\Factory(
51 new I\SignalGenerator(),
52 $this->buildVCFactory(),
53 );
54 }
55 protected function buildFieldFactory(): FieldFactory
56 {
57 return new FieldFactory(
58 $this->createMock(\ILIAS\UI\Implementation\Component\Input\Field\Node\Factory::class),
59 $this->createMock(UploadLimitResolver::class),
60 new I\SignalGenerator(),
61 $this->buildDataFactory(),
62 $this->buildRefinery(),
63 $this->getLanguage()
64 );
65 }
66
67 protected function buildVCFactory(): Control\Factory
68 {
69 return new Control\Factory(
70 $this->buildFieldFactory(),
71 $this->buildDataFactory(),
72 $this->buildRefinery(),
73 new I\SignalGenerator(),
74 $this->getLanguage(),
75 );
76 }
77
78 public function testViewControlContainerConstruct(): void
79 {
80 $vc = $this->buildContainerFactory()->standard([]);
81 $this->assertInstanceOf(VC\ViewControl::class, $vc);
82 $this->assertInstanceOf(I\Signal::class, $vc->getSubmissionSignal());
83 }
84
86 {
87 $c_factory = $this->buildVCFactory();
88 $controls = [
89 $c_factory->fieldSelection([]),
90 $c_factory->sortation([]),
91 $c_factory->pagination()
92 ];
93
94 $name_source = new FormInputNameSource();
95 $vc = $this->buildContainerFactory()->standard($controls);
96 $this->assertSameSize($controls, $vc->getInputs());
97
98 $named = array_map(
99 fn($input) => $input->withNameFrom($name_source, 'view_control'),
100 $vc->getInputs()
101 );
102
103 $this->assertEquals($named, $vc->getInputs());
104 }
105
107 {
108 $request = $this->createMock(ServerRequestInterface::class);
109 $request
110 ->expects($this->once())
111 ->method("getQueryParams")
112 ->willReturn([
113 'view_control/input_0' => ['a1', 'a3'],
114 'view_control/input_1/input_2' => 'a2',
115 'view_control/input_1/input_3' => 'DESC'
116 ]);
117
118 $c_factory = $this->buildVCFactory();
119 $controls = [
120 $c_factory->fieldSelection(['a1' => 'A','a2' => 'B','a3' => 'C']),
121 $c_factory->sortation([
122 '2up' => new Data\Order('a2', 'ASC'),
123 '2down' => new Data\Order('a2', 'DESC')
124 ]),
125 ];
126
127 $vc = $this->buildContainerFactory()->standard($controls);
128 $vc2 = $vc->withRequest($request);
129 $this->assertNotSame($vc2, $vc);
130
131 $data = $vc2->getData();
132 $this->assertSameSize($controls, $data);
133
134 $expected = [
135 ['a1','a3'],
136 $this->buildDataFactory()->order('a2', 'DESC')
137 ];
138 $this->assertEquals($expected, array_values($data));
139 }
140
142 {
143 $this->expectException(\LogicException::class);
144
145 $c_factory = $this->buildVCFactory();
146 $controls = [
147 $c_factory->fieldSelection(['a1' => 'A','a2' => 'B','a3' => 'C'])
148 ];
149 $vc = $this->buildContainerFactory()->standard($controls);
150 $this->getDefaultRenderer()->render($vc);
151 }
152
154 {
155 $transform = $this->buildRefinery()->custom()->transformation(
156 fn($v) => ['modified' => 'transformed']
157 );
158
159 $request = $this->createMock(ServerRequestInterface::class);
160 $request->expects($this->once())
161 ->method("getQueryParams")
162 ->willReturn(['some' => 'data']);
163
164 $controls = [
165 $this->buildVCFactory()->fieldSelection(['a1' => 'A'])
166 ];
167 $vc = $this->buildContainerFactory()->standard($controls)
168 ->withAdditionalTransformation($transform)
169 ->withRequest($request);
170
171
172 $expected = ['modified' => 'transformed'];
173 $this->assertEquals($expected, $vc->getData());
174 }
175
176 public function testExtractCurrentValues(): void
177 {
178 $c_factory = $this->buildVCFactory();
179 $controls = [
180 $c_factory->fieldSelection(['a1' => 'A','a2' => 'B','a3' => 'C'])
181 ->withValue(['a1', 'a3']),
182 $c_factory->sortation([
183 '2up' => new Data\Order('a2', 'ASC'),
184 '2down' => new Data\Order('a2', 'DESC')
185 ])->withValue(['a2', 'DESC']),
186 ];
187
188 $vc = $this->buildContainerFactory()->standard($controls);
189 $data = $vc->getComponentInternalValues();
190
191 $this->assertEquals(
192 [
193 'view_control/input_0' => ['a1', 'a3'],
194 'view_control/input_1/input_2' => 'a2',
195 'view_control/input_1/input_3' => 'DESC'
196 ],
197 $data
198 );
199 }
200}
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:36
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
FormInputNameSource is responsible for generating continuous form input names.
Definition: UI.php:24
Provides common functionality for UI tests.
Definition: Base.php:337
This is how the factory for UI elements looks.
Definition: Factory.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
getLanguage()