ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ComponentEntryRulesTest.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");
5include_once("tests/UI/Crawler/Fixture/Fixture.php");
6
9
11{
12 protected $empty_rules_array = array(
13 "usage" => array(),
14 "composition" => array(),
15 "interaction" => array(),
16 "wording" => array(),
17 "ordering" => array(),
18 "style" => array(),
19 "responsiveness" => array(),
20 "accessibility" => array()
21 );
22 protected $invalid_categories1_array = array(
23 "usage",
24 "wrong"
25 );
26 protected $invalid_categories2_array = array(
27 "usage" => array(),
28 "wrong" => array()
29 );
31 "usage" => array("Correct"),
32 "composition" => "Wrong"
33 );
35 "usage" => array("Correct"),
36 "composition" => array(array("wrong"))
37 );
38 protected $correct_rules1_array = array(
39 "usage" => array(1 => "Usage Rule 1", 2 => "Usage Rule 2"),
40 "composition" => array(1 => "composition Rule 1", 2 => "composition Rule 2"),
41 "interaction" => array(1 => "interaction Rule 1", 2 => "interaction Rule 2"),
42 "wording" => array(1 => "wording Rule 1", 2 => "wording Rule 2"),
43 "ordering" => array(1 => "ordering Rule 1", 2 => "ordering Rule 2"),
44 "style" => array(1 => "style Rule 1", 2 => "style Rule 2"),
45 "responsiveness" => array(1 => "responsiveness Rule 1", 2 => "responsiveness Rule 2"),
46 "accessibility" => array(1 => "accessibility Rule 1", 2 => "accessibility Rule 2")
47 );
48 protected $correct_rules2_array = array(
49 "usage" => array(1 => "Usage Rule 1", 2 => "Usage Rule 2"),
50 "accessibility" => ""
51 );
53 "usage" => array(1 => "Usage Rule 1", 2 => "Usage Rule 2"),
54 "composition" => array(),
55 "interaction" => array(),
56 "wording" => array(),
57 "ordering" => array(),
58 "style" => array(),
59 "responsiveness" => array(),
60 "accessibility" => array()
61 );
62
66 protected $parser;
67
71 protected $proper_entry;
72
73 protected function setUp()
74 {
75 $this->parser = new Crawler\EntriesYamlParser();
76 $this->proper_entry = new ProperEntryFixture();
77 }
78
79
83 public function testEmptyRules()
84 {
86 $this->assertEquals($this->empty_rules_array, $rule->getRules());
87
88 $rule = new Entry\ComponentEntryRules(array());
89 $this->assertEquals($this->empty_rules_array, $rule->getRules());
90 }
91
95 public function testHasRules()
96 {
97 $rules = new Entry\ComponentEntryRules($this->empty_rules_array);
98 $this->assertFalse($rules->hasRules());
99 $rules = new Entry\ComponentEntryRules($this->correct_rules1_array);
100 $this->assertTrue($rules->hasRules());
101 }
102
106 public function testInvalidRules()
107 {
108 try {
110 new Entry\ComponentEntryRules("rule1");
111 $this->assertFalse("This should not happen");
112 } catch (Crawler\Exception\CrawlerException $e) {
113 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
114 }
115 }
119 public function testInvalidCategories1()
120 {
121 try {
122 new Entry\ComponentEntryRules($this->invalid_categories1_array);
123 $this->assertFalse("This should not happen");
124 } catch (Crawler\Exception\CrawlerException $e) {
125 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
126 }
127 }
131 public function testInvalidCategories2()
132 {
133 try {
134 new Entry\ComponentEntryRules($this->invalid_categories2_array);
135 $this->assertFalse("This should not happen");
136 } catch (Crawler\Exception\CrawlerException $e) {
137 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
138 }
139 }
143 public function testInvalidCategoryItem()
144 {
145 try {
146 new Entry\ComponentEntryRules($this->invalid_category_item_array);
147 $this->assertFalse("This should not happen");
148 } catch (Crawler\Exception\CrawlerException $e) {
149 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
150 }
151 }
155 public function testInvalidCategoryValue()
156 {
157 try {
158 new Entry\ComponentEntryRules($this->invalid_category_value_array);
159 $this->assertFalse("This should not happen");
160 } catch (Crawler\Exception\CrawlerException $e) {
161 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::STRING_EXPECTED);
162 }
163 }
167 public function testCorrectRules1()
168 {
169 $rules = new Entry\ComponentEntryRules($this->correct_rules1_array);
170 $this->assertEquals($this->correct_rules1_array, $rules->getRules());
171 }
172
176 public function testCorrectRules2()
177 {
178 $rules = new Entry\ComponentEntryRules($this->correct_rules2_array);
179 $this->assertEquals($this->correct_rules2_array_return, $rules->getRules());
180 }
181
183 {
184 $entry = $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php")[0];
185
186 $entry["rules"]['composition'] = array();
187 $entry["rules"]['interaction'] = array();
188 $entry["rules"]['wording'] = array();
189 $entry["rules"]['ordering'] = array();
190 $entry["rules"]['responsiveness'] = array();
191 $entry["rules"]['accessibility'] = array();
192
193 $rules = new Entry\ComponentEntryRules($entry["rules"]);
194 $this->assertEquals($rules->getRules(), $entry["rules"]);
195 }
196}
An exception for terminatinating execution or to throw for unit testing.
$rule
Definition: showstats.php:43