ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ListingTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once(__DIR__ . "/../../../../../../vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
26 
31 {
32  public function getListingFactory(): C\Listing\Factory
33  {
34  return new Factory();
35  }
36 
37  public function testImplementsFactoryInterface(): 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  $this->assertInstanceOf(
60  "ILIAS\\UI\\Component\\Listing\\Entity\\Factory",
61  $f->entity()
62  );
63  $this->assertInstanceOf(
64  "ILIAS\\UI\\Component\\Listing\\Property",
65  $f->property()
66  );
67  }
68 
69  public function testOrderedGetItems(): void
70  {
71  $f = $this->getListingFactory();
72  $l = $f->ordered(array("1","2"));
73 
74  $items = array("1","2");
75  $this->assertEquals($l->getItems(), $items);
76  }
77 
78  public function testUnorderedGetItems(): void
79  {
80  $f = $this->getListingFactory();
81  $l = $f->unordered(array("1","2"));
82 
83  $items = array("1","2");
84  $this->assertEquals($l->getItems(), $items);
85  }
86 
87  public function testDescriptiveGetItems(): void
88  {
89  $f = $this->getListingFactory();
90  $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
91 
92  $items = array("k1" => "c1","k2" => "c2");
93  $this->assertEquals($l->getItems(), $items);
94  }
95 
96  public function testOrderedWithItems(): void
97  {
98  $f = $this->getListingFactory();
99  $l = $f->ordered(array())->withItems(array("1","2"));
100 
101  $items = array("1","2");
102  $this->assertEquals($l->getItems(), $items);
103  }
104 
105  public function testUnorderedWithItems(): void
106  {
107  $f = $this->getListingFactory();
108  $l = $f->unordered(array())->withItems(array("1","2"));
109 
110  $items = array("1","2");
111  $this->assertEquals($l->getItems(), $items);
112  }
113 
114  public function testDescriptiveWithItems(): void
115  {
116  $f = $this->getListingFactory();
117  $l = $f->descriptive(array())->withItems(array("k1" => "c1","k2" => "c2"));
118 
119  $items = array("k1" => "c1","k2" => "c2");
120  $this->assertEquals($l->getItems(), $items);
121  }
122 
123  public function testRenderOrderedListing(): void
124  {
125  $f = $this->getListingFactory();
126  $r = $this->getDefaultRenderer();
127  $l = $f->ordered(array("1","2"));
128 
129  $html = $this->normalizeHTML($r->render($l));
130 
131  $expected = "<ol>" .
132  "\t\t<li>1</li>" .
133  "\t\t<li>2</li>\t" .
134  "</ol>";
135 
136  $this->assertEquals($expected, $html);
137  }
138 
139  public function testDescriptiveInvalidItems2(): void
140  {
141  $f = $this->getListingFactory();
142 
143  try {
144  $f->descriptive(array("1"));
145  } catch (InvalidArgumentException $e) {
146  $this->assertEquals("InvalidArgumentException", get_class($e));
147  }
148  }
149 
150  public function testDescriptiveInvalidItems3(): void
151  {
152  $f = $this->getListingFactory();
153 
154  try {
155  $f->descriptive(array("1","1"));
156  } catch (InvalidArgumentException $e) {
157  $this->assertEquals("InvalidArgumentException", get_class($e));
158  }
159  }
160 
161  public function testRenderUnorderedListing(): void
162  {
163  $f = $this->getListingFactory();
164  $r = $this->getDefaultRenderer();
165  $l = $f->unordered(array("1","2"));
166 
167  $html = $this->normalizeHTML($r->render($l));
168 
169  $expected = "<ul>" .
170  "\t\t<li>1</li>" .
171  "\t\t<li>2</li>\t" .
172  "</ul>";
173 
174  $this->assertEquals($expected, $html);
175  }
176 
177  public function testRenderDescriptiveListing(): void
178  {
179  $f = $this->getListingFactory();
180  $r = $this->getDefaultRenderer();
181  $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
182 
183  $html = $this->normalizeHTML($r->render($l));
184 
185  $expected = "<dl>" .
186  "\t\t<dt>k1</dt>" .
187  "\t<dd>c1</dd>" .
188  "\t\t<dt>k2</dt>" .
189  "\t<dd>c2</dd>\t" .
190  "</dl>";
191 
192  $this->assertEquals($expected, $html);
193  }
194 }
testUnorderedGetItems()
Definition: ListingTest.php:78
testOrderedWithItems()
Definition: ListingTest.php:96
testDescriptiveInvalidItems3()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
testImplementsFactoryInterface()
Definition: ListingTest.php:37
testRenderUnorderedListing()
Test on Listing implementation.
Definition: ListingTest.php:30
testRenderOrderedListing()
testDescriptiveInvalidItems2()
testUnorderedWithItems()
testDescriptiveWithItems()
testDescriptiveGetItems()
Definition: ListingTest.php:87
testOrderedGetItems()
Definition: ListingTest.php:69
testRenderDescriptiveListing()
$r