ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
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 
4 require_once("libs/composer/vendor/autoload.php");
5 include_once("tests/UI/Crawler/Fixture/Fixture.php");
6 
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  );
31  protected $invalid_category_item_array = array(
32  "usage" => array("Correct"),
33  "composition" => "Wrong"
34  );
35  protected $invalid_category_value_array = array(
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  );
53  protected $correct_rules2_array_return = array(
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() : void
75  {
76  $this->parser = new Crawler\EntriesYamlParser();
77  $this->proper_entry = new ProperEntryFixture();
78  }
79 
80 
84  public function testEmptyRules()
85  {
86  $rule = new Entry\ComponentEntryRules();
87  $this->assertEquals($this->empty_rules_array, $rule->getRules());
88 
89  $rule = new Entry\ComponentEntryRules(array());
90  $this->assertEquals($this->empty_rules_array, $rule->getRules());
91  }
92 
96  public function testHasRules()
97  {
98  $rules = new Entry\ComponentEntryRules($this->empty_rules_array);
99  $this->assertFalse($rules->hasRules());
100  $rules = new Entry\ComponentEntryRules($this->correct_rules1_array);
101  $this->assertTrue($rules->hasRules());
102  }
103 
107  public function testInvalidRules()
108  {
109  try {
110  new Entry\ComponentEntryRules(null);
111  new Entry\ComponentEntryRules("rule1");
112  $this->assertFalse("This should not happen");
114  $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
115  }
116  }
120  public function testInvalidCategories1()
121  {
122  try {
123  new Entry\ComponentEntryRules($this->invalid_categories1_array);
124  $this->assertFalse("This should not happen");
126  $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
127  }
128  }
132  public function testInvalidCategories2()
133  {
134  try {
135  new Entry\ComponentEntryRules($this->invalid_categories2_array);
136  $this->assertFalse("This should not happen");
138  $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
139  }
140  }
144  public function testInvalidCategoryItem()
145  {
146  try {
147  new Entry\ComponentEntryRules($this->invalid_category_item_array);
148  $this->assertFalse("This should not happen");
150  $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
151  }
152  }
156  public function testInvalidCategoryValue()
157  {
158  try {
159  new Entry\ComponentEntryRules($this->invalid_category_value_array);
160  $this->assertFalse("This should not happen");
162  $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::STRING_EXPECTED);
163  }
164  }
168  public function testCorrectRules1()
169  {
170  $rules = new Entry\ComponentEntryRules($this->correct_rules1_array);
171  $this->assertEquals($this->correct_rules1_array, $rules->getRules());
172  }
173 
177  public function testCorrectRules2()
178  {
179  $rules = new Entry\ComponentEntryRules($this->correct_rules2_array);
180  $this->assertEquals($this->correct_rules2_array_return, $rules->getRules());
181  }
182 
183  public function testParseProperEntryToArray()
184  {
185  $entry = $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php")[0];
186 
187  $entry["rules"]['composition'] = array();
188  $entry["rules"]['interaction'] = array();
189  $entry["rules"]['wording'] = array();
190  $entry["rules"]['ordering'] = array();
191  $entry["rules"]['responsiveness'] = array();
192  $entry["rules"]['accessibility'] = array();
193 
194  $rules = new Entry\ComponentEntryRules($entry["rules"]);
195  $this->assertEquals($rules->getRules(), $entry["rules"]);
196  }
197 }