ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
4require_once("libs/composer/vendor/autoload.php");
5include_once("tests/UI/Crawler/Fixture/Fixture.php");
6
9
11{
12
16 protected $empty_description_array = array(
17 "purpose" => "",
18 "composition" => "",
19 "effect" => "",
20 "rivals" => array()
21 );
22
23 protected $invalid_categories1_array = array(
24 "purpose",
25 "wrong"
26 );
27 protected $invalid_categories2_array = array(
28 "purpose" => "",
29 "wrong" => ""
30 );
32 "purpose" => "Correct",
33 "composition" => array("Wrong")
34 );
36 "purpose" => "Correct",
37 "rivals" => array(array("wrong"))
38 );
39
40 protected $correct_description1_array = array(
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
47 protected $correct_description2_array = array(
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 {
81 $this->assertEquals($this->empty_description_array, $description->getDescription());
82
84 $this->assertEquals($this->empty_description_array, $description->getDescription());
85 }
89 public function testInvalidDescription()
90 {
91 try {
94 $this->assertFalse("This should not happen");
95 } catch (Crawler\Exception\CrawlerException $e) {
96 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
97 }
98 }
102 public function testInvalidCategories1()
103 {
104 try {
105 new Entry\ComponentEntryDescription($this->invalid_categories1_array);
106 $this->assertFalse("This should not happen");
107 } catch (Crawler\Exception\CrawlerException $e) {
108 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
109 }
110 }
114 public function testInvalidCategories2()
115 {
116 try {
117 new Entry\ComponentEntryDescription($this->invalid_categories2_array);
118 $this->assertFalse("This should not happen");
119 } catch (Crawler\Exception\CrawlerException $e) {
120 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
121 }
122 }
126 public function testInvalidCategoryItem()
127 {
128 try {
129 new Entry\ComponentEntryDescription($this->invalid_category_item_array);
130 $this->assertFalse("This should not happen");
131 } catch (Crawler\Exception\CrawlerException $e) {
132 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::STRING_EXPECTED);
133 }
134 }
138 public function testInvalidCategoryValue()
139 {
140 try {
141 new Entry\ComponentEntryDescription($this->invalid_category_value_array);
142 $this->assertFalse("This should not happen");
143 } catch (Crawler\Exception\CrawlerException $e) {
144 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::STRING_EXPECTED);
145 }
146 }
150 public function testCorrectDescription1()
151 {
152 $description = new Entry\ComponentEntryDescription($this->correct_description1_array);
153 $this->assertEquals($this->correct_description1_array, $description->getDescription());
154 }
155
159 public function testCorrectDescription2()
160 {
161 $description = new Entry\ComponentEntryDescription($this->correct_description2_array);
162 $this->assertEquals($this->correct_description2_array_return, $description->getDescription());
163 }
164
166 {
167 $entry = $this->parser->parseArrayFromFile("tests/UI/Crawler/Fixture/ProperEntry.php")[0];
168
169 $entry["description"]['composition'] = "";
170 $entry["description"]['effect'] = "";
171
172 $description = new Entry\ComponentEntryDescription($entry["description"]);
173
174 $this->assertEquals($description->getDescription(), $entry["description"]);
175 }
176}
An exception for terminatinating execution or to throw for unit testing.