19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
41 return new class ($deactivation_entries) extends
NullGateway {
43 public array $exposed_deactivation_entries
47 public function createDeactivationEntry(SlotIdentifier $slot):
void
49 $this->exposed_deactivation_entries[] = $slot;
52 public function deleteDeactivationEntry(SlotIdentifier $slot):
void
54 if (!in_array($slot, $this->exposed_deactivation_entries)) {
57 unset($this->exposed_deactivation_entries[array_search($slot, $this->exposed_deactivation_entries)]);
60 public function doesDeactivationEntryExistForSlot(SlotIdentifier $slot):
bool
62 return in_array($slot, $this->exposed_deactivation_entries);
77 return new class ($slot, $values) extends
NullBuilder {
78 protected bool $active =
true;
81 protected SlotIdentifier $slot,
82 protected array $values
89 $clone->active = !$deactivated;
95 return new class ($this->slot, $this->active, $this->values) extends
NullVocabulary {
97 protected SlotIdentifier $slot,
98 protected bool $active,
99 protected array $values
103 public function slot(): SlotIdentifier
108 public function isActive():
bool
110 return $this->active;
114 public function values(): \Generator
116 yield
from $this->values;
128 public function __construct(
protected array $assignments)
132 public function doesSlotHaveValues(SlotIdentifier $slot):
bool
134 return array_key_exists($slot->value, $this->assignments);
137 public function valuesForSlot(SlotIdentifier $slot): \Generator
139 yield
from $this->assignments[$slot->value] ?? [];
147 public function txt(
string $key):
string
149 return 'translated ' . $key;
156 SlotIdentifier $expected_slot,
157 bool $expected_active,
158 string ...$expected_values
160 $this->assertSame($expected_slot, $vocabulary->slot());
164 'Vocab for slot ' . $expected_slot->value .
' activation should be ' . $expected_active
168 iterator_to_array($vocabulary->
values()),
169 'Vocab for slot ' . $expected_slot->value .
' values not correct.'
174 array $expected_content,
175 array $deactivated_slots,
178 $this->assertCount(count($expected_content), $vocabularies);
181 foreach ($expected_content as $expected_slot => $expected_values) {
183 $this->assertVocabularyMatches(
186 !in_array($slot, $deactivated_slots),
195 $already_deactivated = [
196 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
197 SlotIdentifier::CLASSIFICATION_PURPOSE
200 $gateway = $this->getGateway(...$already_deactivated),
201 $this->getVocabFactory(),
202 $this->getAssignments()
208 $already_deactivated,
209 $gateway->exposed_deactivation_entries
215 $already_deactivated = [
216 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
217 SlotIdentifier::CLASSIFICATION_PURPOSE
220 $gateway = $this->getGateway(...$already_deactivated),
221 $this->getVocabFactory(),
222 $this->getAssignments()
225 $repo->deactivateVocabulary(SlotIdentifier::EDUCATIONAL_DIFFICULTY);
228 $already_deactivated,
229 $gateway->exposed_deactivation_entries
235 $already_deactivated = [
236 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
237 SlotIdentifier::CLASSIFICATION_PURPOSE
240 $gateway = $this->getGateway(...$already_deactivated),
241 $this->getVocabFactory(),
242 $this->getAssignments()
245 $repo->deactivateVocabulary(SlotIdentifier::GENERAL_STRUCTURE);
248 array_merge($already_deactivated, [SlotIdentifier::GENERAL_STRUCTURE]),
249 $gateway->exposed_deactivation_entries
255 $already_deactivated = [
256 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
257 SlotIdentifier::CLASSIFICATION_PURPOSE
260 $gateway = $this->getGateway(...$already_deactivated),
261 $this->getVocabFactory(),
262 $this->getAssignments()
268 $already_deactivated,
269 $gateway->exposed_deactivation_entries
275 $already_deactivated = [
276 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
277 SlotIdentifier::CLASSIFICATION_PURPOSE
280 $gateway = $this->getGateway(...$already_deactivated),
281 $this->getVocabFactory(),
282 $this->getAssignments()
285 $repo->activateVocabulary(SlotIdentifier::CLASSIFICATION_PURPOSE);
288 [SlotIdentifier::EDUCATIONAL_DIFFICULTY],
289 $gateway->exposed_deactivation_entries
295 $already_deactivated = [
296 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
297 SlotIdentifier::CLASSIFICATION_PURPOSE
300 $gateway = $this->getGateway(...$already_deactivated),
301 $this->getVocabFactory(),
302 $this->getAssignments()
305 $repo->activateVocabulary(SlotIdentifier::GENERAL_STRUCTURE);
308 $already_deactivated,
309 $gateway->exposed_deactivation_entries
315 $already_deactivated = [
316 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
317 SlotIdentifier::CLASSIFICATION_PURPOSE
320 $gateway = $this->getGateway(...$already_deactivated),
321 $this->getVocabFactory(),
322 $this->getAssignments()
325 $this->assertTrue($repo->isVocabularyActive(SlotIdentifier::GENERAL_STRUCTURE));
330 $already_deactivated = [
331 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
332 SlotIdentifier::CLASSIFICATION_PURPOSE
335 $gateway = $this->getGateway(...$already_deactivated),
336 $this->getVocabFactory(),
337 $this->getAssignments()
340 $this->assertFalse($repo->isVocabularyActive(SlotIdentifier::EDUCATIONAL_DIFFICULTY));
346 $gateway = $this->getGateway(),
347 $this->getVocabFactory(),
348 $this->getAssignments([
349 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2'],
350 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4']
354 $vocab = $repo->getVocabulary(SlotIdentifier::LIFECYCLE_STATUS);
356 $this->assertEmpty(iterator_to_array(
$vocab->values()));
362 $gateway = $this->getGateway(),
363 $this->getVocabFactory(),
364 $this->getAssignments([
365 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2'],
366 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4']
370 $vocab = $repo->getVocabulary(SlotIdentifier::EDUCATIONAL_DIFFICULTY);
371 $this->assertSame(SlotIdentifier::EDUCATIONAL_DIFFICULTY,
$vocab->slot());
372 $this->assertSame([
'value 1',
'value 2'], iterator_to_array(
$vocab->values()));
373 $this->assertTrue(
$vocab->isActive());
379 $gateway = $this->getGateway(SlotIdentifier::EDUCATIONAL_DIFFICULTY),
380 $this->getVocabFactory(),
381 $this->getAssignments([
382 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2'],
383 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4']
387 $vocab = $repo->getVocabulary(SlotIdentifier::EDUCATIONAL_DIFFICULTY);
388 $this->assertSame(SlotIdentifier::EDUCATIONAL_DIFFICULTY,
$vocab->slot());
389 $this->assertSame([
'value 1',
'value 2'], iterator_to_array(
$vocab->values()));
390 $this->assertFalse(
$vocab->isActive());
396 $gateway = $this->getGateway(
397 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
398 SlotIdentifier::LIFECYCLE_STATUS
400 $this->getVocabFactory(),
401 $this->getAssignments([
402 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2'],
403 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4'],
404 SlotIdentifier::LIFECYCLE_STATUS->value => [
'value 5',
'value 6']
408 $vocabs = $repo->getVocabularies(SlotIdentifier::GENERAL_STRUCTURE);
410 $this->assertNull($vocabs->current());
415 $expected_content = [
416 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2'],
417 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4'],
418 SlotIdentifier::LIFECYCLE_STATUS->value => [
'value 5',
'value 6']
420 $deactivated_slots = [
421 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
422 SlotIdentifier::LIFECYCLE_STATUS
426 $gateway = $this->getGateway(...$deactivated_slots),
427 $this->getVocabFactory(),
428 $this->getAssignments($expected_content)
431 $vocabs = $repo->getVocabularies(
432 SlotIdentifier::GENERAL_STRUCTURE,
433 SlotIdentifier::LIFECYCLE_STATUS,
434 SlotIdentifier::CLASSIFICATION_PURPOSE
437 $this->assertVocabulariesMatch(
439 SlotIdentifier::LIFECYCLE_STATUS->value => [
'value 5',
'value 6'],
440 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4']
450 $gateway = $this->getGateway(
451 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
452 SlotIdentifier::LIFECYCLE_STATUS
454 $this->getVocabFactory(),
455 $this->getAssignments([
456 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2'],
457 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4'],
458 SlotIdentifier::LIFECYCLE_STATUS->value => [
'value 5',
'value 6']
462 $vocabs = $repo->getActiveVocabularies(SlotIdentifier::GENERAL_STRUCTURE);
464 $this->assertNull($vocabs->current());
469 $expected_content = [
470 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2'],
471 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4'],
472 SlotIdentifier::LIFECYCLE_STATUS->value => [
'value 5',
'value 6'],
473 SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER->value => [
'value 7',
'value 8']
475 $deactivated_slots = [
476 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
477 SlotIdentifier::LIFECYCLE_STATUS
481 $gateway = $this->getGateway(...$deactivated_slots),
482 $this->getVocabFactory(),
483 $this->getAssignments($expected_content)
486 $vocabs = $repo->getActiveVocabularies(
487 SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER,
488 SlotIdentifier::GENERAL_STRUCTURE,
489 SlotIdentifier::LIFECYCLE_STATUS,
490 SlotIdentifier::CLASSIFICATION_PURPOSE
493 $this->assertVocabulariesMatch(
495 SlotIdentifier::TECHNICAL_REQUIREMENT_BROWSER->value => [
'value 7',
'value 8'],
496 SlotIdentifier::CLASSIFICATION_PURPOSE->value => [
'value 3',
'value 4']
506 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2',
'ProblemStatement',
'ispartof'],
510 $gateway = $this->getGateway(),
511 $this->getVocabFactory(),
512 $this->getAssignments($vocab_values)
515 $labelled_values = $repo->getLabelsForValues(
516 $this->getPresentationUtilities(),
517 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
525 $l1 = $labelled_values->current();
526 $this->assertSame(
'ispartof', $l1->value());
527 $this->assertSame(
'translated meta_is_part_of', $l1->label());
528 $labelled_values->next();
530 $l2 = $labelled_values->current();
531 $this->assertSame(
'value 2', $l2->value());
532 $this->assertSame(
'translated meta_value_2', $l2->label());
533 $labelled_values->next();
535 $l3 = $labelled_values->current();
536 $this->assertSame(
'ProblemStatement', $l3->value());
537 $this->assertSame(
'translated meta_problem_statement', $l3->label());
538 $labelled_values->next();
540 $this->assertNull($labelled_values->current());
546 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2',
'ProblemStatement',
'ispartof'],
550 $gateway = $this->getGateway(),
551 $this->getVocabFactory(),
552 $this->getAssignments($vocab_values)
555 $labelled_values = $repo->getLabelsForValues(
556 $this->getPresentationUtilities(),
557 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
565 $l1 = $labelled_values->current();
566 $this->assertSame(
'ispartof', $l1->value());
567 $this->assertSame(
'translated meta_is_part_of', $l1->label());
568 $labelled_values->next();
570 $l2 = $labelled_values->current();
571 $this->assertSame(
'value 2', $l2->value());
572 $this->assertSame(
'translated meta_value_2', $l2->label());
573 $labelled_values->next();
575 $l3 = $labelled_values->current();
576 $this->assertSame(
'ProblemStatement', $l3->value());
577 $this->assertSame(
'translated meta_problem_statement', $l3->label());
578 $labelled_values->next();
580 $this->assertNull($labelled_values->current());
586 SlotIdentifier::EDUCATIONAL_DIFFICULTY->value => [
'value 1',
'value 2',
'ProblemStatement',
'ispartof'],
590 $gateway = $this->getGateway(SlotIdentifier::EDUCATIONAL_DIFFICULTY),
591 $this->getVocabFactory(),
592 $this->getAssignments($vocab_values)
595 $labelled_values = $repo->getLabelsForValues(
596 $this->getPresentationUtilities(),
597 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
605 $this->assertNull($labelled_values->current());
__construct()
Constructor setup ILIAS global object @access public.