ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ComponentEntryRulesTest.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 ComponentEntryRulesTest extends TestCase
29{
30 protected array $empty_rules_array = [
31 "usage" => [],
32 "composition" => [],
33 "interaction" => [],
34 "wording" => [],
35 "ordering" => [],
36 "style" => [],
37 "responsiveness" => [],
38 "accessibility" => []
39 ];
40
41 protected array $invalid_categories1_array = [
42 "usage",
43 "wrong"
44 ];
45
46 protected array $invalid_categories2_array = [
47 "usage" => [],
48 "wrong" => []
49 ];
50
51 protected array $invalid_category_item_array = [
52 "usage" => ["Correct"],
53 "composition" => "Wrong"
54 ];
55
57 "usage" => ["Correct"],
58 "composition" => [["wrong"]]
59 ];
60
61 protected array $correct_rules1_array = [
62 "usage" => [1 => "Usage Rule 1", 2 => "Usage Rule 2"],
63 "composition" => [1 => "composition Rule 1", 2 => "composition Rule 2"],
64 "interaction" => [1 => "interaction Rule 1", 2 => "interaction Rule 2"],
65 "wording" => [1 => "wording Rule 1", 2 => "wording Rule 2"],
66 "ordering" => [1 => "ordering Rule 1", 2 => "ordering Rule 2"],
67 "style" => [1 => "style Rule 1", 2 => "style Rule 2"],
68 "responsiveness" => [1 => "responsiveness Rule 1", 2 => "responsiveness Rule 2"],
69 "accessibility" => [1 => "accessibility Rule 1", 2 => "accessibility Rule 2"]
70 ];
71
72 protected array $correct_rules2_array = [
73 "usage" => [1 => "Usage Rule 1", 2 => "Usage Rule 2"],
74 "accessibility" => ""
75 ];
76
77 protected array $correct_rules2_array_return = [
78 "usage" => [1 => "Usage Rule 1", 2 => "Usage Rule 2"],
79 "composition" => [],
80 "interaction" => [],
81 "wording" => [],
82 "ordering" => [],
83 "style" => [],
84 "responsiveness" => [],
85 "accessibility" => []
86 ];
87
90
91 protected function setUp(): void
92 {
93 $this->parser = new Crawler\EntriesYamlParser();
94 $this->proper_entry = new ProperEntryFixture();
95 }
96
97
101 public function testEmptyRules(): void
102 {
103 $rule = new Entry\ComponentEntryRules();
104 $this->assertEquals($this->empty_rules_array, $rule->getRules());
105
106 $rule = new Entry\ComponentEntryRules(array());
107 $this->assertEquals($this->empty_rules_array, $rule->getRules());
108 }
109
113 public function testHasRules(): void
114 {
115 $rules = new Entry\ComponentEntryRules($this->empty_rules_array);
116 $this->assertFalse($rules->hasRules());
117 $rules = new Entry\ComponentEntryRules($this->correct_rules1_array);
118 $this->assertTrue($rules->hasRules());
119 }
120
124 public function testInvalidRules(): void
125 {
126 $this->expectException(TypeError::class);
128
129 $this->expectException(TypeError::class);
130 new Entry\ComponentEntryRules('rule1');
131 }
132
136 public function testInvalidCategories1(): void
137 {
138 try {
139 new Entry\ComponentEntryRules($this->invalid_categories1_array);
140 $this->assertFalse("This should not happen");
141 } catch (Crawler\Exception\CrawlerException $e) {
142 $this->assertEquals(Crawler\Exception\CrawlerException::INVALID_INDEX, $e->getCode());
143 }
144 }
145
149 public function testInvalidCategories2(): void
150 {
151 try {
152 new Entry\ComponentEntryRules($this->invalid_categories2_array);
153 $this->assertFalse("This should not happen");
154 } catch (Crawler\Exception\CrawlerException $e) {
155 $this->assertEquals(Crawler\Exception\CrawlerException::INVALID_INDEX, $e->getCode());
156 }
157 }
158
162 public function testInvalidCategoryItem(): void
163 {
164 try {
165 new Entry\ComponentEntryRules($this->invalid_category_item_array);
166 $this->assertFalse("This should not happen");
167 } catch (Crawler\Exception\CrawlerException $e) {
168 $this->assertEquals(Crawler\Exception\CrawlerException::ARRAY_EXPECTED, $e->getCode());
169 }
170 }
171
175 public function testInvalidCategoryValue(): void
176 {
177 try {
178 new Entry\ComponentEntryRules($this->invalid_category_value_array);
179 $this->assertFalse("This should not happen");
180 } catch (Crawler\Exception\CrawlerException $e) {
181 $this->assertEquals(Crawler\Exception\CrawlerException::STRING_EXPECTED, $e->getCode());
182 }
183 }
184
188 public function testCorrectRules1(): void
189 {
190 $rules = new Entry\ComponentEntryRules($this->correct_rules1_array);
191 $this->assertEquals($this->correct_rules1_array, $rules->getRules());
192 }
193
197 public function testCorrectRules2(): void
198 {
199 $rules = new Entry\ComponentEntryRules($this->correct_rules2_array);
200 $this->assertEquals($this->correct_rules2_array_return, $rules->getRules());
201 }
202
203 public function testParseProperEntryToArray(): void
204 {
205 $entry = $this->parser->parseArrayFromFile("components/ILIAS/UI/tests/Crawler/Fixture/ProperEntry.php")[0];
206
207 $entry["rules"]['composition'] = [];
208 $entry["rules"]['interaction'] = [];
209 $entry["rules"]['wording'] = [];
210 $entry["rules"]['ordering'] = [];
211 $entry["rules"]['responsiveness'] = [];
212 $entry["rules"]['accessibility'] = [];
213
214 $rules = new Entry\ComponentEntryRules($entry["rules"]);
215 $this->assertEquals($rules->getRules(), $entry["rules"]);
216 }
217}
Crawler EntriesYamlParser $parser
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Fixture.php:20