ILIAS  release_8 Revision v8.24
ViewControlContainerTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once './libs/composer/vendor/autoload.php';
22require_once './tests/UI/Base.php';
23
28use ILIAS\Data;
29use ILIAS\Refinery\Factory as Refinery;
30use 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(ilLanguage::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(UploadLimitResolver::class),
59 new I\SignalGenerator(),
60 $this->buildDataFactory(),
61 $this->buildRefinery(),
62 $this->getLanguage()
63 );
64 }
65
66 protected function buildVCFactory(): Control\Factory
67 {
68 return new Control\Factory(
69 $this->buildFieldFactory(),
70 $this->buildDataFactory(),
71 $this->buildRefinery(),
72 new I\SignalGenerator(),
73 $this->getLanguage(),
74 );
75 }
76
77 public function testViewControlContainerConstruct(): void
78 {
79 $vc = $this->buildContainerFactory()->standard([]);
80 $this->assertInstanceOf(VC\ViewControl::class, $vc);
81 $this->assertInstanceOf(I\Signal::class, $vc->getSubmissionSignal());
82 }
83
85 {
86 $c_factory = $this->buildVCFactory();
87 $controls = [
88 $c_factory->fieldSelection([]),
89 $c_factory->sortation([]),
90 $c_factory->pagination()
91 ];
92
93 $name_source = new FormInputNameSource();
94 $vc = $this->buildContainerFactory()->standard($controls);
95 $this->assertSameSize($controls, $vc->getInputs());
96
97 $named = array_map(
98 fn ($input) => $input->withNameFrom($name_source, 'view_control'),
99 $vc->getInputs()
100 );
101
102 $this->assertEquals($named, $vc->getInputs());
103 }
104
106 {
107 $request = $this->createMock(ServerRequestInterface::class);
108 $request
109 ->expects($this->once())
110 ->method("getQueryParams")
111 ->willReturn([
112 'view_control/input_0' => ['a1', 'a3'],
113 'view_control/input_1/input_2' => 'a2',
114 'view_control/input_1/input_3' => 'DESC'
115 ]);
116
117 $c_factory = $this->buildVCFactory();
118 $controls = [
119 $c_factory->fieldSelection(['a1' => 'A','a2' => 'B','a3' => 'C']),
120 $c_factory->sortation([
121 '2up' => new Data\Order('a2', 'ASC'),
122 '2down' => new Data\Order('a2', 'DESC')
123 ]),
124 ];
125
126 $vc = $this->buildContainerFactory()->standard($controls);
127 $vc2 = $vc->withRequest($request);
128 $this->assertNotSame($vc2, $vc);
129
130 $data = $vc2->getData();
131 $this->assertSameSize($controls, $data);
132
133 $expected = [
134 ['a1','a3'],
135 $this->buildDataFactory()->order('a2', 'DESC')
136 ];
137 $this->assertEquals($expected, array_values($data));
138 }
139
141 {
142 $transform = $this->buildRefinery()->custom()->transformation(
143 fn ($v) => ['modified' => 'transformed']
144 );
145
146 $request = $this->createMock(ServerRequestInterface::class);
147 $request->expects($this->once())
148 ->method("getQueryParams")
149 ->willReturn(['some' => 'data']);
150
151 $controls = [
152 $this->buildVCFactory()->fieldSelection(['a1' => 'A'])
153 ];
154 $vc = $this->buildContainerFactory()->standard($controls)
155 ->withAdditionalTransformation($transform)
156 ->withRequest($request);
157
158
159 $expected = ['modified' => 'transformed'];
160 $this->assertEquals($expected, $vc->getData());
161 }
162}
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:21
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:13
FormInputNameSource is responsible for generating continuous form input names.
Provides common functionality for UI tests.
Definition: Base.php:299
This is how the factory for UI elements looks.
Definition: Factory.php:31
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...