ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
HistoryTableTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27use ILIAS\LegalDocuments\test\ContainerMock;
32use PHPUnit\Framework\TestCase;
34use ilDateTime;
35use DateTimeImmutable;
36
37require_once __DIR__ . '/../ContainerMock.php';
38
39class HistoryTableTest extends TestCase
40{
41 use ContainerMock;
42
43 public function testConstruct(): void
44 {
45 $this->assertInstanceOf(HistoryTable::class, new HistoryTable(
46 $this->mock(HistoryRepository::class),
47 $this->mock(ProvideDocument::class),
48 'reset',
49 'auto-complete-link',
50 $this->mock(UI::class),
51 $this->mock(DocumentModal::class),
52 $this->fail(...)
53 ));
54 }
55
56 public function testColumns(): void
57 {
58 $ui = $this->mock(UI::class);
59 $ui->expects(self::exactly(6))->method('txt')->willReturnCallback(fn($key) => 'txt: ' . $key);
60
61 $instance = new HistoryTable(
62 $this->mock(HistoryRepository::class),
63 $this->mock(ProvideDocument::class),
64 'reset',
65 'auto-complete-link',
66 $ui,
67 $this->mock(DocumentModal::class),
68 $this->fail(...)
69 );
70
71 $this->assertSame([
72 'created' => ['txt: tbl_hist_head_acceptance_date', 'created'],
73 'login' => ['txt: tbl_hist_head_login', 'login'],
74 'firstname' => ['txt: tbl_hist_head_firstname', 'firstname'],
75 'lastname' => ['txt: tbl_hist_head_lastname', 'lastname'],
76 'document' => ['txt: tbl_hist_head_document', 'document'],
77 'criteria' => ['txt: tbl_hist_head_criteria'],
78 ], $instance->columns());
79 }
80
81 public function testConfig(): void
82 {
83 class_exists(ilDateTime::class, true); // Trigger autoload to ensure IL_CAL_UNIX is defined.
84 $filter = $this->mock(TableFilter::class);
85 $filter->expects(self::exactly(2))->method('addFilterItem');
86
87 $config = $this->mock(TableConfig::class);
88 $config->expects(self::once())->method('setTitle')->with('txt: acceptance_history');
89 $config->expects(self::once())->method('setDefaultOrderField')->with('created');
90 $config->expects(self::once())->method('setDefaultOrderDirection')->with('DESC');
91 $config->expects(self::once())->method('setSelectableColumns')->with('firstname', 'lastname', 'criteria');
92 $config->expects(self::once())->method('asFilter')->with('reset command')->willReturn($filter);
93
94 $ui = $this->mock(UI::class);
95 $ui->method('txt')->willReturnCallback(fn($key) => 'txt: ' . $key);
96
97 $instance = new HistoryTable(
98 $this->mock(HistoryRepository::class),
99 $this->mock(ProvideDocument::class),
100 'reset command',
101 'auto-complete-link',
102 $ui,
103 $this->mock(DocumentModal::class),
104 $this->mock(...)
105 );
106
107 $instance->config($config);
108 }
109
110 public function testRows(): void
111 {
112 $expected_filter = ['a' => 'b', 'start' => 'x', 'end' => 'y', 'c' => 'd'];
113 $repository = $this->mock(HistoryRepository::class);
114 $repository->expects(self::once())->method('countAll')->with($expected_filter)->willReturn(2);
115 $repository->expects(self::once())->method('all')->with(
116 $expected_filter,
117 ['foo' => 'bar'],
118 4,
119 34
120 )->willReturn([
121 $this->mock(History::class),
122 $this->mock(History::class),
123 ]);
124
125 $selection = $this->mockTree(TableSelection::class, [
126 'filter' => ['a' => 'b','period' => ['start' => 'x', 'end' => 'y'] ,'c' => 'd'],
127 'getOrderField' => 'foo',
128 'getOrderDirection' => 'bar',
129 'getOffset' => 4,
130 'getLimit' => 34,
131 ]);
132 $selection->expects(self::once())->method('setMaxCount')->with(2);
133
134 $instance = new HistoryTable(
135 $repository,
136 $this->mock(ProvideDocument::class),
137 'reset command',
138 'auto-complete-link',
139 $this->mock(UI::class),
140 $this->mock(DocumentModal::class),
141 $this->mock(...),
142 fn(DateTimeImmutable $date) => 'formated'
143 );
144
145 $this->assertSame([[
146 'created' => 'formated',
147 'login' => '',
148 'firstname' => '',
149 'lastname' => '',
150 'document' => [],
151 'criteria' => '',
152 ], [
153 'created' => 'formated',
154 'login' => '',
155 'firstname' => '',
156 'lastname' => '',
157 'document' => [],
158 'criteria' => '',
159 ]], $instance->rows($selection));
160 }
161
162 public function testName(): void
163 {
164 $instance = new HistoryTable(
165 $this->mock(HistoryRepository::class),
166 $this->mock(ProvideDocument::class),
167 'reset command',
168 'auto-complete-link',
169 $this->mock(UI::class),
170 $this->mock(DocumentModal::class),
171 $this->fail(...)
172 );
173
174 $this->assertSame(HistoryTable::class, $instance->name());
175 }
176}
@classDescription Date and time handling
ILIAS DI UIServices $ui