ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
DataViewControlsTest Class Reference

Tests for the Data Table. More...

+ Inheritance diagram for DataViewControlsTest:
+ Collaboration diagram for DataViewControlsTest:

Public Member Functions

 testDataTableHasViewControls ()
 
 testDataTableHasNoPaginationViewControl ()
 
 testDataTableHasNoOrderingViewControl ()
 
 testDataTableHasNoOrderingViewControlDueToRecordCount ()
 
 testDataTableHasNoFieldSelectionViewControl ()
 
 testDataTableViewControlStorage ()
 
 testDataTableHasNoFieldSelectionButAdditionalViewControl ()
 

Protected Member Functions

 getDataRetrieval (int $total_count)
 
 getTable (int $total_count, array $columns)
 
- Protected Member Functions inherited from TableTestBase
 buildFieldFactory ()
 
 buildRefinery ()
 
 getViewControlFactory ()
 
 getViewControlContainerFactory ()
 
 getTableFactory ()
 
 getMockStorage ()
 

Private Member Functions

 getRequestMock (array $returns)
 

Detailed Description

Tests for the Data Table.

Definition at line 35 of file DataViewControlsTest.php.

Member Function Documentation

◆ getDataRetrieval()

DataViewControlsTest::getDataRetrieval ( int  $total_count)
protected

Definition at line 37 of file DataViewControlsTest.php.

37 : I\Table\DataRetrieval
38 {
39 return new class ($total_count) implements I\Table\DataRetrieval {
40 public function __construct(
41 protected int $total_count
42 ) {
43 }
44 public function getRows(
45 I\Table\DataRowBuilder $row_builder,
46 array $visible_column_ids,
48 Order $order,
49 mixed $additional_viewcontrol_data,
50 mixed $filter_data,
51 mixed $additional_parameters
52 ): \Generator {
53 yield $row_builder->buildStandardRow('', []);
54 }
55 public function getTotalRowCount(
56 mixed $additional_viewcontrol_data,
57 mixed $filter_data,
58 mixed $additional_parameters
59 ): ?int {
60 return $this->total_count;
61 }
62 };
63 }
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
A simple class to express a naive range of whole positive numbers.
Definition: Range.php:29
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\UI\Implementation\Component\Table\$range, and ILIAS\GlobalScreen\Provider\__construct().

Referenced by getTable(), and testDataTableHasNoFieldSelectionButAdditionalViewControl().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRequestMock()

DataViewControlsTest::getRequestMock ( array  $returns)
private

Definition at line 205 of file DataViewControlsTest.php.

205 : ServerRequestInterface
206 {
207 $request = $this->createMock(ServerRequestInterface::class);
208 $request
209 ->method("getUri")
210 ->willReturn(new \GuzzleHttp\Psr7\Uri('http://localhost:80'));
211 $request
212 ->method("getQueryParams")
213 ->willReturn($returns);
214 return $request;
215 }

Referenced by getTable(), testDataTableHasNoFieldSelectionButAdditionalViewControl(), and testDataTableViewControlStorage().

+ Here is the caller graph for this function:

◆ getTable()

DataViewControlsTest::getTable ( int  $total_count,
array  $columns 
)
protected

Definition at line 65 of file DataViewControlsTest.php.

65 : array
66 {
67 $factory = $this->getTableFactory();
68 $table = $factory->data($this->getDataRetrieval($total_count), 'Table', $columns);
69 return $table
70 ->withRequest($this->getRequestMock([]))
71 ->applyViewControls([], []);
72 }
getRequestMock(array $returns)
getDataRetrieval(int $total_count)

References getDataRetrieval(), getRequestMock(), and TableTestBase\getTableFactory().

Referenced by testDataTableHasNoFieldSelectionViewControl(), testDataTableHasNoOrderingViewControl(), testDataTableHasNoOrderingViewControlDueToRecordCount(), testDataTableHasNoPaginationViewControl(), testDataTableHasViewControls(), and testDataTableViewControlStorage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testDataTableHasNoFieldSelectionButAdditionalViewControl()

DataViewControlsTest::testDataTableHasNoFieldSelectionButAdditionalViewControl ( )

Definition at line 266 of file DataViewControlsTest.php.

