ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 ()
 

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 ?array $filter_data,
50 ?array $additional_parameters
51 ): \Generator {
52 yield $row_builder->buildStandardRow('', []);
53 }
54 public function getTotalRowCount(
55 ?array $filter_data,
56 ?array $additional_parameters
57 ): ?int {
58 return $this->total_count;
59 }
60 };
61 }
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().

+ 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 201 of file DataViewControlsTest.php.

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

Referenced by testDataTableViewControlStorage().

+ Here is the caller graph for this function:

◆ getTable()

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

Definition at line 63 of file DataViewControlsTest.php.

63 : array
64 {
65 $factory = $this->getTableFactory();
66 $table = $factory->data($this->getDataRetrieval($total_count), 'Table', $columns);
67 return $table->applyViewControls([], []);
68 }
getDataRetrieval(int $total_count)

References getDataRetrieval(), 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:

◆ testDataTableHasNoFieldSelectionViewControl()

DataViewControlsTest::testDataTableHasNoFieldSelectionViewControl ( )

Definition at line 181 of file DataViewControlsTest.php.

181 : void
182 {
183 $factory = $this->getTableFactory();
184 $columns = [
185 'f1' => $factory->column()->text('f1'),
186 'f2' => $factory->column()->text('f2'),
187 ];
188 $total_count = 200;
189 list($table, $view_controls) = $this->getTable($total_count, $columns);
190
191 $this->assertEquals(
192 [
193 C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
194 C\Table\Data::VIEWCONTROL_KEY_ORDERING,
195 ],
196 array_keys($view_controls->getInputs())
197 );
198 }
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 124 of file DataViewControlsTest.php.

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

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 153 of file DataViewControlsTest.php.

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

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 94 of file DataViewControlsTest.php.

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

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

+ Here is the call graph for this function:

◆ testDataTableHasViewControls()

DataViewControlsTest::testDataTableHasViewControls ( )

Definition at line 70 of file DataViewControlsTest.php.

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

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

+ Here is the call graph for this function:

◆ testDataTableViewControlStorage()

DataViewControlsTest::testDataTableViewControlStorage ( )

Definition at line 213 of file DataViewControlsTest.php.

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

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: