ILIAS  release_7 Revision v7.30-3-g800a261c036
ComponentEntriesTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
3
4require_once("libs/composer/vendor/autoload.php");
5
8
9use PHPUnit\Framework\TestCase;
10
11class ComponentEntriesTest extends TestCase
12{
16 protected $entry;
17
21 protected $entry_data;
22
23 protected function setUp() : void
24 {
25 $this->entries_data = include "tests/UI/Crawler/Fixture/EntriesFixture.php";
26 $this->entries = new Entries();
27 $this->entry_data = include "tests/UI/Crawler/Fixture/EntryFixture.php";
28 $this->entry = new Entry($this->entry_data);
29 $this->entries->addEntriesFromArray($this->entries_data);
30 }
31
32
33 public function testConstruct()
34 {
35 $this->assertInstanceOf(Entries::class, $this->entries);
36 }
37
38 public function testCreateFromArray()
39 {
40 $entries = new Entries();
41 $this->assertEquals(Entries::createFromArray([]), $entries);
42 $this->assertEquals(Entries::createFromArray($this->entries_data), $this->entries);
43 }
44
45 public function testAddEntry()
46 {
47 $entry = new Entry($this->entry_data);
48 $entries = new Entries();
49
50 $this->assertEquals(Entries::createFromArray([]), $entries);
51 $entries->addEntry($entry);
52 $this->assertEquals(Entries::createFromArray([$this->entry_data]), $entries);
53 }
54
55 public function testAddEntries()
56 {
57 $entries = new Entries();
58
59 $this->assertEquals(Entries::createFromArray([]), $entries);
60 $entries->addEntries($this->entries);
61 $this->assertEquals($this->entries, $entries);
62 }
63
64 public function testAddFromArray()
65 {
66 $entries_emtpy = new Entries();
67 $entries = new Entries();
68 $this->assertEquals($entries_emtpy, $entries);
69 $entries->addEntriesFromArray([]);
70 $this->assertEquals($entries_emtpy, $entries);
71 $entries->addEntriesFromArray($this->entries_data);
72 $this->assertEquals($entries, $this->entries);
73 }
74
75 public function testGetRootEntryId()
76 {
77 $entries = new Entries();
78 $this->assertEquals("root", $entries->getRootEntryId());
79 $entries->setRootEntryId("root2");
80 $this->assertEquals("root2", $entries->getRootEntryId());
81 $this->assertEquals("Entry1", $this->entries->getRootEntryId());
82 }
83
84 public function testGetRootEntry()
85 {
86 $entries = new Entries();
87 try {
88 $entries->getRootEntry();
89 $this->assertFalse("this should not happen");
90 } catch (\ILIAS\UI\Implementation\Crawler\Exception\CrawlerException $e) {
91 $this->assertTrue(true);
92 }
93 $this->assertEquals(new Entry($this->entries_data["Entry1"]), $this->entries->getRootEntry());
94 }
95
96 public function testGetEntryById()
97 {
98 $entries = new Entries();
99 try {
100 $entries->getEntryById("invalid");
101 $this->assertFalse("this should not happen");
102 } catch (\ILIAS\UI\Implementation\Crawler\Exception\CrawlerException $e) {
103 $this->assertTrue(true);
104 }
105 $this->assertEquals(new Entry($this->entries_data["Entry2"]), $this->entries->getEntryById("Entry2"));
106 }
107
108 public function testGetParentsOfEntry()
109 {
110 $this->assertEquals([], $this->entries->getParentsOfEntry("Entry1"));
111 $this->assertEquals(["Entry1"], $this->entries->getParentsOfEntry("Entry2"));
112 }
113
115 {
116 $this->assertEquals([], $this->entries->getParentsOfEntryTitles("Entry1"));
117 $this->assertEquals(['Entry1' => 'Entry1Title'], $this->entries->getParentsOfEntryTitles("Entry2"));
118 }
119
121 {
122 $this->assertEquals(['Entry2'], $this->entries->getDescendantsOfEntry("Entry1"));
123 $this->assertEquals([], $this->entries->getDescendantsOfEntry("Entry2"));
124 }
125
127 {
128 $this->assertEquals(['Entry2' => 'Entry2Title'], $this->entries->getDescendantsOfEntryTitles("Entry1"));
129 $this->assertEquals([], $this->entries->getDescendantsOfEntryTitles("Entry2"));
130 }
131
132 public function testJsonSerialize()
133 {
134 $entries = new Entries();
135
136 $this->assertEquals([], $entries->jsonSerialize());
137 $this->assertEquals($this->entries_data, $this->entries->jsonSerialize());
138 }
139}
An exception for terminatinating execution or to throw for unit testing.
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.
Class ChatMainBarProvider \MainMenu\Provider.
Class Factory.