ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ListingTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
26
31{
33 {
34 return new Listing\Factory(
35 new Listing\Workflow\Factory(),
36 new Listing\CharacteristicValue\Factory(),
37 new Listing\Entity\Factory(),
38 );
39 }
40
41 public function testImplementsFactoryInterface(): void
42 {
43 $f = $this->getListingFactory();
44
45 $this->assertInstanceOf("ILIAS\\UI\\Component\\Listing\\Factory", $f);
46 $this->assertInstanceOf(
47 "ILIAS\\UI\\Component\\Listing\\Ordered",
48 $f->ordered(array("1"))
49 );
50 $this->assertInstanceOf(
51 "ILIAS\\UI\\Component\\Listing\\Unordered",
52 $f->unordered(array("1"))
53 );
54 $this->assertInstanceOf(
55 "ILIAS\\UI\\Component\\Listing\\Descriptive",
56 $f->descriptive(array("k1" => "c1"))
57 );
58
59 $this->assertInstanceOf(
60 "ILIAS\\UI\\Component\\Listing\\CharacteristicValue\\Factory",
61 $f->characteristicValue()
62 );
63 $this->assertInstanceOf(
64 "ILIAS\\UI\\Component\\Listing\\Entity\\Factory",
65 $f->entity()
66 );
67 $this->assertInstanceOf(
68 "ILIAS\\UI\\Component\\Listing\\Property",
69 $f->property()
70 );
71 }
72
73 public function testOrderedGetItems(): void
74 {
75 $f = $this->getListingFactory();
76 $l = $f->ordered(array("1","2"));
77
78 $items = array("1","2");
79 $this->assertEquals($l->getItems(), $items);
80 }
81
82 public function testUnorderedGetItems(): void
83 {
84 $f = $this->getListingFactory();
85 $l = $f->unordered(array("1","2"));
86
87 $items = array("1","2");
88 $this->assertEquals($l->getItems(), $items);
89 }
90
91 public function testDescriptiveGetItems(): void
92 {
93 $f = $this->getListingFactory();
94 $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
95
96 $items = array("k1" => "c1","k2" => "c2");
97 $this->assertEquals($l->getItems(), $items);
98 }
99
100 public function testOrderedWithItems(): void
101 {
102 $f = $this->getListingFactory();
103 $l = $f->ordered(array())->withItems(array("1","2"));
104
105 $items = array("1","2");
106 $this->assertEquals($l->getItems(), $items);
107 }
108
109 public function testUnorderedWithItems(): void
110 {
111 $f = $this->getListingFactory();
112 $l = $f->unordered(array())->withItems(array("1","2"));
113
114 $items = array("1","2");
115 $this->assertEquals($l->getItems(), $items);
116 }
117
118 public function testDescriptiveWithItems(): void
119 {
120 $f = $this->getListingFactory();
121 $l = $f->descriptive(array())->withItems(array("k1" => "c1","k2" => "c2"));
122
123 $items = array("k1" => "c1","k2" => "c2");
124 $this->assertEquals($l->getItems(), $items);
125 }
126
127 public function testRenderOrderedListing(): void
128 {
129 $f = $this->getListingFactory();
130 $r = $this->getDefaultRenderer();
131 $l = $f->ordered(array("1","2"));
132
133 $html = $this->normalizeHTML($r->render($l));
134
135 $expected = "<ol>" .
136 "\t\t<li>1</li>" .
137 "\t\t<li>2</li>\t" .
138 "</ol>";
139
140 $this->assertEquals($expected, $html);
141 }
142
143 public function testDescriptiveInvalidItems2(): void
144 {
145 $f = $this->getListingFactory();
146
147 try {
148 $f->descriptive(array("1"));
149 } catch (InvalidArgumentException $e) {
150 $this->assertEquals("InvalidArgumentException", get_class($e));
151 }
152 }
153
154 public function testDescriptiveInvalidItems3(): void
155 {
156 $f = $this->getListingFactory();
157
158 try {
159 $f->descriptive(array("1","1"));
160 } catch (InvalidArgumentException $e) {
161 $this->assertEquals("InvalidArgumentException", get_class($e));
162 }
163 }
164
165 public function testRenderUnorderedListing(): void
166 {
167 $f = $this->getListingFactory();
168 $r = $this->getDefaultRenderer();
169 $l = $f->unordered(array("1","2"));
170
171 $html = $this->normalizeHTML($r->render($l));
172
173 $expected = "<ul>" .
174 "\t\t<li>1</li>" .
175 "\t\t<li>2</li>\t" .
176 "</ul>";
177
178 $this->assertEquals($expected, $html);
179 }
180
181 public function testRenderDescriptiveListing(): void
182 {
183 $f = $this->getListingFactory();
184 $r = $this->getDefaultRenderer();
185 $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
186
187 $html = $this->normalizeHTML($r->render($l));
188
189 $expected = "<dl>" .
190 "\t\t<dt>k1</dt>" .
191 "\t<dd>c1</dd>" .
192 "\t\t<dt>k2</dt>" .
193 "\t<dd>c2</dd>\t" .
194 "</dl>";
195
196 $this->assertEquals($expected, $html);
197 }
198}
Provides common functionality for UI tests.
Definition: Base.php:337
Test on Listing implementation.
Definition: ListingTest.php:31
testUnorderedGetItems()
Definition: ListingTest.php:82
testDescriptiveInvalidItems2()
testUnorderedWithItems()
testRenderDescriptiveListing()
testRenderUnorderedListing()
testDescriptiveWithItems()
testRenderOrderedListing()
testDescriptiveInvalidItems3()
testOrderedGetItems()
Definition: ListingTest.php:73
testImplementsFactoryInterface()
Definition: ListingTest.php:41
testOrderedWithItems()
testDescriptiveGetItems()
Definition: ListingTest.php:91