ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ListingTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2016 Timon Amstutz <timon.amstutz@ilub.unibe.ch> Extended GPL, see docs/LICENSE */
4 
5 require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../Base.php");
7 
8 use \ILIAS\UI\Component as C;
9 
14 {
15 
19  public function getListingFactory()
20  {
21  return new \ILIAS\UI\Implementation\Component\Listing\Factory();
22  }
23 
24 
26  {
27  $f = $this->getListingFactory();
28 
29  $this->assertInstanceOf("ILIAS\\UI\\Component\\Listing\\Factory", $f);
30  $this->assertInstanceOf(
31  "ILIAS\\UI\\Component\\Listing\\Ordered",
32  $f->ordered(array("1"))
33  );
34  $this->assertInstanceOf(
35  "ILIAS\\UI\\Component\\Listing\\Unordered",
36  $f->unordered(array("1"))
37  );
38  $this->assertInstanceOf(
39  "ILIAS\\UI\\Component\\Listing\\Descriptive",
40  $f->descriptive(array("k1" => "c1"))
41  );
42 
43  $this->assertInstanceOf(
44  "ILIAS\\UI\\Component\\Listing\\CharacteristicValue\\Factory",
45  $f->characteristicValue()
46  );
47  }
48 
49 
50  public function test_ordered_get_items()
51  {
52  $f = $this->getListingFactory();
53  $l = $f->ordered(array("1","2"));
54 
55  $items = array("1","2");
56  $this->assertEquals($l->getItems(), $items);
57  }
58 
59  public function test_unordered_get_items()
60  {
61  $f = $this->getListingFactory();
62  $l = $f->unordered(array("1","2"));
63 
64  $items = array("1","2");
65  $this->assertEquals($l->getItems(), $items);
66  }
67 
68  public function test_descriptive_get_items()
69  {
70  $f = $this->getListingFactory();
71  $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
72 
73  $items = array("k1" => "c1","k2" => "c2");
74  $this->assertEquals($l->getItems(), $items);
75  }
76 
77  public function test_ordered_with_items()
78  {
79  $f = $this->getListingFactory();
80  $l = $f->ordered(array())->withItems(array("1","2"));
81 
82  $items = array("1","2");
83  $this->assertEquals($l->getItems(), $items);
84  }
85 
86  public function test_unordered_with_items()
87  {
88  $f = $this->getListingFactory();
89  $l = $f->unordered(array())->withItems(array("1","2"));
90 
91  $items = array("1","2");
92  $this->assertEquals($l->getItems(), $items);
93  }
94 
95  public function test_descriptive_with_items()
96  {
97  $f = $this->getListingFactory();
98  $l = $f->descriptive(array())->withItems(array("k1" => "c1","k2" => "c2"));
99 
100  $items = array("k1" => "c1","k2" => "c2");
101  $this->assertEquals($l->getItems(), $items);
102  }
103 
104 
105  public function test_render_ordered_listing()
106  {
107  $f = $this->getListingFactory();
108  $r = $this->getDefaultRenderer();
109  $l = $f->ordered(array("1","2"));
110 
111  $html = $this->normalizeHTML($r->render($l));
112 
113  $expected = "<ol>" .
114  "\t\t<li>1</li>" .
115  "\t\t<li>2</li>\t" .
116  "</ol>";
117 
118  $this->assertEquals($expected, $html);
119  }
120 
122  {
123  $f = $this->getListingFactory();
124 
125  try {
126  $f->descriptive(array("1"));
127  } catch (InvalidArgumentException $e) {
128  $this->assertEquals(get_class($e), "InvalidArgumentException");
129  }
130  }
131 
133  {
134  $f = $this->getListingFactory();
135 
136  try {
137  $f->descriptive(array("1","1"));
138  } catch (InvalidArgumentException $e) {
139  $this->assertEquals(get_class($e), "InvalidArgumentException");
140  }
141  }
142 
143 
145  {
146  $f = $this->getListingFactory();
147  $r = $this->getDefaultRenderer();
148  $l = $f->unordered(array("1","2"));
149 
150  $html = $this->normalizeHTML($r->render($l));
151 
152  $expected = "<ul>" .
153  "\t\t<li>1</li>" .
154  "\t\t<li>2</li>\t" .
155  "</ul>";
156 
157  $this->assertEquals($expected, $html);
158  }
159 
161  {
162  $f = $this->getListingFactory();
163  $r = $this->getDefaultRenderer();
164  $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
165 
166  $html = $this->normalizeHTML($r->render($l));
167 
168  $expected = "<dl>" .
169  "\t\t<dt>k1</dt>" .
170  "\t<dd>c1</dd>" .
171  "\t\t<dt>k2</dt>" .
172  "\t<dd>c2</dd>\t" .
173  "</dl>";
174 
175  $this->assertEquals($expected, $html);
176  }
177 }
test_descriptive_invalid_items2()
test_ordered_with_items()
Definition: ListingTest.php:77
test_unordered_get_items()
Definition: ListingTest.php:59
normalizeHTML($html)
Definition: Base.php:363
test_implements_factory_interface()
Definition: ListingTest.php:25
test_descriptive_invalid_items3()
test_descriptive_with_items()
Definition: ListingTest.php:95
Provides common functionality for UI tests.
Definition: Base.php:262
test_render_ordered_listing()
Test on button implementation.
Definition: ListingTest.php:13
test_ordered_get_items()
Definition: ListingTest.php:50
test_unordered_with_items()
Definition: ListingTest.php:86
test_render_descriptive_listing()
test_descriptive_get_items()
Definition: ListingTest.php:68
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
test_render_unordered_listing()