ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
StructureElementTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
29 class StructureElementTest extends TestCase
30 {
31  protected function getDefinition(string $name): DefinitionInterface
32  {
33  return new class ($name) extends NullDefinition {
34  public function __construct(protected string $name)
35  {
36  }
37 
38  public function name(): string
39  {
40  return $this->name;
41  }
42  };
43  }
44 
45  protected function getStructureElement(
46  bool $is_root,
47  string $name,
48  StructureElement ...$elements
49  ): StructureElement {
50  return new StructureElement(
51  $is_root,
52  $this->getDefinition($name),
53  ...$elements
54  );
55  }
56 
57  public function testSubAndSuperElements(): void
58  {
59  $struct11 = $this->getStructureElement(false, '1.1');
60  $struct1 = $this->getStructureElement(false, '1', $struct11);
61  $struct2 = $this->getStructureElement(false, '2');
62  $root = $this->getStructureElement(true, 'root', $struct1, $struct2);
63 
64  $subs = $root->getSubElements();
65  $this->assertSame($struct1, $subs->current());
66  $subs->next();
67  $this->assertSame($struct2, $subs->current());
68  $subs->next();
69  $this->assertNull($subs->current());
70 
71  $this->assertSame($root, $struct1->getSuperElement());
72  $this->assertSame($struct11, $struct1->getSubElements()->current());
73  }
74 
75  public function testMDIDAndIsRoot(): void
76  {
77  $root = $this->getStructureElement(true, 'root');
78  $not_root = $this->getStructureElement(false, 'name');
79 
80  $this->assertSame(NoID::ROOT, $root->getMDID());
81  $this->assertSame(NoID::STRUCTURE, $not_root->getMDID());
82 
83  $this->assertTrue($root->isRoot());
84  $this->assertFalse($not_root->isRoot());
85  }
86 
87  public function testSubElementByName(): void
88  {
89  $sub1 = $this->getStructureElement(false, 'sub 1');
90  $sub2 = $this->getStructureElement(false, 'sub 2');
91  $sub3 = $this->getStructureElement(false, 'sub 3');
92  $el = $this->getStructureElement(false, 'name', $sub1, $sub2, $sub3);
93 
94  $this->assertSame($sub2, $el->getSubElement('sub 2'));
95  $this->assertSame($sub3, $el->getSubElement('sub 3'));
96  $this->assertSame($sub1, $el->getSubElement('sub 1'));
97  $this->assertNull($el->getSubElement('something else'));
98  }
99 }
getStructureElement(bool $is_root, string $name, StructureElement ... $elements)
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76