19declare(strict_types=1);
23use PHPUnit\Framework\TestCase;
48 protected SlotIdentifier $slot,
49 protected array $values
53 public function type():
Type
58 public function slot(): SlotIdentifier
63 public function values(): \Generator
65 yield
from $this->values;
73 public function txt(
string $key):
string
75 return 'translated suffix';
81 SlotIdentifier $slot_with_vocab,
82 string ...$values_from_vocab
84 return new class ($slot_with_vocab, $values_from_vocab) extends NullCopyrightBridge {
86 protected SlotIdentifier $slot_with_vocab,
87 protected array $values_from_vocab
91 public function labelsForValues(
95 foreach ($values as $value) {
96 if ($slot !== $this->slot_with_vocab) {
99 if (!in_array($value, $this->values_from_vocab)) {
102 yield
new class ($value) extends NullLabelledValue {
103 public function __construct(
protected string $value)
107 public function value(): string
112 public function label(): string
114 return 'copyright label for ' . $this->value;
123 SlotIdentifier $slot_with_vocab,
126 string ...$values_from_vocab
127 ): ControlledRepository {
128 return new class ($slot_with_vocab, $only_active, $empty_labels, $values_from_vocab) extends NullControlledRepository {
130 protected SlotIdentifier $slot_with_vocab,
131 protected bool $only_active,
132 protected bool $empty_labels,
133 protected array $values_from_vocab
137 public function getLabelsForValues(
138 SlotIdentifier $slot,
142 if ($slot !== $this->slot_with_vocab || $only_active !== $this->only_active) {
145 foreach ($values as $value) {
146 if (!in_array($value, $this->values_from_vocab)) {
149 yield
new class ($value, $this->empty_labels) extends NullLabelledValue {
151 protected string $value,
152 protected bool $empty_label
156 public function value(): string
161 public function label(): string
163 if ($this->empty_label) {
166 return 'controlled label for ' . $this->value;
175 SlotIdentifier $slot_with_vocab,
177 string ...$values_from_vocab
178 ): StandardRepository {
179 return new class ($slot_with_vocab, $only_active, $values_from_vocab) extends NullStandardRepository {
181 protected SlotIdentifier $slot_with_vocab,
182 protected bool $only_active,
183 protected array $values_from_vocab
187 public function getLabelsForValues(
188 PresentationUtilities $presentation_utilities,
189 SlotIdentifier $slot,
193 if ($slot !== $this->slot_with_vocab || $only_active !== $this->only_active) {
196 foreach ($values as $value) {
197 if (!in_array($value, $this->values_from_vocab)) {
200 yield
new class ($value) extends NullLabelledValue {
201 public function __construct(
protected string $value)
205 public function value(): string
210 public function label(): string
212 return 'standard label for ' . $this->value;
222 string $expected_value,
223 string $expected_label
227 $labelled_value->value(),
228 'Value of Labelled value ' . $labelled_value->value() .
' should be ' . $expected_value
232 $labelled_value->
label(),
233 'Label of Labelled value ' . $labelled_value->
label() .
' should be ' . $expected_label
242 \Generator $labelled_values,
245 $as_array = iterator_to_array($labelled_values);
249 'There should be ' . count($expected) .
' labelled values, not ' . count($as_array)
252 foreach ($as_array as $labelled_value) {
253 $this->assertLabelledValueMatches(
255 $expected[$i][
'value'],
256 $expected[$i][
'label']
265 [
'v1',
true,
true,
true,
'copyright label for v1'],
266 [
'v2',
true,
false,
true,
'copyright label for v2'],
267 [
'v3',
true,
true,
false,
'copyright label for v3'],
268 [
'v4',
true,
false,
false,
'copyright label for v4'],
269 [
'v5',
false,
true,
true,
'controlled label for v5'],
270 [
'v6',
false,
false,
true,
'standard label for v6'],
271 [
'v7',
false,
true,
false,
'controlled label for v7'],
272 [
'v8',
false,
false,
false,
'v8']
276 #[\PHPUnit\Framework\Attributes\DataProvider('singleValueProvider')]
279 bool $is_in_copyright,
280 bool $is_in_controlled,
281 bool $is_in_standard,
282 string $expected_label
285 $this->getCopyrightBridge(
286 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
287 ...($is_in_copyright ? [$value] : [])
289 $this->getControlledRepository(
290 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
293 ...($is_in_controlled ? [$value] : [])
295 $this->getStandardRepository(
296 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
298 ...($is_in_standard ? [$value] : [])
303 $this->getPresentationUtilities(),
304 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
309 $this->assertLabelledValuesMatchInOrder(
311 [[
'value' => $value,
'label' => $expected_label]]
315 #[\PHPUnit\Framework\Attributes\DataProvider('singleValueProvider')]
318 bool $is_in_copyright,
319 bool $is_in_controlled,
320 bool $is_in_standard,
321 string $expected_label_without_suffix
324 $this->getCopyrightBridge(
325 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
326 ...($is_in_copyright ? [$value] : [])
328 $this->getControlledRepository(
329 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
332 ...($is_in_controlled ? [$value] : [])
334 $this->getStandardRepository(
335 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
337 ...($is_in_standard ? [$value] : [])
342 $this->getPresentationUtilities(),
343 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
348 $suffix = (!$is_in_standard && !$is_in_controlled && !$is_in_copyright) ?
' translated suffix' :
'';
349 $this->assertLabelledValuesMatchInOrder(
351 [[
'value' => $value,
'label' => $expected_label_without_suffix . $suffix]]
357 $value =
'some value';
359 $this->getCopyrightBridge(SlotIdentifier::EDUCATIONAL_DIFFICULTY),
360 $this->getControlledRepository(
361 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
365 $this->getStandardRepository(
366 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
371 $labels = $presentation->presentableLabels(
372 $this->getPresentationUtilities(),
373 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
378 $this->assertLabelledValuesMatchInOrder(
380 [[
'value' => $value,
'label' => $value]]
387 $this->getCopyrightBridge(
388 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
392 $this->getControlledRepository(
393 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
400 $this->getStandardRepository(
401 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
408 $labels = $presentation->presentableLabels(
409 $this->getPresentationUtilities(),
410 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
419 $this->assertLabelledValuesMatchInOrder(
422 [
'value' =>
'contr 2',
'label' =>
'controlled label for contr 2'],
423 [
'value' =>
'cp 1',
'label' =>
'copyright label for cp 1'],
424 [
'value' =>
'something else',
'label' =>
'something else'],
425 [
'value' =>
'stand 2',
'label' =>
'standard label for stand 2'],
426 [
'value' =>
'contr 3',
'label' =>
'controlled label for contr 3']
434 $this->getCopyrightBridge(
435 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
440 $this->getControlledRepository(
441 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
448 $this->getStandardRepository(
449 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
457 $labels = $presentation->labelsForVocabulary(
458 $this->getPresentationUtilities(),
459 $this->getVocabulary(
461 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
468 $this->assertLabelledValuesMatchInOrder(
471 [
'value' =>
'v1',
'label' =>
'standard label for v1'],
472 [
'value' =>
'v2',
'label' =>
'standard label for v2'],
473 [
'value' =>
'v3',
'label' =>
'standard label for v3']
481 $this->getCopyrightBridge(
482 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
487 $this->getControlledRepository(
488 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
495 $this->getStandardRepository(
496 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
504 $labels = $presentation->labelsForVocabulary(
505 $this->getPresentationUtilities(),
506 $this->getVocabulary(
507 Type::CONTROLLED_STRING,
508 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
515 $this->assertLabelledValuesMatchInOrder(
518 [
'value' =>
'v1',
'label' =>
'controlled label for v1'],
519 [
'value' =>
'v2',
'label' =>
'controlled label for v2'],
520 [
'value' =>
'v3',
'label' =>
'controlled label for v3']
528 $this->getCopyrightBridge(
529 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
534 $this->getControlledRepository(
535 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
542 $this->getStandardRepository(
543 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
551 $labels = $presentation->labelsForVocabulary(
552 $this->getPresentationUtilities(),
553 $this->getVocabulary(
554 Type::CONTROLLED_VOCAB_VALUE,
555 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
562 $this->assertLabelledValuesMatchInOrder(
565 [
'value' =>
'v1',
'label' =>
'controlled label for v1'],
566 [
'value' =>
'v2',
'label' =>
'controlled label for v2'],
567 [
'value' =>
'v3',
'label' =>
'controlled label for v3']
575 $this->getCopyrightBridge(
576 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
581 $this->getControlledRepository(
582 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
589 $this->getStandardRepository(
590 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
598 $labels = $presentation->labelsForVocabulary(
599 $this->getPresentationUtilities(),
600 $this->getVocabulary(
602 SlotIdentifier::EDUCATIONAL_DIFFICULTY,
609 $this->assertLabelledValuesMatchInOrder(
612 [
'value' =>
'v1',
'label' =>
'copyright label for v1'],
613 [
'value' =>
'v2',
'label' =>
'copyright label for v2'],
614 [
'value' =>
'v3',
'label' =>
'copyright label for v3']
__construct()
Constructor setup ILIAS global object @access public.
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
if(!file_exists('../ilias.ini.php'))