19declare(strict_types=1);
21require_once(
"vendor/composer/vendor/autoload.php");
22require_once(__DIR__ .
"/TableTestBase.php");
29use Psr\Http\Message\ServerRequestInterface;
39 return new class ($total_count) implements
I\
Table\DataRetrieval {
41 protected int $total_count
44 public function getRows(
45 I\
Table\DataRowBuilder $row_builder,
46 array $visible_column_ids,
49 mixed $additional_viewcontrol_data,
51 mixed $additional_parameters
53 yield $row_builder->buildStandardRow(
'', []);
55 public function getTotalRowCount(
56 mixed $additional_viewcontrol_data,
58 mixed $additional_parameters
60 return $this->total_count;
65 protected function getTable(
int $total_count, array $columns): array
68 $table = $factory->data($this->
getDataRetrieval($total_count),
'Table', $columns);
71 ->applyViewControls([], []);
78 'f1' => $factory->column()->text(
'f1'),
79 'f2' => $factory->column()->text(
'f2')->withIsOptional(
true),
82 list($table, $view_controls) = $this->
getTable($total_count, $columns);
84 $this->assertInstanceOf(
I\Input\
Container\ViewControl\ViewControl::class, $view_controls);
87 C\
Table\Data::VIEWCONTROL_KEY_PAGINATION,
88 C\
Table\Data::VIEWCONTROL_KEY_ORDERING,
89 C\
Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
91 array_keys($view_controls->getInputs())
93 foreach (array_values($view_controls->getInputs()) as $vc) {
94 $this->assertInstanceOf(
I\Input\
Container\ViewControl\ViewControlInput::class, $vc);
102 'f1' => $factory->column()->text(
'f1'),
103 'f2' => $factory->column()->text(
'f2')->withIsOptional(
true),
105 $total_count = current(
C\Input\ViewControl\Pagination::DEFAULT_LIMITS) - 1;
106 list($table, $view_controls) = $this->
getTable($total_count, $columns);
110 C\
Table\Data::VIEWCONTROL_KEY_PAGINATION,
111 C\
Table\Data::VIEWCONTROL_KEY_ORDERING,
112 C\
Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
114 array_keys($view_controls->getInputs())
116 $this->assertInstanceOf(
117 I\Input\ViewControl\Group::class,
118 $view_controls->getInputs()[
C\
Table\Data::VIEWCONTROL_KEY_PAGINATION]
121 $group_contents = $view_controls->getInputs()[C\Table\Data::VIEWCONTROL_KEY_PAGINATION]->getInputs();
124 fn($vc) => $this->assertInstanceOf(
I\Input\ViewControl\NullControl::class, $vc)
132 'f1' => $factory->column()->text(
'f1')
133 ->withIsSortable(
false),
134 'f2' => $factory->column()->text(
'f2')
135 ->withIsSortable(
false)
136 ->withIsOptional(
true),
139 list($table, $view_controls) = $this->
getTable($total_count, $columns);
142 $inputs = $view_controls->getInputs();
145 C\
Table\Data::VIEWCONTROL_KEY_PAGINATION,
146 C\
Table\Data::VIEWCONTROL_KEY_ORDERING,
147 C\
Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
151 $this->assertInstanceOf(
152 I\Input\ViewControl\Group::class,
161 'f1' => $factory->column()->text(
'f1')
162 ->withIsSortable(
true),
163 'f2' => $factory->column()->text(
'f2')
164 ->withIsSortable(
true)
165 ->withIsOptional(
true),
168 list($table, $view_controls) = $this->
getTable($total_count, $columns);
170 $inputs = $view_controls->getInputs();
173 C\
Table\Data::VIEWCONTROL_KEY_PAGINATION,
174 C\
Table\Data::VIEWCONTROL_KEY_ORDERING,
175 C\
Table\Data::VIEWCONTROL_KEY_FIELDSELECTION,
179 $this->assertInstanceOf(
180 I\Input\ViewControl\Group::class,
189 'f1' => $factory->column()->text(
'f1'),
190 'f2' => $factory->column()->text(
'f2'),
193 list($table, $view_controls) = $this->
getTable($total_count, $columns);
197 C\
Table\Data::VIEWCONTROL_KEY_PAGINATION,
198 C\
Table\Data::VIEWCONTROL_KEY_ORDERING,
200 array_keys($view_controls->getInputs())
207 $request = $this->createMock(ServerRequestInterface::class);
210 ->willReturn(
new \GuzzleHttp\Psr7\Uri(
'http://localhost:80'));
212 ->method(
"getQueryParams")
213 ->willReturn($returns);
221 'f1' => $factory->column()->text(
'f1')->withIsOptional(
true),
222 'f2' => $factory->column()->text(
'f2')->withIsOptional(
true),
223 'f3' => $factory->column()->text(
'f3')->withIsOptional(
true),
226 list($base_table, $view_controls) = $this->
getTable($total_count, $columns);
228 $table_id =
'testing_data_table';
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']
240 list($table, $view_controls) = $table->applyViewControls([], []);
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()));
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()));
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()));
270 'f1' => $factory->column()->text(
'f1'),
271 'f2' => $factory->column()->text(
'f2'),
274 $table = $factory->data($this->
getDataRetrieval($total_count),
'Table', $columns)
275 ->withAdditionalViewControl(
278 'mode2' =>
'another mode'
281 ->withId(
'testing_data_table_id')
284 'vctesting_data_table_id/additional_12' =>
'mode2'
287 list($table, $view_controls) = $table->applyViewControls([], []);
291 C\
Table\Data::VIEWCONTROL_KEY_PAGINATION,
292 C\
Table\Data::VIEWCONTROL_KEY_ORDERING,
295 array_keys($view_controls->getInputs())
300 $table->getAdditionalViewControlData()
Tests for the Data Table.
testDataTableHasNoFieldSelectionViewControl()
testDataTableHasNoPaginationViewControl()
getRequestMock(array $returns)
testDataTableHasNoOrderingViewControl()
testDataTableHasNoOrderingViewControlDueToRecordCount()
testDataTableViewControlStorage()
testDataTableHasNoFieldSelectionButAdditionalViewControl()
getDataRetrieval(int $total_count)
getTable(int $total_count, array $columns)
testDataTableHasViewControls()
Both the subject and the direction need to be specified when expressing an order.
A simple class to express a naive range of whole positive numbers.
Basic Tests for all Tables.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc