ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ComponentEntryDescriptionTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once("vendor/composer/vendor/autoload.php");
22include_once("components/ILIAS/UI/tests/Crawler/Fixture/Fixture.php");
23
26use PHPUnit\Framework\TestCase;
27
28class ComponentEntryDescriptionTest extends TestCase
29{
30 protected array $empty_description_array = [
31 "purpose" => "",
32 "composition" => "",
33 "effect" => "",
34 "rivals" => []
35 ];
36
37 protected array $invalid_categories1_array = [
38 "purpose",
39 "wrong"
40 ];
41
42 protected array $invalid_categories2_array = [
43 "purpose" => "",
44 "wrong" => ""
45 ];
46
47 protected array $invalid_category_item_array = [
48 "purpose" => "Correct",
49 "composition" => ["Wrong"]
50 ];
51
53 "purpose" => "Correct",
54 "rivals" => [["wrong"]]
55 ];
56
57 protected array $correct_description1_array = [
58 "purpose" => "Purpose Description",
59 "composition" => "Composition Description",
60 "effect" => "Effect Description",
61 "rivals" => ["Element 1" => "Rival 1", "Element 2" => "Rival 2"]
62 ];
63
64 protected array $correct_description2_array = [
65 "purpose" => "Purpose Description"
66 ];
67
69 "purpose" => "Purpose Description",
70 "composition" => "",
71 "effect" => "",
72 "rivals" => []
73 ];
74
77
78 protected function setUp(): void
79 {
80 $this->parser = new Crawler\EntriesYamlParser();
81 $this->proper_entry = new ProperEntryFixture();
82 }
83
87 public function testEmptyDescription(): void
88 {
89 $description = new Entry\ComponentEntryDescription();
90 $this->assertEquals($this->empty_description_array, $description->getDescription());
91
92 $description = new Entry\ComponentEntryDescription(array());
93 $this->assertEquals($this->empty_description_array, $description->getDescription());
94 }
98 public function testInvalidDescription(): void
99 {
100 $this->expectException(TypeError::class);
102
103 $this->expectException(TypeError::class);
105 }
109 public function testInvalidCategories1(): void
110 {
111 try {
112 new Entry\ComponentEntryDescription($this->invalid_categories1_array);
113 $this->assertFalse("This should not happen");
114 } catch (Crawler\Exception\CrawlerException $e) {
115 $this->assertEquals(Crawler\Exception\CrawlerException::INVALID_INDEX, $e->getCode());
116 }
117 }
121 public function testInvalidCategories2(): void
122 {
123 try {
124 new Entry\ComponentEntryDescription($this->invalid_categories2_array);
125 $this->assertFalse("This should not happen");
126 } catch (Crawler\Exception\CrawlerException $e) {
127 $this->assertEquals(Crawler\Exception\CrawlerException::INVALID_INDEX, $e->getCode());
128 }
129 }
133 public function testInvalidCategoryItem(): void
134 {
135 try {
136 new Entry\ComponentEntryDescription($this->invalid_category_item_array);
137 $this->assertFalse("This should not happen");
138 } catch (Crawler\Exception\CrawlerException $e) {
139 $this->assertEquals(Crawler\Exception\CrawlerException::STRING_EXPECTED, $e->getCode());
140 }
141 }
145 public function testInvalidCategoryValue(): void
146 {
147 try {
148 new Entry\ComponentEntryDescription($this->invalid_category_value_array);
149 $this->assertFalse("This should not happen");
150 } catch (Crawler\Exception\CrawlerException $e) {
151 $this->assertEquals(Crawler\Exception\CrawlerException::STRING_EXPECTED, $e->getCode());
152 }
153 }
157 public function testCorrectDescription1(): void
158 {
159 $description = new Entry\ComponentEntryDescription($this->correct_description1_array);
160 $this->assertEquals($this->correct_description1_array, $description->getDescription());
161 }
162
166 public function testCorrectDescription2(): void
167 {
168 $description = new Entry\ComponentEntryDescription($this->correct_description2_array);
169 $this->assertEquals($this->correct_description2_array_return, $description->getDescription());
170 }
171
172 public function testParseProperEntryToArray(): void
173 {
174 $entry = $this->parser->parseArrayFromFile("components/ILIAS/UI/tests/Crawler/Fixture/ProperEntry.php")[0];
175
176 $entry["description"]['composition'] = "";
177 $entry["description"]['effect'] = "";
178
179 $description = new Entry\ComponentEntryDescription($entry["description"]);
180
181 $this->assertEquals($description->getDescription(), $entry["description"]);
182 }
183}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Fixture.php:20