ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ComponentEntriesTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
21 require_once("libs/composer/vendor/autoload.php");
22 
25 
28 
29 class ComponentEntriesTest extends TestCase
30 {
34  protected $entries_data;
35  protected Entries $entries;
36  protected Entry $entry;
37  protected array $entry_data;
38 
39  protected function setUp(): void
40  {
41  $this->entries_data = include "tests/UI/Crawler/Fixture/EntriesFixture.php";
42  $this->entries = new Entries();
43  $this->entry_data = include "tests/UI/Crawler/Fixture/EntryFixture.php";
44  $this->entry = new Entry($this->entry_data);
45  $this->entries->addEntriesFromArray($this->entries_data);
46  }
47 
48  public function testConstruct(): void
49  {
50  $this->assertInstanceOf(Entries::class, $this->entries);
51  }
52 
53  public function testAddEntry(): void
54  {
55  $entry = new Entry($this->entry_data);
56  $entries = new Entries();
57 
58  $entries->addEntry($entry);
59  $this->assertEquals(1, $entries->count());
60 
61  $entry->setId("2");
62  $entries->addEntry($entry);
63  $this->assertEquals(2, $entries->count());
64  }
65 
66  public function testAddEntries(): void
67  {
68  $entry = new Entry($this->entry_data);
69 
70  $entries = new Entries();
71  $entries->addEntry($entry);
72 
73  $entry->setId("2");
74  $entries->addEntry($entry);
75 
76  $new_entries = new Entries();
77  $new_entries->addEntries($this->entries);
78  $this->assertEquals(2, $new_entries->count());
79  }
80 
81  public function testAddFromArray(): void
82  {
83  $entries_emtpy = new Entries();
84  $entries = new Entries();
85  $this->assertEquals($entries_emtpy, $entries);
86  $entries->addEntriesFromArray([]);
87  $this->assertEquals($entries_emtpy, $entries);
88  $entries->addEntriesFromArray($this->entries_data);
89  $this->assertEquals($entries, $this->entries);
90  }
91 
92  public function testGetRootEntryId(): void
93  {
94  $entries = new Entries();
95  $this->assertEquals("root", $entries->getRootEntryId());
96  $entries->setRootEntryId("root2");
97  $this->assertEquals("root2", $entries->getRootEntryId());
98  $this->assertEquals("Entry1", $this->entries->getRootEntryId());
99  }
100 
101  public function testGetRootEntry(): void
102  {
103  $entries = new Entries();
104  try {
105  $entries->getRootEntry();
106  $this->assertFalse("this should not happen");
107  } catch (CrawlerException $e) {
108  $this->assertTrue(true);
109  }
110  $this->assertEquals(new Entry($this->entries_data["Entry1"]), $this->entries->getRootEntry());
111  }
112 
113  public function testGetEntryById(): void
114  {
115  $entries = new Entries();
116  try {
117  $entries->getEntryById("invalid");
118  $this->assertFalse("this should not happen");
119  } catch (CrawlerException $e) {
120  $this->assertTrue(true);
121  }
122  $this->assertEquals(new Entry($this->entries_data["Entry2"]), $this->entries->getEntryById("Entry2"));
123  }
124 
125  public function testGetParentsOfEntry(): void
126  {
127  $this->assertEquals([], $this->entries->getParentsOfEntry("Entry1"));
128  $this->assertEquals(["Entry1"], $this->entries->getParentsOfEntry("Entry2"));
129  }
130 
131  public function testIsParentOfEntry(): void
132  {
133  $this->assertEquals(false, $this->entries->isParentOfEntry("Entry2", "Entry1"));
134  $this->assertEquals(true, $this->entries->isParentOfEntry("Entry1", "Entry2"));
135  }
136 
137  public function testGetParentsOfEntryTitles(): void
138  {
139  $this->assertEquals([], $this->entries->getParentsOfEntryTitles("Entry1"));
140  $this->assertEquals(['Entry1' => 'Entry1Title'], $this->entries->getParentsOfEntryTitles("Entry2"));
141  }
142 
143  public function testGetDescendantsOfEntries(): void
144  {
145  $this->assertEquals(['Entry2'], $this->entries->getDescendantsOfEntry("Entry1"));
146  $this->assertEquals([], $this->entries->getDescendantsOfEntry("Entry2"));
147  }
148 
149  public function testGetDescendantsOfEntryTitles(): void
150  {
151  $this->assertEquals(['Entry2' => 'Entry2Title'], $this->entries->getDescendantsOfEntryTitles("Entry1"));
152  $this->assertEquals([], $this->entries->getDescendantsOfEntryTitles("Entry2"));
153  }
154 
155  public function testGetChildrenOfEntry(): void
156  {
157  $this->assertEquals([$this->entries->getEntryById("Entry2")], $this->entries->getChildrenOfEntry("Entry1"));
158  $this->assertEquals([], $this->entries->getDescendantsOfEntryTitles("Entry2"));
159  }
160 
161  public function testJsonSerialize(): void
162  {
163  $entries = new Entries();
164 
165  $this->assertEquals([], $entries->jsonSerialize());
166  $this->assertEquals($this->entries_data, $this->entries->jsonSerialize());
167  }
168 }
Container storing a list of UI Component Entries, can act as Iterator, countable and is serializable...
Stores Information of UI Components parsed from YAML, examples and less files.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...