266 : void
267 {
268 $factory = $this->getTableFactory();
269 $columns = [
270 'f1' => $factory->column()->text('f1'),
271 'f2' => $factory->column()->text('f2'),
272 ];
273 $total_count = 200;
274 $table = $factory->data($this->getDataRetrieval($total_count), 'Table', $columns)
275 ->withAdditionalViewControl(
276 $this->getViewControlFactory()->mode([
277 'mode1' => 'a mode',
278 'mode2' => 'another mode'
279 ])
280 )
281 ->withId('testing_data_table_id')
282 ->withRequest(
283 $this->getRequestMock([
284 'vctesting_data_table_id/additional_12' => 'mode2'
285 ])
286 );
287 list($table, $view_controls) = $table->applyViewControls([], []);
288
289 $this->assertEquals(
290 [
291 C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
292 C\Table\Data::VIEWCONTROL_KEY_ORDERING,
293 0
294 ],
295 array_keys($view_controls->getInputs())
296 );
297
298 $this->assertEquals(
299 ['mode2'],
300 $table->getAdditionalViewControlData()
301 );
302 }

References getDataRetrieval(), getRequestMock(), TableTestBase\getTableFactory(), and TableTestBase\getViewControlFactory().

+ Here is the call graph for this function:

◆ testDataTableHasNoFieldSelectionViewControl()

DataViewControlsTest::testDataTableHasNoFieldSelectionViewControl ( )

Definition at line 185 of file DataViewControlsTest.php.

185 : void
186 {
187 $factory = $this->getTableFactory();
188 $columns = [
189 'f1' => $factory->column()->text('f1'),
190 'f2' => $factory->column()->text('f2'),
191 ];
192 $total_count = 200;
193 list($table, $view_controls) = $this->getTable($total_count, $columns);
194
195 $this->assertEquals(
196 [
197 C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
198 C\Table\Data::VIEWCONTROL_KEY_ORDERING,
199 ],
200 array_keys($view_controls->getInputs())
201 );
202 }
getTable(int $total_count, array $columns)

References getTable(), and TableTestBase\getTableFactory().

+ Here is the call graph for this function:

◆ testDataTableHasNoOrderingViewControl()

DataViewControlsTest::testDataTableHasNoOrderingViewControl ( )

Definition at line 128 of file DataViewControlsTest.php.

128 : void
129 {
130 $factory = $this->getTableFactory();
131 $columns = [
132 'f1' => $factory->column()->text('f1')
133 ->withIsSortable(false),
134 'f2' => $factory->column()->text('f2')
135 ->withIsSortable(false)
136 ->withIsOptional(true),
137 ];
138 $total_count = 200;
139 list($table, $view_controls) = $this->getTable($total_count, $columns);
140
141
142 $inputs = $view_controls->getInputs();
143 $this->assertEquals(
144 [
145 C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
146 C\Table\Data::VIEWCONTROL_KEY_ORDERING,
147 C\Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
148 ],
149 array_keys($inputs)
150 );
151 $this->assertInstanceOf(
152 I\Input\ViewControl\Group::class,
153 $inputs[C\Table\Data::VIEWCONTROL_KEY_ORDERING]
154 );
155 }

References ILIAS\UI\Implementation\Component\Input\$inputs, getTable(), and TableTestBase\getTableFactory().

+ Here is the call graph for this function:

◆ testDataTableHasNoOrderingViewControlDueToRecordCount()

DataViewControlsTest::testDataTableHasNoOrderingViewControlDueToRecordCount ( )

Definition at line 157 of file DataViewControlsTest.php.

157 : void
158 {
159 $factory = $this->getTableFactory();
160 $columns = [
161 'f1' => $factory->column()->text('f1')
162 ->withIsSortable(true),
163 'f2' => $factory->column()->text('f2')
164 ->withIsSortable(true)
165 ->withIsOptional(true),
166 ];
167 $total_count = 1;
168 list($table, $view_controls) = $this->getTable($total_count, $columns);
169
170 $inputs = $view_controls->getInputs();
171 $this->assertEquals(
172 [
173 C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
174 C\Table\Data::VIEWCONTROL_KEY_ORDERING,
175 C\Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
176 ],
177 array_keys($inputs)
178 );
179 $this->assertInstanceOf(
180 I\Input\ViewControl\Group::class,
181 $inputs[C\Table\Data::VIEWCONTROL_KEY_ORDERING]
182 );
183 }

References ILIAS\UI\Implementation\Component\Input\$inputs, getTable(), and TableTestBase\getTableFactory().

+ Here is the call graph for this function:

◆ testDataTableHasNoPaginationViewControl()

DataViewControlsTest::testDataTableHasNoPaginationViewControl ( )

Definition at line 98 of file DataViewControlsTest.php.

