ILIAS  release_7 Revision v7.30-3-g800a261c036
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
9use PHPUnit\Framework\TestCase;
10
11class ComponentEntryDescriptionTest extends TestCase
12{
13
17 protected $empty_description_array = array(
18 "purpose" => "",
19 "composition" => "",
20 "effect" => "",
21 "rivals" => array()
22 );
23
24 protected $invalid_categories1_array = array(
25 "purpose",
26 "wrong"
27 );
28 protected $invalid_categories2_array = array(
29 "purpose" => "",
30 "wrong" => ""
31 );
33 "purpose" => "Correct",
34 "composition" => array("Wrong")
35 );
37 "purpose" => "Correct",
38 "rivals" => array(array("wrong"))
39 );
40
41 protected $correct_description1_array = array(
42 "purpose" => "Purpose Description",
43 "composition" => "Composition Description",
44 "effect" => "Effect Description",
45 "rivals" => array("Element 1" => "Rival 1", "Element 2" => "Rival 2")
46 );
47
48 protected $correct_description2_array = array(
49 "purpose" => "Purpose Description"
50 );
51
53 "purpose" => "Purpose Description",
54 "composition" => "",
55 "effect" => "",
56 "rivals" => array()
57 );
58
62 protected $parser;
63
67 protected $proper_entry;
68
69 protected function setUp() : void
70 {
71 $this->parser = new Crawler\EntriesYamlParser();
72 $this->proper_entry = new ProperEntryFixture();
73 }
74
75
79 public function testEmptyDescription()
80 {
81 $description = new Entry\ComponentEntryDescription();
82 $this->assertEquals($this->empty_description_array, $description->getDescription());
83
84 $description = new Entry\ComponentEntryDescription(array());
85 $this->assertEquals($this->empty_description_array, $description->getDescription());
86 }
90 public function testInvalidDescription()
91 {
92 try {
95 $this->assertFalse("This should not happen");
96 } catch (Crawler\Exception\CrawlerException $e) {
97 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::ARRAY_EXPECTED);
98 }
99 }
103 public function testInvalidCategories1()
104 {
105 try {
106 new Entry\ComponentEntryDescription($this->invalid_categories1_array);
107 $this->assertFalse("This should not happen");
108 } catch (Crawler\Exception\CrawlerException $e) {
109 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
110 }
111 }
115 public function testInvalidCategories2()
116 {
117 try {
118 new Entry\ComponentEntryDescription($this->invalid_categories2_array);
119 $this->assertFalse("This should not happen");
120 } catch (Crawler\Exception\CrawlerException $e) {
121 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::INVALID_INDEX);
122 }
123 }
127 public function testInvalidCategoryItem()
128 {
129 try {
130 new Entry\ComponentEntryDescription($this->invalid_category_item_array);
131 $this->assertFalse("This should not happen");
132 } catch (Crawler\Exception\CrawlerException $e) {
133 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::STRING_EXPECTED);
134 }
135 }
139 public function testInvalidCategoryValue()
140 {
141 try {
142 new Entry\ComponentEntryDescription($this->invalid_category_value_array);
143 $this->assertFalse("This should not happen");
144 } catch (Crawler\Exception\CrawlerException $e) {
145 $this->assertEquals($e->getCode(), Crawler\Exception\CrawlerException::STRING_EXPECTED);
146 }
147 }
151 public function testCorrectDescription1()
152 {
153 $description = new Entry\ComponentEntryDescription($this->correct_description1_array);
154 $this->assertEquals($this->correct_description1_array, $description->getDescription());
155 }
156
160 public function testCorrectDescription2()
161 {
162 $description = new Entry\ComponentEntryDescription($this->correct_description2_array);
163 $this->assertEquals($this->correct_description2_array_return, $description->getDescription());
164 }
165
167 {
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}
An exception for terminatinating execution or to throw for unit testing.