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

Public Member Functions

 testSet ()
 

Protected Member Functions

 getLOMStructureInitiator ()
 

Detailed Description

Definition at line 31 of file LOMStructureInitiatorTest.php.

Member Function Documentation

◆ getLOMStructureInitiator()

ILIAS\MetaData\Structure\LOMStructureInitiatorTest::getLOMStructureInitiator ( )
protected

Definition at line 33 of file LOMStructureInitiatorTest.php.

33 : LOMStructureInitiator
34 {
35 $initial_array = [
36 'name' => 'root',
37 'subs' => [
38 [
39 'name' => 'first',
40 'subs' => []
41 ],
42 [
43 'name' => 'second',
44 'subs' => [
45 [
46 'name' => 'sub second',
47 'subs' => []
48 ]
49 ]
50 ]
51 ]
52 ];
53
54 $reader_factory = new class ($initial_array) extends NullReaderFactory {
55 public function __construct(protected array $initial_array)
56 {
57 }
58
59 public function reader(): ReaderInterface
60 {
61 return new class ($this->initial_array) extends NullReader {
62 public function __construct(protected array $array)
63 {
64 }
65
66 public function definition(): DefinitionInterface
67 {
68 return new class ($this->array['name']) extends NullDefinition {
69 public function __construct(protected string $name)
70 {
71 }
72
73 public function name(): string
74 {
75 return $this->name;
76 }
77 };
78 }
79
80 public function subDefinitions(): \Generator
81 {
82 foreach ($this->array['subs'] as $sub) {
83 yield new self($sub);
84 }
85 }
86 };
87 }
88 };
89
90 /*
91 * The tree structure needs to be built from actual elements
92 * and not only their interfaces (see BaseElement::addSubElement,
93 * so the factory does not have an interface and needs to be used
94 * here as is.
95 */
96 return new LOMStructureInitiator(
97 $reader_factory,
98 new StructureFactory()
99 );
100 }
__construct()
Constructor setup ILIAS global object @access public.
Definition: class.ilias.php:76

References ILIAS\__construct().

Referenced by ILIAS\MetaData\Structure\LOMStructureInitiatorTest\testSet().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ testSet()

ILIAS\MetaData\Structure\LOMStructureInitiatorTest::testSet ( )

Definition at line 102 of file LOMStructureInitiatorTest.php.

102 : void
103 {
104 $root = $this->getLOMStructureInitiator()->set()->getRoot();
105 $this->assertSame(
106 'root',
107 $root->getDefinition()->name()
108 );
109 $subs = $root->getSubElements();
110 $first = $subs->current();
111 $subs->next();
112 $second = $subs->current();
113 $subs->next();
114 $third = $subs->current();
115
116 $this->assertSame(
117 'first',
118 $first->getDefinition()->name()
119 );
120 $this->assertSame(
121 'second',
122 $second->getDefinition()->name()
123 );
124 $this->assertNull($third);
125
126 $this->assertNull($first->getSubElements()->current());
127 $this->assertSame(
128 'sub second',
129 $second->getSubElements()->current()->getDefinition()->name()
130 );
131 }

References ILIAS\MetaData\Structure\LOMStructureInitiatorTest\getLOMStructureInitiator().

+ Here is the call graph for this function:

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