ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
BridgeTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
26use ILIAS\MetaData\Copyright\RepositoryInterface as CopyrightRepository;
40
41class BridgeTest extends TestCase
42{
43 protected function getVocabFactory(): FactoryInterface
44 {
45 return new class () extends NullFactory {
46 public function copyright(string ...$values): BuilderInterface
47 {
48 return new class ($values) extends NullBuilder {
49 public function __construct(protected array $values)
50 {
51 }
52
53 public function get(): VocabularyInterface
54 {
55 return new class ($this->values) extends NullVocabulary {
56 public function __construct(protected array $values)
57 {
58 }
59
60 public function values(): \Generator
61 {
62 yield from $this->values;
63 }
64 };
65 }
66 };
67 }
68 };
69 }
70
71 protected function getSettings(bool $cp_selection_active = true): SettingsInterface
72 {
73 return new class ($cp_selection_active) extends NullSettings {
74 public function __construct(protected bool $cp_selection_active)
75 {
76 }
77
78 public function isCopyrightSelectionActive(): bool
79 {
80 return $this->cp_selection_active;
81 }
82 };
83 }
84
85 protected function getCopyright(int $id, string $title): EntryInterface
86 {
87 return new class ($id, $title) extends NullEntry {
88 public function __construct(
89 protected int $id,
90 protected string $title
91 ) {
92 }
93
94 public function id(): int
95 {
96 return $this->id;
97 }
98
99 public function title(): string
100 {
101 return $this->title;
102 }
103 };
104 }
105
106 protected function getCopyrightRepository(): CopyrightRepository
107 {
108 $copyrights = [];
109 $copyrights[] = $this->getCopyright(1, 'title cp 1');
110 $copyrights[] = $this->getCopyright(2, 'title cp 2');
111 $copyrights[] = $this->getCopyright(3, 'title cp 3');
112
113 return new class ($copyrights) extends NullRepository {
114 public function __construct(protected array $copyrights)
115 {
116 }
117
118 public function getAllEntries(): \Generator
119 {
120 yield from $this->copyrights;
121 }
122 };
123 }
124
125 protected function getIdentifierHandler(): IdentifierHandler
126 {
127 return new class () extends NullHandler {
128 public function buildIdentifierFromEntryID(int $entry_id): string
129 {
130 return 'id_' . $entry_id;
131 }
132 };
133 }
134
135 public function testVocabularyWrongSlot(): void
136 {
137 $bridge = new Bridge(
138 $this->getVocabFactory(),
139 $this->getSettings(),
140 $this->getCopyrightRepository(),
141 $this->getIdentifierHandler()
142 );
143
144 $vocab = $bridge->vocabulary(SlotIdentifier::CLASSIFICATION_PURPOSE);
145
146 $this->assertNull($vocab);
147 }
148
149 public function testVocabularySelectionDisabled(): void
150 {
151 $bridge = new Bridge(
152 $this->getVocabFactory(),
153 $this->getSettings(false),
154 $this->getCopyrightRepository(),
155 $this->getIdentifierHandler()
156 );
157
158 $vocab = $bridge->vocabulary(SlotIdentifier::RIGHTS_DESCRIPTION);
159
160 $this->assertNull($vocab);
161 }
162
163 public function testVocabulary(): void
164 {
165 $bridge = new Bridge(
166 $this->getVocabFactory(),
167 $this->getSettings(),
168 $this->getCopyrightRepository(),
169 $this->getIdentifierHandler()
170 );
171
172 $vocab = $bridge->vocabulary(SlotIdentifier::RIGHTS_DESCRIPTION);
173
174 $this->assertNotNull($vocab);
175 $this->assertSame(
176 ['id_1', 'id_2', 'id_3'],
177 iterator_to_array($vocab->values())
178 );
179 }
180
181 public function testLabelsForValuesWrongSlot(): void
182 {
183 $bridge = new Bridge(
184 $this->getVocabFactory(),
185 $this->getSettings(),
186 $this->getCopyrightRepository(),
187 $this->getIdentifierHandler()
188 );
189
190 $labelled_values = $bridge->labelsForValues(
191 SlotIdentifier::CLASSIFICATION_PURPOSE,
192 'id_1',
193 'id_3',
194 'something'
195 );
196
197 $this->assertNull($labelled_values->current());
198 }
199
201 {
202 $bridge = new Bridge(
203 $this->getVocabFactory(),
204 $this->getSettings(false),
205 $this->getCopyrightRepository(),
206 $this->getIdentifierHandler()
207 );
208
209 $labelled_values = $bridge->labelsForValues(
210 SlotIdentifier::RIGHTS_DESCRIPTION,
211 'id_1',
212 'id_3',
213 'something'
214 );
215
216 $this->assertNull($labelled_values->current());
217 }
218
219 public function testLabelsForValues(): void
220 {
221 $bridge = new Bridge(
222 $this->getVocabFactory(),
223 $this->getSettings(),
224 $this->getCopyrightRepository(),
225 $this->getIdentifierHandler()
226 );
227
228 $labelled_values = $bridge->labelsForValues(
229 SlotIdentifier::RIGHTS_DESCRIPTION,
230 'id_1',
231 'id_3',
232 'something'
233 );
234
235 $label_1 = $labelled_values->current();
236 $this->assertSame('id_1', $label_1->value());
237 $this->assertSame('title cp 1', $label_1->label());
238 $labelled_values->next();
239 $label_3 = $labelled_values->current();
240 $this->assertSame('id_3', $label_3->value());
241 $this->assertSame('title cp 3', $label_3->label());
242 $labelled_values->next();
243 $this->assertNull($labelled_values->current());
244 }
245}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$vocab
getSettings(bool $cp_selection_active=true)
Definition: BridgeTest.php:71
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76