ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ComponentEntryDescriptionTest.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 
9 
10 
12 
17  "purpose"=>"",
18  "composition"=>"",
19  "effect"=>"",
20  "rivals"=>array()
21  );
22 
24  "purpose",
25  "wrong"
26  );
28  "purpose"=>"",
29  "wrong"=>""
30  );
32  "purpose"=>"Correct",
33  "composition"=>array("Wrong")
34  );
36  "purpose"=>"Correct",
37  "rivals"=>array(array("wrong"))
38  );
39 
41  "purpose"=>"Purpose Description",
42  "composition"=>"Composition Description",
43  "effect"=>"Effect Description",
44  "rivals"=>array("Element 1" => "Rival 1", "Element 2" => "Rival 2")
45  );
46 
48  "purpose"=>"Purpose Description"
49  );
50 
52  "purpose"=>"Purpose Description",
53  "composition"=>"",
54  "effect"=>"",
55  "rivals"=>array()
56  );
57 
61  protected $parser;
62 
66  protected $proper_entry;
67 
68  protected function setUp()
69  {
70  $this->parser = new Crawler\EntriesYamlParser();
71  $this->proper_entry = new ProperEntryFixture();
72  }
73 
74 
78  public function testEmptyDescription() {
79  $description = new Entry\ComponentEntryDescription();
80  $this->assertEquals($this->empty_description_array,$description->getDescription());
81 
82  $description = new Entry\ComponentEntryDescription(array());
83  $this->assertEquals($this->empty_description_array,$description->getDescription());
84  }
88  public function testInvalidDescription() {
89  try{
92  $this->assertFalse("This should not happen");
93 
95  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
96  }
97  }
101  public function testInvalidCategories1() {
102  try{
103  new Entry\ComponentEntryDescription($this->invalid_categories1_array);
104  $this->assertFalse("This should not happen");
105 
107  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::INVALID_INDEX);
108  }
109  }
113  public function testInvalidCategories2() {
114  try{
115  new Entry\ComponentEntryDescription($this->invalid_categories2_array);
116  $this->assertFalse("This should not happen");
117 
119  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::INVALID_INDEX);
120  }
121 
122  }
126  public function testInvalidCategoryItem() {
127  try{
128  new Entry\ComponentEntryDescription($this->invalid_category_item_array);
129  $this->assertFalse("This should not happen");
130 
132  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::STRING_EXPECTED);
133  }
134 
135  }
139  public function testInvalidCategoryValue() {
140  try{
141  new Entry\ComponentEntryDescription($this->invalid_category_value_array);
142  $this->assertFalse("This should not happen");
143 
145  $this->assertEquals($e->getCode(),Crawler\Exception\CrawlerException::STRING_EXPECTED);
146  }
147 
148  }
152  public function testCorrectDescription1() {
153  $description = new Entry\ComponentEntryDescription($this->correct_description1_array);
154  $this->assertEquals($this->correct_description1_array,$description->getDescription());
155 
156  }
157 
161  public function testCorrectDescription2() {
162  $description = new Entry\ComponentEntryDescription($this->correct_description2_array);
163  $this->assertEquals($this->correct_description2_array_return,$description->getDescription());
164 
165  }
166 
167  public function testParseProperEntryToArray() {
168  $entry = $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php")[0];
169 
170  $entry["description"]['composition'] = "";
171  $entry["description"]['effect'] = "";
172 
173  $description = new Entry\ComponentEntryDescription($entry["description"]);
174 
175  $this->assertEquals($description->getDescription(),$entry["description"]);
176  }
177 }
Create styles array
The data for the language used.