ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
RepositoryTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
24
25class RepositoryTest extends TestCase
26{
27 protected function getRepository(
28 array $returns_on_query
30 return new class ($returns_on_query) extends DatabaseRepository {
31 public array $exposed_queries = [];
32
33 public function __construct(protected array $returns_on_query)
34 {
35 }
36
37 protected function query(string $query): \Generator
38 {
39 $this->exposed_queries[] = $query;
40 yield from $this->returns_on_query;
41 }
42
43 protected function manipulate(string $query): void
44 {
45 $this->exposed_queries[] = $query;
46 }
47
48 protected function quoteInteger(int $integer): string
49 {
50 return '~int:' . $integer . '~';
51 }
52
53 protected function inWithIntegers(string $field, int ...$integers): string
54 {
55 return '~' . $field . '~in~(' . implode(',', $integers) . ')~';
56 }
57 };
58 }
59
60 public function testIsHarvestingBlockedTrue(): void
61 {
62 $repo = $this->getRepository([['blocked' => '1']]);
63
64 $blocked = $repo->isHarvestingBlocked(32);
65
66 $this->assertSame(
67 ['SELECT' . ' blocked FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
68 $repo->exposed_queries
69 );
70 $this->assertTrue($blocked);
71 }
72
73 public function testIsHarvestingBlockedFalse(): void
74 {
75 $repo = $this->getRepository([['blocked' => '0']]);
76
77 $blocked = $repo->isHarvestingBlocked(32);
78
79 $this->assertSame(
80 ['SELECT' . ' blocked FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
81 $repo->exposed_queries
82 );
83 $this->assertFalse($blocked);
84 }
85
87 {
88 $repo = $this->getRepository([]);
89
90 $blocked = $repo->isHarvestingBlocked(32);
91
92 $this->assertSame(
93 ['SELECT' . ' blocked FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
94 $repo->exposed_queries
95 );
96 $this->assertFalse($blocked);
97 }
98
99 public function testSetHarvestingBlockedTrue(): void
100 {
101 $repo = $this->getRepository([]);
102
103 $repo->setHarvestingBlocked(32, true);
104
105 $this->assertSame(
106 [
107 'INSERT' . ' INTO il_meta_oer_stat (obj_id, href_id, blocked) VALUES (' .
108 '~int:32~, ~int:0~, ~int:1~) ON DUPLICATE KEY UPDATE blocked = ~int:1~'
109 ],
110 $repo->exposed_queries
111 );
112 }
113
114 public function testSetHarvestingBlockedFalse(): void
115 {
116 $repo = $this->getRepository([]);
117
118 $repo->setHarvestingBlocked(32, false);
119
120 $this->assertSame(
121 [
122 'INSERT' . ' INTO il_meta_oer_stat (obj_id, href_id, blocked) VALUES (' .
123 '~int:32~, ~int:0~, ~int:0~) ON DUPLICATE KEY UPDATE blocked = ~int:0~'
124 ],
125 $repo->exposed_queries
126 );
127 }
128
129 public function testIsAlreadyHarvestedTrue(): void
130 {
131 $repo = $this->getRepository([['href_id' => '678']]);
132
133 $harvested = $repo->isAlreadyHarvested(32);
134
135 $this->assertSame(
136 ['SELECT' . ' href_id FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
137 $repo->exposed_queries
138 );
139 $this->assertTrue($harvested);
140 }
141
142 public function testIsAlreadyHarvestedFalse(): void
143 {
144 $repo = $this->getRepository([['href_id' => '0']]);
145
146 $harvested = $repo->isAlreadyHarvested(32);
147
148 $this->assertSame(
149 ['SELECT' . ' href_id FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
150 $repo->exposed_queries
151 );
152 $this->assertFalse($harvested);
153 }
154
156 {
157 $repo = $this->getRepository([]);
158
159 $harvested = $repo->isAlreadyHarvested(32);
160
161 $this->assertSame(
162 ['SELECT' . ' href_id FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
163 $repo->exposed_queries
164 );
165 $this->assertFalse($harvested);
166 }
167
168 public function testGetAllHarvestedObjIDs(): void
169 {
170 $repo = $this->getRepository([['obj_id' => '32'], ['obj_id' => '909'], ['obj_id' => '55']]);
171
172 $obj_ids = iterator_to_array($repo->getAllHarvestedObjIDs());
173
174 $this->assertSame(
175 ['SELECT obj_id FROM il_meta_oer_stat WHERE href_id > 0'],
176 $repo->exposed_queries
177 );
178 $this->assertCount(3, $obj_ids);
179 $this->assertSame(32, $obj_ids[0]);
180 $this->assertSame(909, $obj_ids[1]);
181 $this->assertSame(55, $obj_ids[2]);
182 }
183
184 public function testGetHarvestRefID(): void
185 {
186 $repo = $this->getRepository([['href_id' => '90']]);
187
188 $href_id = $repo->getHarvestRefID(32);
189
190 $this->assertSame(
191 ['SELECT' . ' href_id FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
192 $repo->exposed_queries
193 );
194 $this->assertSame(90, $href_id);
195 }
196
197 public function testGetHarvestRefIDNotFound(): void
198 {
199 $repo = $this->getRepository([]);
200
201 $href_id = $repo->getHarvestRefID(32);
202
203 $this->assertSame(
204 ['SELECT' . ' href_id FROM il_meta_oer_stat WHERE obj_id = ~int:32~'],
205 $repo->exposed_queries
206 );
207 $this->assertSame(0, $href_id);
208 }
209
210 public function testSetHarvestRefID(): void
211 {
212 $repo = $this->getRepository([]);
213
214 $repo->setHarvestRefID(32, 90);
215
216 $this->assertSame(
217 [
218 'INSERT' . ' INTO il_meta_oer_stat (obj_id, href_id, blocked) VALUES (' .
219 '~int:32~, ~int:90~, ~int:0~) ON DUPLICATE KEY UPDATE href_id = ~int:90~'
220 ],
221 $repo->exposed_queries
222 );
223 }
224
225 public function testDeleteHarvestRefID(): void
226 {
227 $repo = $this->getRepository([]);
228
229 $repo->deleteHarvestRefID(32);
230
231 $this->assertSame(
232 ['UPDATE' . ' il_meta_oer_stat SET href_id = 0 WHERE obj_id = ~int:32~'],
233 $repo->exposed_queries
234 );
235 }
236
237 public function testFilterOutBlockedObjects(): void
238 {
239 $repo = $this->getRepository([['obj_id' => '5'], ['obj_id' => '123'], ['obj_id' => '876']]);
240
241 $obj_ids = iterator_to_array($repo->filterOutBlockedObjects(32, 5, 909, 123, 876, 55));
242
243 $this->assertSame(
244 [
245 'SELECT' . ' obj_id FROM il_meta_oer_stat WHERE blocked = 1 AND ' .
246 '~obj_id~in~(32,5,909,123,876,55)~'
247 ],
248 $repo->exposed_queries
249 );
250 $this->assertCount(3, $obj_ids);
251 $this->assertSame(32, $obj_ids[0]);
252 $this->assertSame(909, $obj_ids[1]);
253 $this->assertSame(55, $obj_ids[2]);
254 }
255
256 public function testDeleteStatus(): void
257 {
258 $repo = $this->getRepository([]);
259
260 $repo->deleteStatus(32);
261
262 $this->assertSame(
263 ['DELETE FROM' . ' il_meta_oer_stat WHERE obj_id = ~int:32~'],
264 $repo->exposed_queries
265 );
266 }
267}
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...