ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ActionsTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
36
37class ActionsTest extends TestCase
38{
39 public function getVocabulary(
40 Type $type,
41 string $id,
42 SlotIdentifier $slot = SlotIdentifier::NULL
44 return new class ($type, $id, $slot) extends NullVocabulary {
45 public function __construct(
46 protected Type $type,
47 protected string $id,
48 protected SlotIdentifier $slot
49 ) {
50 }
51
52 public function type(): Type
53 {
54 return $this->type;
55 }
56
57 public function id(): string
58 {
59 return $this->id;
60 }
61
62 public function slot(): SlotIdentifier
63 {
64 return $this->slot;
65 }
66 };
67 }
68
69 public function getInfos(
70 bool $is_deactivatable = true,
71 bool $can_disallow_custom_input = true,
72 bool $is_custom_input_applicable = true,
73 bool $can_be_deleted = true
75 return new class (
76 $is_deactivatable,
77 $can_disallow_custom_input,
78 $is_custom_input_applicable,
79 $can_be_deleted
80 ) extends NullInfos {
81 public function __construct(
82 protected bool $is_deactivatable,
83 protected bool $can_disallow_custom_input,
84 protected bool $is_custom_input_applicable,
85 protected bool $can_be_deleted
86 ) {
87 }
88
89 public function isDeactivatable(VocabularyInterface $vocabulary): bool
90 {
91 return $this->is_deactivatable;
92 }
93
94 public function canDisallowCustomInput(VocabularyInterface $vocabulary): bool
95 {
96 return $this->can_disallow_custom_input;
97 }
98
99 public function isCustomInputApplicable(VocabularyInterface $vocabulary): bool
100 {
101 return $this->is_custom_input_applicable;
102 }
103
104 public function canBeDeleted(VocabularyInterface $vocabulary): bool
105 {
106 return $this->can_be_deleted;
107 }
108 };
109 }
110
111 public function getControlledRepo(): ControlledRepo
112 {
113 return new class () extends NullControlledRepo {
114 public array $changes_to_active = [];
115 public array $changes_to_custom_input = [];
116 public array $exposed_deletions = [];
117
118 public function setActiveForVocabulary(
119 string $vocab_id,
120 bool $active
121 ): void {
122 $this->changes_to_active[] = ['id' => $vocab_id, 'active' => $active];
123 }
124
125 public function setCustomInputsAllowedForVocabulary(
126 string $vocab_id,
127 bool $custom_inputs
128 ): void {
129 $this->changes_to_custom_input[] = ['id' => $vocab_id, 'custom_inputs' => $custom_inputs];
130 }
131
132 public function deleteVocabulary(string $vocab_id): void
133 {
134 $this->exposed_deletions[] = $vocab_id;
135 }
136 };
137 }
138
139 public function getStandardRepo(): StandardRepo
140 {
141 return new class () extends NullStandardRepo {
142 public array $changes_to_active = [];
143
144 public function activateVocabulary(SlotIdentifier $slot): void
145 {
146 $this->changes_to_active[] = [
147 'slot' => $slot,
148 'active' => true
149 ];
150 }
151
152 public function deactivateVocabulary(SlotIdentifier $slot): void
153 {
154 $this->changes_to_active[] = [
155 'slot' => $slot,
156 'active' => false
157 ];
158 }
159 };
160 }
161
162 public function testActivateStandard(): void
163 {
164 $actions = new Actions(
165 $this->getInfos(true, false, false, true),
166 $controlled_repo = $this->getControlledRepo(),
167 $standard_repo = $this->getStandardRepo(),
168 );
169 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
170
171 $actions->activate($vocab);
172
173 $this->assertSame(
174 [['slot' => SlotIdentifier::LIFECYCLE_STATUS, 'active' => true]],
175 $standard_repo->changes_to_active
176 );
177 $this->assertEmpty($controlled_repo->changes_to_active);
178 $this->assertEmpty($controlled_repo->changes_to_custom_input);
179 }
180
181 public function testActivateControlledString(): void
182 {
183 $actions = new Actions(
184 $this->getInfos(true, true, true, true),
185 $controlled_repo = $this->getControlledRepo(),
186 $standard_repo = $this->getStandardRepo(),
187 );
188 $vocab = $this->getVocabulary(Type::CONTROLLED_STRING, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
189
190 $actions->activate($vocab);
191
192 $this->assertEmpty($standard_repo->changes_to_active);
193 $this->assertSame(
194 [['id' => 'vocab id', 'active' => true]],
195 $controlled_repo->changes_to_active
196 );
197 $this->assertEmpty($controlled_repo->changes_to_custom_input);
198 }
199
200 public function testActivateControlledVocabValue(): void
201 {
202 $actions = new Actions(
203 $this->getInfos(true, false, false, true),
204 $controlled_repo = $this->getControlledRepo(),
205 $standard_repo = $this->getStandardRepo(),
206 );
207 $vocab = $this->getVocabulary(Type::CONTROLLED_VOCAB_VALUE, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
208
209 $actions->activate($vocab);
210
211 $this->assertEmpty($standard_repo->changes_to_active);
212 $this->assertSame(
213 [['id' => 'vocab id', 'active' => true]],
214 $controlled_repo->changes_to_active
215 );
216 $this->assertEmpty($controlled_repo->changes_to_custom_input);
217 }
218
219 public function testActivateCopyright(): void
220 {
221 $actions = new Actions(
222 $this->getInfos(false, false, true, true),
223 $controlled_repo = $this->getControlledRepo(),
224 $standard_repo = $this->getStandardRepo(),
225 );
226 $vocab = $this->getVocabulary(Type::COPYRIGHT, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
227
228 $actions->activate($vocab);
229
230 $this->assertEmpty($standard_repo->changes_to_active);
231 $this->assertEmpty($controlled_repo->changes_to_active);
232 $this->assertEmpty($controlled_repo->changes_to_custom_input);
233 }
234
236 {
237 $actions = new Actions(
238 $this->getInfos(false, false, false, true),
239 $controlled_repo = $this->getControlledRepo(),
240 $standard_repo = $this->getStandardRepo(),
241 );
242 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
243
244 $this->expectException(\ilMDVocabulariesException::class);
245 $actions->deactivate($vocab);
246 }
247
248 public function testDeactivateStandard(): void
249 {
250 $actions = new Actions(
251 $this->getInfos(true, false, false, true),
252 $controlled_repo = $this->getControlledRepo(),
253 $standard_repo = $this->getStandardRepo(),
254 );
255 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
256
257 $actions->deactivate($vocab);
258
259 $this->assertSame(
260 [['slot' => SlotIdentifier::LIFECYCLE_STATUS, 'active' => false]],
261 $standard_repo->changes_to_active
262 );
263 $this->assertEmpty($controlled_repo->changes_to_active);
264 $this->assertEmpty($controlled_repo->changes_to_custom_input);
265 }
266
267 public function testDeactivateControlledString(): void
268 {
269 $actions = new Actions(
270 $this->getInfos(true, true, true, true),
271 $controlled_repo = $this->getControlledRepo(),
272 $standard_repo = $this->getStandardRepo(),
273 );
274 $vocab = $this->getVocabulary(Type::CONTROLLED_STRING, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
275
276 $actions->deactivate($vocab);
277
278 $this->assertEmpty($standard_repo->changes_to_active);
279 $this->assertSame(
280 [['id' => 'vocab id', 'active' => false]],
281 $controlled_repo->changes_to_active
282 );
283 $this->assertEmpty($controlled_repo->changes_to_custom_input);
284 }
285
287 {
288 $actions = new Actions(
289 $this->getInfos(true, false, false, true),
290 $controlled_repo = $this->getControlledRepo(),
291 $standard_repo = $this->getStandardRepo(),
292 );
293 $vocab = $this->getVocabulary(Type::CONTROLLED_VOCAB_VALUE, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
294
295 $actions->deactivate($vocab);
296
297 $this->assertEmpty($standard_repo->changes_to_active);
298 $this->assertSame(
299 [['id' => 'vocab id', 'active' => false]],
300 $controlled_repo->changes_to_active
301 );
302 $this->assertEmpty($controlled_repo->changes_to_custom_input);
303 }
304
305 public function testDeactivateCopyright(): void
306 {
307 $actions = new Actions(
308 $this->getInfos(true, false, true, true),
309 $controlled_repo = $this->getControlledRepo(),
310 $standard_repo = $this->getStandardRepo(),
311 );
312 $vocab = $this->getVocabulary(Type::COPYRIGHT, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
313
314 $actions->deactivate($vocab);
315
316 $this->assertEmpty($standard_repo->changes_to_active);
317 $this->assertEmpty($controlled_repo->changes_to_active);
318 $this->assertEmpty($controlled_repo->changes_to_custom_input);
319 }
320
322 {
323 $actions = new Actions(
324 $this->getInfos(true, false, false, true),
325 $controlled_repo = $this->getControlledRepo(),
326 $standard_repo = $this->getStandardRepo(),
327 );
328 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
329
330 $this->expectException(\ilMDVocabulariesException::class);
331 $actions->allowCustomInput($vocab);
332 }
333
334 public function testAllowCustomInputStandard(): void
335 {
336 $actions = new Actions(
337 $this->getInfos(true, false, true, true),
338 $controlled_repo = $this->getControlledRepo(),
339 $standard_repo = $this->getStandardRepo(),
340 );
341 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
342
343 $actions->allowCustomInput($vocab);
344
345 $this->assertEmpty($standard_repo->changes_to_active);
346 $this->assertEmpty($controlled_repo->changes_to_active);
347 $this->assertEmpty($controlled_repo->changes_to_custom_input);
348 }
349
351 {
352 $actions = new Actions(
353 $this->getInfos(true, true, true, true),
354 $controlled_repo = $this->getControlledRepo(),
355 $standard_repo = $this->getStandardRepo(),
356 );
357 $vocab = $this->getVocabulary(Type::CONTROLLED_STRING, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
358
359 $actions->allowCustomInput($vocab);
360
361 $this->assertEmpty($standard_repo->changes_to_active);
362 $this->assertEmpty($controlled_repo->changes_to_active);
363 $this->assertSame(
364 [['id' => 'vocab id', 'custom_inputs' => true]],
365 $controlled_repo->changes_to_custom_input
366 );
367 }
368
370 {
371 $actions = new Actions(
372 $this->getInfos(true, false, true, true),
373 $controlled_repo = $this->getControlledRepo(),
374 $standard_repo = $this->getStandardRepo(),
375 );
376 $vocab = $this->getVocabulary(Type::CONTROLLED_VOCAB_VALUE, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
377
378 $actions->allowCustomInput($vocab);
379
380 $this->assertEmpty($standard_repo->changes_to_active);
381 $this->assertEmpty($controlled_repo->changes_to_active);
382 $this->assertEmpty($controlled_repo->changes_to_custom_input);
383 }
384
385 public function testAllowCustomInputCopyright(): void
386 {
387 $actions = new Actions(
388 $this->getInfos(false, false, true, true),
389 $controlled_repo = $this->getControlledRepo(),
390 $standard_repo = $this->getStandardRepo(),
391 );
392 $vocab = $this->getVocabulary(Type::COPYRIGHT, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
393
394 $actions->allowCustomInput($vocab);
395
396 $this->assertEmpty($standard_repo->changes_to_active);
397 $this->assertEmpty($controlled_repo->changes_to_active);
398 $this->assertEmpty($controlled_repo->changes_to_custom_input);
399 }
400
402 {
403 $actions = new Actions(
404 $this->getInfos(true, true, false, true),
405 $controlled_repo = $this->getControlledRepo(),
406 $standard_repo = $this->getStandardRepo(),
407 );
408 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
409
410 $this->expectException(\ilMDVocabulariesException::class);
411 $actions->disallowCustomInput($vocab);
412 }
413
415 {
416 $actions = new Actions(
417 $this->getInfos(true, false, true, true),
418 $controlled_repo = $this->getControlledRepo(),
419 $standard_repo = $this->getStandardRepo(),
420 );
421 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
422
423 $this->expectException(\ilMDVocabulariesException::class);
424 $actions->disallowCustomInput($vocab);
425 }
426
427 public function testDisallowCustomInputStandard(): void
428 {
429 $actions = new Actions(
430 $this->getInfos(true, true, true, true),
431 $controlled_repo = $this->getControlledRepo(),
432 $standard_repo = $this->getStandardRepo(),
433 );
434 $vocab = $this->getVocabulary(Type::STANDARD, '', SlotIdentifier::LIFECYCLE_STATUS);
435
436 $actions->disallowCustomInput($vocab);
437
438 $this->assertEmpty($standard_repo->changes_to_active);
439 $this->assertEmpty($controlled_repo->changes_to_active);
440 $this->assertEmpty($controlled_repo->changes_to_custom_input);
441 }
442
444 {
445 $actions = new Actions(
446 $this->getInfos(true, true, true, true),
447 $controlled_repo = $this->getControlledRepo(),
448 $standard_repo = $this->getStandardRepo(),
449 );
450 $vocab = $this->getVocabulary(Type::CONTROLLED_STRING, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
451
452 $actions->disallowCustomInput($vocab);
453
454 $this->assertEmpty($standard_repo->changes_to_active);
455 $this->assertEmpty($controlled_repo->changes_to_active);
456 $this->assertSame(
457 [['id' => 'vocab id', 'custom_inputs' => false]],
458 $controlled_repo->changes_to_custom_input
459 );
460 }
461
463 {
464 $actions = new Actions(
465 $this->getInfos(true, true, true, true),
466 $controlled_repo = $this->getControlledRepo(),
467 $standard_repo = $this->getStandardRepo(),
468 );
469 $vocab = $this->getVocabulary(Type::CONTROLLED_VOCAB_VALUE, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
470
471 $actions->disallowCustomInput($vocab);
472
473 $this->assertEmpty($standard_repo->changes_to_active);
474 $this->assertEmpty($controlled_repo->changes_to_active);
475 $this->assertEmpty($controlled_repo->changes_to_custom_input);
476 }
477
478 public function testDisallowCustomInputCopyright(): void
479 {
480 $actions = new Actions(
481 $this->getInfos(false, true, true, true),
482 $controlled_repo = $this->getControlledRepo(),
483 $standard_repo = $this->getStandardRepo(),
484 );
485 $vocab = $this->getVocabulary(Type::COPYRIGHT, 'vocab id', SlotIdentifier::LIFECYCLE_STATUS);
486
487 $actions->disallowCustomInput($vocab);
488
489 $this->assertEmpty($standard_repo->changes_to_active);
490 $this->assertEmpty($controlled_repo->changes_to_active);
491 $this->assertEmpty($controlled_repo->changes_to_custom_input);
492 }
493
495 {
496 $actions = new Actions(
497 $this->getInfos(false, true, true, false),
498 $controlled_repo = $this->getControlledRepo(),
499 $standard_repo = $this->getStandardRepo(),
500 );
501
502 $this->expectException(\ilMDVocabulariesException::class);
503 $actions->delete($this->getVocabulary(Type::STANDARD, 'some id'));
504 }
505
506 public function testDeleteStandard(): void
507 {
508 $actions = new Actions(
509 $this->getInfos(false, true, true, true),
510 $controlled_repo = $this->getControlledRepo(),
511 $standard_repo = $this->getStandardRepo(),
512 );
513
514 $actions->delete($this->getVocabulary(Type::STANDARD, 'some id'));
515
516 $this->assertEmpty($controlled_repo->exposed_deletions);
517 }
518
519 public function testDeleteControlledString(): void
520 {
521 $actions = new Actions(
522 $this->getInfos(true, true, true, true),
523 $controlled_repo = $this->getControlledRepo(),
524 $standard_repo = $this->getStandardRepo(),
525 );
526
527 $actions->delete($this->getVocabulary(Type::CONTROLLED_STRING, 'some id'));
528
529 $this->assertSame(
530 ['some id'],
531 $controlled_repo->exposed_deletions
532 );
533 }
534
535 public function testDeleteControlledVocabValue(): void
536 {
537 $actions = new Actions(
538 $this->getInfos(true, true, true, true),
539 $controlled_repo = $this->getControlledRepo(),
540 $standard_repo = $this->getStandardRepo(),
541 );
542
543 $actions->delete($this->getVocabulary(Type::CONTROLLED_VOCAB_VALUE, 'some id'));
544
545 $this->assertSame(
546 ['some id'],
547 $controlled_repo->exposed_deletions
548 );
549 }
550
551 public function testDeleteCopyright(): void
552 {
553 $actions = new Actions(
554 $this->getInfos(true, true, true, true),
555 $controlled_repo = $this->getControlledRepo(),
556 $standard_repo = $this->getStandardRepo(),
557 );
558
559 $actions->delete($this->getVocabulary(Type::COPYRIGHT, 'some id'));
560
561 $this->assertEmpty($controlled_repo->exposed_deletions);
562 }
563}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$vocab
getVocabulary(Type $type, string $id, SlotIdentifier $slot=SlotIdentifier::NULL)
Definition: ActionsTest.php:39
getInfos(bool $is_deactivatable=true, bool $can_disallow_custom_input=true, bool $is_custom_input_applicable=true, bool $can_be_deleted=true)
Definition: ActionsTest.php:69
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76
return true
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