ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
10
12
13 protected $empty_rules_array = array(
14 "usage"=>array(),
15 "composition"=>array(),
16 "interaction"=>array(),
17 "wording"=>array(),
18 "ordering"=>array(),
19 "style"=>array(),
20 "responsiveness"=>array(),
21 "accessibility"=>array()
22 );
23 protected $invalid_categories1_array = array(
24 "usage",
25 "wrong"
26 );
27 protected $invalid_categories2_array = array(
28 "usage"=>array(),
29 "wrong"=>array()
30 );
32 "usage"=>array("Correct"),
33 "composition"=>"Wrong"
34 );
36 "usage"=>array("Correct"),
37 "composition"=>array(array("wrong"))
38 );
39 protected $correct_rules1_array = array(
40 "usage"=>array(1 => "Usage Rule 1", 2 => "Usage Rule 2"),
41 "composition"=>array(1 => "composition Rule 1", 2 => "composition Rule 2"),
42 "interaction"=>array(1 => "interaction Rule 1", 2 => "interaction Rule 2"),
43 "wording"=>array(1 => "wording Rule 1", 2 => "wording Rule 2"),
44 "ordering"=>array(1 => "ordering Rule 1", 2 => "ordering Rule 2"),
45 "style"=>array(1 => "style Rule 1", 2 => "style Rule 2"),
46 "responsiveness"=>array(1 => "responsiveness Rule 1", 2 => "responsiveness Rule 2"),
47 "accessibility"=>array(1 => "accessibility Rule 1", 2 => "accessibility Rule 2")
48 );
49 protected $correct_rules2_array = array(
50 "usage"=>array(1 => "Usage Rule 1", 2 => "Usage Rule 2"),
51 "accessibility"=>""
52 );
54 "usage"=>array(1 => "Usage Rule 1", 2 => "Usage Rule 2"),
55 "composition"=>array(),
56 "interaction"=>array(),
57 "wording"=>array(),
58 "ordering"=>array(),
59 "style"=>array(),
60 "responsiveness"=>array(),
61 "accessibility"=>array()
62 );
63
67 protected $parser;
68
72 protected $proper_entry;
73
74 protected function setUp()
75 {
76 $this->parser = new Crawler\EntriesYamlParser();
77 $this->proper_entry = new ProperEntryFixture();
78 }
79
80
84 public function testEmptyRules() {
85 $rule = new Entry\ComponentEntryRules();
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 }
94 public function testInvalidRules() {
95 try{
97 new Entry\ComponentEntryRules("rule1");
98 $this->assertFalse("This should not happen");
99
100 }catch(Crawler\Exception\CrawlerException $e){
101 $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
102 }
103 }
107 public function testInvalidCategories1() {
108 try{
109 new Entry\ComponentEntryRules($this->invalid_categories1_array);
110 $this->assertFalse("This should not happen");
111
112 }catch(Crawler\Exception\CrawlerException $e){
113 $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::INVALID_INDEX);
114 }
115 }
119 public function testInvalidCategories2() {
120 try{
121 new Entry\ComponentEntryRules($this->invalid_categories2_array);
122 $this->assertFalse("This should not happen");
123
124 }catch(Crawler\Exception\CrawlerException $e){
125 $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::INVALID_INDEX);
126 }
127 }
131 public function testInvalidCategoryItem() {
132 try{
133 new Entry\ComponentEntryRules($this->invalid_category_item_array);
134 $this->assertFalse("This should not happen");
135
136 }catch(Crawler\Exception\CrawlerException $e){
137 $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
138 }
139 }
143 public function testInvalidCategoryValue() {
144 try{
145 new Entry\ComponentEntryRules($this->invalid_category_value_array);
146 $this->assertFalse("This should not happen");
147
148 }catch(Crawler\Exception\CrawlerException $e){
149 $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::STRING_EXPECTED);
150 }
151 }
155 public function testCorrectRules1() {
156 $rules = new Entry\ComponentEntryRules($this->correct_rules1_array);
157 $this->assertEquals($this->correct_rules1_array,$rules->getRules());
158
159 }
160
164 public function testCorrectRules2() {
165 $rules = new Entry\ComponentEntryRules($this->correct_rules2_array);
166 $this->assertEquals($this->correct_rules2_array_return,$rules->getRules());
167
168 }
169
170 public function testParseProperEntryToArray() {
171 $entry = $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php")[0];
172
173 $entry["rules"]['composition'] = array();
174 $entry["rules"]['interaction'] = array();
175 $entry["rules"]['wording'] = array();
176 $entry["rules"]['ordering'] = array();
177 $entry["rules"]['responsiveness'] = array();
178 $entry["rules"]['accessibility'] = array();
179
180 $rules = new Entry\ComponentEntryRules($entry["rules"]);
181 $this->assertEquals($rules->getRules(),$entry["rules"]);
182 }
183}
An exception for terminatinating execution or to throw for unit testing.