ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\MetaData\Structure\Dictionaries\DictionaryTest Class Reference
+ Inheritance diagram for ILIAS\MetaData\Structure\Dictionaries\DictionaryTest:
+ Collaboration diagram for ILIAS\MetaData\Structure\Dictionaries\DictionaryTest:

Public Member Functions

 testTagForElement ()
 
 testTagForElementWithIndices ()
 
 testTagForElementAtRoot ()
 

Protected Member Functions

 getTagAssignment (int $path_id, string $tag_name, int ... $indices)
 
 getDictionary ()
 
 getElement (int $id, ElementInterface ... $subs)
 
 getElements ()
 

Detailed Description

Definition at line 43 of file DictionaryTest.php.

Member Function Documentation

◆ getDictionary()

ILIAS\MetaData\Structure\Dictionaries\DictionaryTest::getDictionary ( )
protected

Definition at line 105 of file DictionaryTest.php.

105 : Dictionary
106 {
107 $tag_assignments = [
108 $this->getTagAssignment(0, 'tag 0'),
109 $this->getTagAssignment(0, 'tag 0 index 0', 0),
110 $this->getTagAssignment(0, 'tag 0 index 3', 3),
111 $this->getTagAssignment(1, 'tag 1 index 1', 1),
112 $this->getTagAssignment(1, 'tag 1 index -2', -2),
113 $this->getTagAssignment(1, 'tag 1 index 0 and 1', 0, 1),
114 $this->getTagAssignment(1, 'tag 1 index -3 and 1', -3, 1),
115 $this->getTagAssignment(2, 'tag 2'),
116 $this->getTagAssignment(2, 'tag 2 number 2')
117 ];
118
119 $path_factory = new class () extends NullFactory {
120 public function toElement(
121 BaseElementInterface $to,
122 bool $leads_to_exactly_one = false
123 ): PathInterface {
124 return new class ($to->getMDID()) extends NullPath {
125 public function __construct(protected int $id)
126 {
127 }
128
129 public function toString(): string
130 {
131 return (string) $this->id;
132 }
133 };
134 }
135 };
136
137 $navigator_factory = new class () extends NullNavigatorFactory {
138 public function navigator(
139 PathInterface $path,
140 ElementInterface $start_element
141 ): NavigatorInterface {
142 return new class ($path, $start_element) extends NullNavigator {
143 protected ElementInterface $start_element;
144
145 public function __construct(
146 protected PathInterface $path,
147 ElementInterface $start_element
148 ) {
149 if ($start_element->getMDID() === 0) {
150 $this->start_element = $start_element;
151 } else {
152 $this->start_element = $start_element->getSuperElement();
153 }
154 }
155
156 public function elementsAtFinalStep(): \Generator
157 {
158 if ($this->path->toString() === '0') {
159 yield $this->start_element;
160 return;
161 }
162
163 foreach ($this->start_element->getSubElements() as $sub) {
164 if ((string) $sub->getMDID() === $this->path->toString()) {
165 yield $sub;
166 }
167 }
168 }
169 };
170 }
171 };
172
173 return new class ($path_factory, $navigator_factory, ...$tag_assignments) extends Dictionary {
174 public function __construct(
175 PathFactoryInterface $path_factory,
176 NavigatorFactoryInterface $navigator_factory,
177 TagAssignmentInterface ...$tag_assignments
178 ) {
179 parent::__construct($path_factory, $navigator_factory, ...$tag_assignments);
180 }
181 };
182 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getTagAssignment(int $path_id, string $tag_name, int ... $indices)
__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...
$path
Definition: ltiservices.php:30
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References $id, $path, ILIAS\GlobalScreen\Provider\__construct(), ILIAS\MetaData\Elements\Base\BaseElementInterface\getMDID(), ILIAS\MetaData\Elements\ElementInterface\getSuperElement(), and ILIAS\Export\ImportHandler\File\XML\Manifest\toString.

+ Here is the call graph for this function:

◆ getElement()

ILIAS\MetaData\Structure\Dictionaries\DictionaryTest::getElement ( int  $id,
ElementInterface ...  $subs 
)
protected

Definition at line 184 of file DictionaryTest.php.

187 : ElementInterface {
188 return new class ($id, $subs) extends NullElement {
189 protected ?ElementInterface $super = null;
190 public function __construct(
191 protected int $id,
192 protected array $subs
193 ) {
194 }
195
196 public function getDefinition(): DefinitionInterface
197 {
198 return new class ($this->id) extends NullDefinition {
199 public function __construct(protected int $id)
200 {
201 }
202
203 public function name(): string
204 {
205 return (string) $this->id;
206 }
207 };
208 }
209
210 public function getSubElements(): \Generator
211 {
212 yield from $this->subs;
213 }
214
215 public function getSuperElement(): ?ElementInterface
216 {
217 return $this->super;
218 }
219
220 public function setSuperElement(ElementInterface $super): void
221 {
222 $this->super = $super;
223 }
224
225 public function getMDID(): int|NoID
226 {
227 return $this->id;
228 }
229 };
230 }

◆ getElements()

ILIAS\MetaData\Structure\Dictionaries\DictionaryTest::getElements ( )
protected

Definition at line 232 of file DictionaryTest.php.

232 : array
233 {
234 $el2 = $this->getElement(2);
235 $el10 = $this->getElement(1);
236 $el11 = $this->getElement(1);
237 $el12 = $this->getElement(1);
238 $el3 = $this->getElement(3);
239 $el0 = $this->getElement(0, $el2, $el10, $el11, $el12, $el3);
240
241 $el2->setSuperElement($el0);
242 $el10->setSuperElement($el0);
243 $el11->setSuperElement($el0);
244 $el12->setSuperElement($el0);
245 $el3->setSuperElement($el0);
246
247 return [
248 'el0' => $el0,
249 'el2' => $el2,
250 'el10' => $el10,
251 'el11' => $el11,
252 'el12' => $el12,
253 'el3' => $el3
254 ];
255 }
getElement(int $id, ElementInterface ... $subs)

◆ getTagAssignment()

ILIAS\MetaData\Structure\Dictionaries\DictionaryTest::getTagAssignment ( int  $path_id,
string  $tag_name,
int ...  $indices 
)
protected

Definition at line 45 of file DictionaryTest.php.

49 : TagAssignmentInterface {
50 return new class ($path_id, $tag_name, $indices) extends NullTagAssignment {
51 public function __construct(
52 protected int $path_id,
53 protected string $tag_name,
54 protected array $indices
55 ) {
56 }
57
58 public function tag(): TagInterface
59 {
60 return new class ($this->tag_name, $this->indices) extends NullTag {
61 public function __construct(
62 protected string $name,
63 protected array $indices
64 ) {
65 }
66
67 public function name()
68 {
69 return $this->name;
70 }
71
72 public function indices(): \Generator
73 {
74 yield from $this->indices;
75 }
76
77 public function isRestrictedToIndices(): bool
78 {
79 return !empty($this->indices);
80 }
81 };
82 }
83
84 public function path(): PathInterface
85 {
86 return new class ($this->path_id) extends NullPath {
87 public function __construct(protected int $path_id)
88 {
89 }
90
91 public function toString(): string
92 {
93 return (string) $this->path_id;
94 }
95 };
96 }
97
98 public function matchesPath(PathInterface $path): bool
99 {
100 return (string) $this->path_id === $path->toString();
101 }
102 };
103 }

◆ testTagForElement()

ILIAS\MetaData\Structure\Dictionaries\DictionaryTest::testTagForElement ( )

Definition at line 257 of file DictionaryTest.php.

257 : void
258 {
259 $dict = $this->getDictionary();
260 $tags = $dict->tagsForElement($this->getElements()['el2']);
261
262 $this->assertSame(
263 'tag 2',
264 $tags->current()->name()
265 );
266 $tags->next();
267 $this->assertSame(
268 'tag 2 number 2',
269 $tags->current()->name()
270 );
271 $tags->next();
272 $this->assertNull($tags->current());
273
274 $tags = $dict->tagsForElement($this->getElements()['el3']);
275 $this->assertNull($tags->current());
276 }

◆ testTagForElementAtRoot()

ILIAS\MetaData\Structure\Dictionaries\DictionaryTest::testTagForElementAtRoot ( )

Definition at line 313 of file DictionaryTest.php.

313 : void
314 {
315 $dict = $this->getDictionary();
316 $tags = $dict->tagsForElement($this->getElements()['el0']);
317
318 $this->assertSame(
319 'tag 0',
320 $tags->current()->name()
321 );
322 $tags->next();
323 $this->assertSame(
324 'tag 0 index 0',
325 $tags->current()->name()
326 );
327 $tags->next();
328 $this->assertNull($tags->current());
329 }

◆ testTagForElementWithIndices()

ILIAS\MetaData\Structure\Dictionaries\DictionaryTest::testTagForElementWithIndices ( )

Definition at line 278 of file DictionaryTest.php.

278 : void
279 {
280 $dict = $this->getDictionary();
281 $els = $this->getElements();
282 $tags10 = $dict->tagsForElement($this->getElements()['el10']);
283 $tags11 = $dict->tagsForElement($this->getElements()['el11']);
284 $tags12 = $dict->tagsForElement($this->getElements()['el12']);
285
286 $this->assertSame(
287 'tag 1 index 0 and 1',
288 $tags10->current()->name()
289 );
290 $tags10->next();
291 $this->assertNull($tags10->current());
292
293 $this->assertSame(
294 'tag 1 index 1',
295 $tags11->current()->name()
296 );
297 $tags11->next();
298 $this->assertSame(
299 'tag 1 index 0 and 1',
300 $tags11->current()->name()
301 );
302 $tags11->next();
303 $this->assertSame(
304 'tag 1 index -3 and 1',
305 $tags11->current()->name()
306 );
307 $tags11->next();
308 $this->assertNull($tags11->current());
309
310 $this->assertNull($tags12->current());
311 }

The documentation for this class was generated from the following file: