ILIAS  release_8 Revision v8.24
ListingTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
26
31{
32 public function getListingFactory(): C\Listing\Factory
33 {
34 return new Factory();
35 }
36
37 public function test_implements_factory_interface(): void
38 {
39 $f = $this->getListingFactory();
40
41 $this->assertInstanceOf("ILIAS\\UI\\Component\\Listing\\Factory", $f);
42 $this->assertInstanceOf(
43 "ILIAS\\UI\\Component\\Listing\\Ordered",
44 $f->ordered(array("1"))
45 );
46 $this->assertInstanceOf(
47 "ILIAS\\UI\\Component\\Listing\\Unordered",
48 $f->unordered(array("1"))
49 );
50 $this->assertInstanceOf(
51 "ILIAS\\UI\\Component\\Listing\\Descriptive",
52 $f->descriptive(array("k1" => "c1"))
53 );
54
55 $this->assertInstanceOf(
56 "ILIAS\\UI\\Component\\Listing\\CharacteristicValue\\Factory",
57 $f->characteristicValue()
58 );
59 }
60
61 public function test_ordered_get_items(): void
62 {
63 $f = $this->getListingFactory();
64 $l = $f->ordered(array("1","2"));
65
66 $items = array("1","2");
67 $this->assertEquals($l->getItems(), $items);
68 }
69
70 public function test_unordered_get_items(): void
71 {
72 $f = $this->getListingFactory();
73 $l = $f->unordered(array("1","2"));
74
75 $items = array("1","2");
76 $this->assertEquals($l->getItems(), $items);
77 }
78
79 public function test_descriptive_get_items(): void
80 {
81 $f = $this->getListingFactory();
82 $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
83
84 $items = array("k1" => "c1","k2" => "c2");
85 $this->assertEquals($l->getItems(), $items);
86 }
87
88 public function test_ordered_with_items(): void
89 {
90 $f = $this->getListingFactory();
91 $l = $f->ordered(array())->withItems(array("1","2"));
92
93 $items = array("1","2");
94 $this->assertEquals($l->getItems(), $items);
95 }
96
97 public function test_unordered_with_items(): void
98 {
99 $f = $this->getListingFactory();
100 $l = $f->unordered(array())->withItems(array("1","2"));
101
102 $items = array("1","2");
103 $this->assertEquals($l->getItems(), $items);
104 }
105
106 public function test_descriptive_with_items(): void
107 {
108 $f = $this->getListingFactory();
109 $l = $f->descriptive(array())->withItems(array("k1" => "c1","k2" => "c2"));
110
111 $items = array("k1" => "c1","k2" => "c2");
112 $this->assertEquals($l->getItems(), $items);
113 }
114
115 public function test_render_ordered_listing(): void
116 {
117 $f = $this->getListingFactory();
118 $r = $this->getDefaultRenderer();
119 $l = $f->ordered(array("1","2"));
120
121 $html = $this->normalizeHTML($r->render($l));
122
123 $expected = "<ol>" .
124 "\t\t<li>1</li>" .
125 "\t\t<li>2</li>\t" .
126 "</ol>";
127
128 $this->assertEquals($expected, $html);
129 }
130
131 public function test_descriptive_invalid_items2(): void
132 {
133 $f = $this->getListingFactory();
134
135 try {
136 $f->descriptive(array("1"));
137 } catch (InvalidArgumentException $e) {
138 $this->assertEquals("InvalidArgumentException", get_class($e));
139 }
140 }
141
142 public function test_descriptive_invalid_items3(): void
143 {
144 $f = $this->getListingFactory();
145
146 try {
147 $f->descriptive(array("1","1"));
148 } catch (InvalidArgumentException $e) {
149 $this->assertEquals("InvalidArgumentException", get_class($e));
150 }
151 }
152
153 public function test_render_unordered_listing(): void
154 {
155 $f = $this->getListingFactory();
156 $r = $this->getDefaultRenderer();
157 $l = $f->unordered(array("1","2"));
158
159 $html = $this->normalizeHTML($r->render($l));
160
161 $expected = "<ul>" .
162 "\t\t<li>1</li>" .
163 "\t\t<li>2</li>\t" .
164 "</ul>";
165
166 $this->assertEquals($expected, $html);
167 }
168
169 public function test_render_descriptive_listing(): void
170 {
171 $f = $this->getListingFactory();
172 $r = $this->getDefaultRenderer();
173 $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
174
175 $html = $this->normalizeHTML($r->render($l));
176
177 $expected = "<dl>" .
178 "\t\t<dt>k1</dt>" .
179 "\t<dd>c1</dd>" .
180 "\t\t<dt>k2</dt>" .
181 "\t<dd>c2</dd>\t" .
182 "</dl>";
183
184 $this->assertEquals($expected, $html);
185 }
186}
Provides common functionality for UI tests.
Definition: Base.php:299
normalizeHTML(string $html)
Definition: Base.php:422
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Test on button implementation.
Definition: ListingTest.php:31
test_render_ordered_listing()
test_descriptive_with_items()
test_descriptive_invalid_items3()
test_unordered_get_items()
Definition: ListingTest.php:70
test_descriptive_get_items()
Definition: ListingTest.php:79
test_implements_factory_interface()
Definition: ListingTest.php:37
test_render_unordered_listing()
test_ordered_get_items()
Definition: ListingTest.php:61
test_unordered_with_items()
Definition: ListingTest.php:97
test_ordered_with_items()
Definition: ListingTest.php:88
test_descriptive_invalid_items2()
test_render_descriptive_listing()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...