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

Public Member Functions

 testSubAndSuperElements ()
 
 testGetData ()
 
 testIsScaffold ()
 
 testGetMarkerAndIsMarked ()
 
 testMarkerTrail ()
 
 testMarkTwice ()
 
 testMarkWithScaffolds ()
 
 testUnmark ()
 
 testAddScaffolds ()
 
 testAddScaffoldByName ()
 
 testAddScaffoldByNameWithGap ()
 
 testAddScaffoldsWithSubElementsException ()
 
 testAddScaffoldByNameWithSubElementsException ()
 

Protected Member Functions

 getDefinition (string $name)
 
 getMarkerFactory ()
 
 getScaffoldProvider (bool $broken=false)
 
 getElement (int|NoID $id, Element ... $elements)
 
 getElementWithName (int|NoID $id, string $name, Element ... $elements)
 

Detailed Description

Definition at line 38 of file ElementTest.php.

Member Function Documentation

◆ getDefinition()

ILIAS\MetaData\Elements\ElementTest::getDefinition ( string  $name)
protected

Definition at line 40 of file ElementTest.php.

40 : DefinitionInterface
41 {
42 return new class ($name) extends NullDefinition {
43 public function __construct(protected string $name)
44 {
45 }
46
47 public function name(): string
48 {
49 return $this->name;
50 }
51 };
52 }
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76

References ILIAS\__construct().

+ Here is the call graph for this function:

◆ getElement()

ILIAS\MetaData\Elements\ElementTest::getElement ( int|NoID  $id,
Element ...  $elements 
)
protected

Definition at line 165 of file ElementTest.php.