98 : void
99 {
100 $factory = $this->getTableFactory();
101 $columns = [
102 'f1' => $factory->column()->text('f1'),
103 'f2' => $factory->column()->text('f2')->withIsOptional(true),
104 ];
105 $total_count = current(C\Input\ViewControl\Pagination::DEFAULT_LIMITS) - 1;
106 list($table, $view_controls) = $this->getTable($total_count, $columns);
107
108 $this->assertEquals(
109 [
110 C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
111 C\Table\Data::VIEWCONTROL_KEY_ORDERING,
112 C\Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
113 ],
114 array_keys($view_controls->getInputs())
115 );
116 $this->assertInstanceOf(
117 I\Input\ViewControl\Group::class,
118 $view_controls->getInputs()[C\Table\Data::VIEWCONTROL_KEY_PAGINATION]
119 );
120
121 $group_contents = $view_controls->getInputs()[C\Table\Data::VIEWCONTROL_KEY_PAGINATION]->getInputs();
122 array_walk(
123 $group_contents,
124 fn($vc) => $this->assertInstanceOf(I\Input\ViewControl\NullControl::class, $vc)
125 );
126 }

References getTable(), and TableTestBase\getTableFactory().

+ Here is the call graph for this function:

◆ testDataTableHasViewControls()

DataViewControlsTest::testDataTableHasViewControls ( )

Definition at line 74 of file DataViewControlsTest.php.

74 : void
75 {
76 $factory = $this->getTableFactory();
77 $columns = [
78 'f1' => $factory->column()->text('f1'),
79 'f2' => $factory->column()->text('f2')->withIsOptional(true),
80 ];
81 $total_count = 12;
82 list($table, $view_controls) = $this->getTable($total_count, $columns);
83
84 $this->assertInstanceOf(I\Input\Container\ViewControl\ViewControl::class, $view_controls);
85 $this->assertEquals(
86 [
87 C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
88 C\Table\Data::VIEWCONTROL_KEY_ORDERING,
89 C\Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
90 ],
91 array_keys($view_controls->getInputs())
92 );
93 foreach (array_values($view_controls->getInputs()) as $vc) {
94 $this->assertInstanceOf(I\Input\Container\ViewControl\ViewControlInput::class, $vc);
95 }
96 }

References getTable(), and TableTestBase\getTableFactory().

+ Here is the call graph for this function:

◆ testDataTableViewControlStorage()

DataViewControlsTest::testDataTableViewControlStorage ( )

Definition at line 217 of file DataViewControlsTest.php.

217 : void
218 {
219 $factory = $this->getTableFactory();
220 $columns = [
221 'f1' => $factory->column()->text('f1')->withIsOptional(true),
222 'f2' => $factory->column()->text('f2')->withIsOptional(true),
223 'f3' => $factory->column()->text('f3')->withIsOptional(true),
224 ];
225 $total_count = 12;
226 list($base_table, $view_controls) = $this->getTable($total_count, $columns);
227
228 $table_id = 'testing_data_table';
229 $table = $base_table
230 ->withId($table_id)
231 ->withRequest(
232 $this->getRequestMock([
233 'vctesting_data_table/input_7/input_8' => 0,
234 'vctesting_data_table/input_7/input_9' => 10,
235 'vctesting_data_table/input_10/input_11' => 'f2',
236 'vctesting_data_table/input_10/input_12' => 'DESC',
237 'vctesting_data_table/input_13' => ['f2']
238 ])
239 );
240 list($table, $view_controls) = $table->applyViewControls([], []);
241
242 //applied values from viewcontrols
243 $this->assertEquals(new Range(0, 10), $table->getRange());
244 $this->assertEquals(new Order('f2', Order::DESC), $table->getOrder());
245 $this->assertEquals(1, count($table->getSelectedOptionalColumns()));
246
247 //default_values for different id
248 $table = $base_table
249 ->withId('other id')
250 ->withRequest($this->getRequestMock([]));
251 list($table, $view_controls) = $table->applyViewControls([], []);
252 $this->assertEquals(new Range(0, 12), $table->getRange());
253 $this->assertEquals(new Order('f1', Order::ASC), $table->getOrder());
254 $this->assertEquals(3, count($table->getSelectedOptionalColumns()));
255
256 //applied values from session with empty request
257 $table = $base_table
258 ->withId($table_id)
259 ->withRequest($this->getRequestMock([]));
260 list($table, $view_controls) = $table->applyViewControls([], []);
261 $this->assertEquals(new Range(0, 10), $table->getRange());
262 $this->assertEquals(new Order('f2', Order::DESC), $table->getOrder());
263 $this->assertEquals(1, count($table->getSelectedOptionalColumns()));
264 }

References getRequestMock(), getTable(), and TableTestBase\getTableFactory().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: