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