168 : Element {
169 return new Element(
170 $id,
171 $this->getDefinition('name'),
172 new NullData(),
173 ...$elements
174 );
175 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23

◆ getElementWithName()

ILIAS\MetaData\Elements\ElementTest::getElementWithName ( int|NoID  $id,
string  $name,
Element ...  $elements 
)
protected

Definition at line 177 of file ElementTest.php.

181 : Element {
182 return new Element(
183 $id,
184 $this->getDefinition($name),
185 new NullData(),
186 ...$elements
187 );
188 }

◆ getMarkerFactory()

ILIAS\MetaData\Elements\ElementTest::getMarkerFactory ( )
protected

Definition at line 54 of file ElementTest.php.

54 : MarkerFactoryInterface
55 {
56 return new class () extends NullMarkerFactory {
57 public function marker(Action $action, string $data_value = ''): MarkerInterface
58 {
59 return new class ($action) extends NullMarker {
60 protected Action $action;
61
62 public function __construct(Action $action)
63 {
64 $this->action = $action;
65 }
66
67 public function action(): Action
68 {
69 return $this->action;
70 }
71
72 public function dataValue(): string
73 {
74 return '';
75 }
76 };
77 }
78 };
79 }

References ILIAS\__construct().

+ Here is the call graph for this function:

◆ getScaffoldProvider()

ILIAS\MetaData\Elements\ElementTest::getScaffoldProvider ( bool  $broken = false)
protected

Definition at line 81 of file ElementTest.php.

81 : ScaffoldProviderInterface
82 {
83 return new class ($broken) extends NullScaffoldProvider {
84 public function __construct(protected bool $broken)
85 {
86 }
87
88 protected function getScaffold(string $name, ElementInterface ...$elements): ElementInterface
89 {
90 $definition = new class ($name) implements DefinitionInterface {
91 protected string $name;
92
93 public function __construct(string $name)
94 {
95 $this->name = $name;
96 }
97
98 public function name(): string
99 {
100 return $this->name;
101 }
102
103 public function unique(): bool
104 {
105 return false;
106 }
107
108 public function dataType(): Type
109 {
110 return Type::NULL;
111 }
112 };
113
114 $data = new class () extends NullData {
115 public function type(): Type
116 {
117 return Type::STRING;
118 }
119
120 public function value(): string
121 {
122 return 'value';
123 }
124 };
125
126 return new Element(
127 NoID::SCAFFOLD,
128 $definition,
129 $data,
130 ...$elements
131 );
132 }
133
134 public function getScaffoldsForElement(ElementInterface $element): \Generator
135 {
136 if ($this->broken) {
137 $sub = $this->getScaffold('name');
138 $with_sub = $this->getScaffold('with sub', $sub);
139
140 yield '' => $with_sub;
141 return;
142 }
143
144 $first = $this->getScaffold('first');
145 $second = $this->getScaffold('second');
146 $third = $this->getScaffold('third');
147 $fourth = $this->getScaffold('fourth');
148
149 yield $first;
150 yield $second;
151 yield $third;
152 yield $fourth;
153 }
154
155 public function getPossibleSubElementNamesForElementInOrder(ElementInterface $element): \Generator
156 {
157 yield 'first';
158 yield 'second';
159 yield 'third';
160 yield 'fourth';
161 }
162 };
163 }

References $data, ILIAS\__construct(), and ILIAS\Data\Description\NULL.

+ Here is the call graph for this function:

◆ testAddScaffoldByName()

ILIAS\MetaData\Elements\ElementTest::testAddScaffoldByName ( )

Definition at line 343 of file ElementTest.php.

343 : void
344 {
345 $second = $this->getElementWithName(6, 'second');
346 $third = $this->getElementWithName(17, 'third');
347 $el = $this->getElement(13, $second, $third);
348
349 $el->addScaffoldToSubElements($this->getScaffoldProvider(), 'second');
350
351 $subs = $el->getSubElements();
352 $this->assertSame($second, $subs->current());
353 $subs->next();
354 $this->assertTrue($subs->current()->isScaffold());
355 $this->assertSame('second', $subs->current()->getDefinition()->name());
356 $subs->next();
357 $this->assertSame($third, $subs->current());
358 $subs->next();
359 $this->assertNull($subs->current());
360 }
getElementWithName(int|NoID $id, string $name, Element ... $elements)
getElement(int|NoID $id, Element ... $elements)
getScaffoldProvider(bool $broken=false)
Definition: ElementTest.php:81

◆ testAddScaffoldByNameWithGap()

ILIAS\MetaData\Elements\ElementTest::testAddScaffoldByNameWithGap ( )

Definition at line 364 of file ElementTest.php.

364 : void
365 {
366 $second = $this->getElementWithName(6, 'second');
367 $fourth = $this->getElementWithName(17, 'fourth');
368 $el = $this->getElement(13, $second, $fourth);
369
370 $el->addScaffoldToSubElements($this->getScaffoldProvider(), 'second');
371
372 $subs = $el->getSubElements();
373 $this->assertSame($second, $subs->current());
374 $subs->next();
375 $this->assertTrue($subs->current()->isScaffold());
376 $this->assertSame('second', $subs->current()->getDefinition()->name());
377 $subs->next();
378 $this->assertSame($fourth, $subs->current());
379 $subs->next();
380 $this->assertNull($subs->current());
381 }

◆ testAddScaffoldByNameWithSubElementsException()

ILIAS\MetaData\Elements\ElementTest::testAddScaffoldByNameWithSubElementsException ( )

Definition at line 391 of file ElementTest.php.

391 : void
392 {
393 $el = $this->getElement(37);
394
395 $this->expectException(\ilMDElementsException::class);
396 $el->addScaffoldToSubElements($this->getScaffoldProvider(true), 'with sub');
397 }

◆ testAddScaffolds()

ILIAS\MetaData\Elements\ElementTest::testAddScaffolds ( )

Definition at line 315 of file ElementTest.php.

315 : void
316 {
317 $second = $this->getElementWithName(6, 'second');
318 $fourth = $this->getElementWithName(6, 'fourth');
319 $el = $this->getElement(13, $second, $fourth);
320
321 $el->addScaffoldsToSubElements($this->getScaffoldProvider());
322
323 $subs = $el->getSubElements();
324 $this->assertTrue($subs->current()->isScaffold());
325 $this->assertSame('first', $subs->current()->getDefinition()->name());
326 $subs->next();
327 $this->assertSame($second, $subs->current());
328 $subs->next();
329 $this->assertTrue($subs->current()->isScaffold());
330 $this->assertSame('second', $subs->current()->getDefinition()->name());
331 $subs->next();
332 $this->assertTrue($subs->current()->isScaffold());
333 $this->assertSame('third', $subs->current()->getDefinition()->name());
334 $subs->next();
335 $this->assertSame($fourth, $subs->current());
336 $subs->next();
337 $this->assertTrue($subs->current()->isScaffold());
338 $this->assertSame('fourth', $subs->current()->getDefinition()->name());
339 $subs->next();
340 $this->assertNull($subs->current());
341 }

◆ testAddScaffoldsWithSubElementsException()

ILIAS\MetaData\Elements\ElementTest::testAddScaffoldsWithSubElementsException ( )

Definition at line 383 of file ElementTest.php.

383 : void
384 {
385 $el = $this->getElement(37);
386
387 $this->expectException(\ilMDElementsException::class);
388 $el->addScaffoldsToSubElements($this->getScaffoldProvider(true));
389 }

◆ testGetData()

ILIAS\MetaData\Elements\ElementTest::testGetData ( )

Definition at line 208 of file ElementTest.php.

208 : void
209 {
210 $data = new NullData();
211 $el = new Element(
212 7,
213 $this->getDefinition('name'),
214 $data
215 );
216
217 $this->assertSame($data, $el->getData());
218 }

References $data.

◆ testGetMarkerAndIsMarked()

ILIAS\MetaData\Elements\ElementTest::testGetMarkerAndIsMarked ( )

Definition at line 229 of file ElementTest.php.

229 : void
230 {
231 $mark_me = $this->getElement(13);
232 $stay_away = $this->getElement(7);
233 $mark_me->mark($this->getMarkerFactory(), Action::NEUTRAL);
234
235 $this->assertTrue($mark_me->isMarked());
236 $this->assertInstanceOf(MarkerInterface::class, $mark_me->getMarker());
237 $this->assertFalse($stay_away->isMarked());
238 $this->assertNull($stay_away->getMarker());
239 }

◆ testIsScaffold()

ILIAS\MetaData\Elements\ElementTest::testIsScaffold ( )

Definition at line 220 of file ElementTest.php.

220 : void
221 {
222 $scaffold = $this->getElement(NoID::SCAFFOLD);
223 $not_scaffold = $this->getElement(5);
224
225 $this->assertTrue($scaffold->isScaffold());
226 $this->assertFalse($not_scaffold->isScaffold());
227 }

◆ testMarkerTrail()

ILIAS\MetaData\Elements\ElementTest::testMarkerTrail ( )

Definition at line 241 of file ElementTest.php.

241 : void
242 {
243 $el111 = $this->getElement(111);
244 $el11 = $this->getElement(11, $el111);
245 $el12 = $this->getElement(12);
246 $el1 = $this->getElement(1, $el11, $el12);
247 $el2 = $this->getElement(2);
248 $root = $this->getElement(NoID::ROOT, $el1, $el2);
249
250 $el11->mark($this->getMarkerFactory(), Action::CREATE_OR_UPDATE);
251
252 $this->assertTrue($el11->isMarked());
253 $this->assertSame(Action::CREATE_OR_UPDATE, $el11->getMarker()->action());
254 $this->assertTrue($el1->isMarked());
255 $this->assertSame(Action::NEUTRAL, $el1->getMarker()->action());
256 $this->assertTrue($root->isMarked());
257 $this->assertSame(Action::NEUTRAL, $root->getMarker()->action());
258
259 $this->assertFalse($el111->isMarked());
260 $this->assertFalse($el12->isMarked());
261 $this->assertFalse($el2->isMarked());
262 }

◆ testMarkTwice()

ILIAS\MetaData\Elements\ElementTest::testMarkTwice ( )

Definition at line 264 of file ElementTest.php.

264 : void
265 {
266 $marker_factory = $this->getMarkerFactory();
267 $sub = $this->getElement(11);
268 $el = $this->getElement(1, $sub);
269
270 $el->mark($marker_factory, Action::CREATE_OR_UPDATE);
271 $this->assertSame(Action::CREATE_OR_UPDATE, $el->getMarker()->action());
272
273 $sub->mark($marker_factory, Action::DELETE);
274 $this->assertSame(Action::DELETE, $sub->getMarker()->action());
275 $this->assertSame(Action::CREATE_OR_UPDATE, $el->getMarker()->action());
276
277 $el->mark($marker_factory, Action::DELETE);
278 $this->assertSame(Action::DELETE, $el->getMarker()->action());
279 }

References ILIAS\MetaData\Elements\Markers\DELETE.

◆ testMarkWithScaffolds()

ILIAS\MetaData\Elements\ElementTest::testMarkWithScaffolds ( )

Definition at line 281 of file ElementTest.php.

281 : void
282 {
283 $marker_factory = $this->getMarkerFactory();
284 $sub = $this->getElement(NoID::SCAFFOLD);
285 $el = $this->getElement(NoID::SCAFFOLD, $sub);
286
287 $sub->mark($marker_factory, Action::CREATE_OR_UPDATE);
288 $this->assertSame(Action::CREATE_OR_UPDATE, $sub->getMarker()->action());
289 $this->assertSame(Action::CREATE_OR_UPDATE, $el->getMarker()->action());
290
291 $sub = $this->getElement(NoID::SCAFFOLD);
292 $el = $this->getElement(NoID::SCAFFOLD, $sub);
293
294 $sub->mark($marker_factory, Action::DELETE);
295 $this->assertSame(Action::DELETE, $sub->getMarker()->action());
296 $this->assertSame(Action::NEUTRAL, $el->getMarker()->action());
297 }

References ILIAS\MetaData\Elements\Markers\DELETE.

◆ testSubAndSuperElements()

ILIAS\MetaData\Elements\ElementTest::testSubAndSuperElements ( )

Definition at line 190 of file ElementTest.php.

190 : void
191 {
192 $el11 = $this->getElement(11);
193 $el1 = $this->getElement(1, $el11);
194 $el2 = $this->getElement(2);
195 $root = $this->getElement(NoID::ROOT, $el1, $el2);
196
197 $subs = $root->getSubElements();
198 $this->assertSame($el1, $subs->current());
199 $subs->next();
200 $this->assertSame($el2, $subs->current());
201 $subs->next();
202 $this->assertNull($subs->current());
203
204 $this->assertSame($root, $el1->getSuperElement());
205 $this->assertSame($el11, $el1->getSubElements()->current());
206 }

◆ testUnmark()

ILIAS\MetaData\Elements\ElementTest::testUnmark ( )

Definition at line 299 of file ElementTest.php.

299 : void
300 {
301 $el111 = $this->getElement(111);
302 $el11 = $this->getElement(11, $el111);
303 $el1 = $this->getElement(1, $el11);
304 $root = $this->getElement(NoID::ROOT, $el1);
305
306 $el111->mark($this->getMarkerFactory(), Action::CREATE_OR_UPDATE);
307 $el11->unmark();
308
309 $this->assertTrue($root->isMarked());
310 $this->assertTrue($el1->isMarked());
311 $this->assertFalse($el11->isMarked());
312 $this->assertFalse($el111->isMarked());
313 }

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