ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
5require_once(__DIR__ . "/../../../../libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../Base.php");
7
8use \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
44
45 public function test_ordered_get_items()
46 {
47 $f = $this->getListingFactory();
48 $l = $f->ordered(array("1","2"));
49
50 $items = array("1","2");
51 $this->assertEquals($l->getItems(), $items);
52 }
53
54 public function test_unordered_get_items()
55 {
56 $f = $this->getListingFactory();
57 $l = $f->unordered(array("1","2"));
58
59 $items = array("1","2");
60 $this->assertEquals($l->getItems(), $items);
61 }
62
64 {
65 $f = $this->getListingFactory();
66 $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
67
68 $items = array("k1" => "c1","k2" => "c2");
69 $this->assertEquals($l->getItems(), $items);
70 }
71
72 public function test_ordered_with_items()
73 {
74 $f = $this->getListingFactory();
75 $l = $f->ordered(array())->withItems(array("1","2"));
76
77 $items = array("1","2");
78 $this->assertEquals($l->getItems(), $items);
79 }
80
81 public function test_unordered_with_items()
82 {
83 $f = $this->getListingFactory();
84 $l = $f->unordered(array())->withItems(array("1","2"));
85
86 $items = array("1","2");
87 $this->assertEquals($l->getItems(), $items);
88 }
89
91 {
92 $f = $this->getListingFactory();
93 $l = $f->descriptive(array())->withItems(array("k1" => "c1","k2" => "c2"));
94
95 $items = array("k1" => "c1","k2" => "c2");
96 $this->assertEquals($l->getItems(), $items);
97 }
98
99
101 {
102 $f = $this->getListingFactory();
103 $r = $this->getDefaultRenderer();
104 $l = $f->ordered(array("1","2"));
105
106 $html = $this->normalizeHTML($r->render($l));
107
108 $expected = "<ol>" .
109 "\t\t<li>1</li>" .
110 "\t\t<li>2</li>\t" .
111 "</ol>";
112
113 $this->assertEquals($expected, $html);
114 }
115
117 {
118 $f = $this->getListingFactory();
119
120 try {
121 $f->descriptive(array("1"));
122 } catch (InvalidArgumentException $e) {
123 $this->assertEquals(get_class($e), "InvalidArgumentException");
124 }
125 }
126
128 {
129 $f = $this->getListingFactory();
130
131 try {
132 $f->descriptive(array("1","1"));
133 } catch (InvalidArgumentException $e) {
134 $this->assertEquals(get_class($e), "InvalidArgumentException");
135 }
136 }
137
138
140 {
141 $f = $this->getListingFactory();
142 $r = $this->getDefaultRenderer();
143 $l = $f->unordered(array("1","2"));
144
145 $html = $this->normalizeHTML($r->render($l));
146
147 $expected = "<ul>" .
148 "\t\t<li>1</li>" .
149 "\t\t<li>2</li>\t" .
150 "</ul>";
151
152 $this->assertEquals($expected, $html);
153 }
154
156 {
157 $f = $this->getListingFactory();
158 $r = $this->getDefaultRenderer();
159 $l = $f->descriptive(array("k1" => "c1","k2" => "c2"));
160
161 $html = $this->normalizeHTML($r->render($l));
162
163 $expected = "<dl>" .
164 "\t\t<dt>k1</dt>" .
165 "\t<dd>c1</dd>" .
166 "\t\t<dt>k2</dt>" .
167 "\t<dd>c2</dd>\t" .
168 "</dl>";
169
170 $this->assertEquals($expected, $html);
171 }
172}
global $l
Definition: afr.php:30
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:192
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:228
normalizeHTML($html)
Definition: Base.php:261
Test on button implementation.
Definition: ListingTest.php:14
test_render_ordered_listing()
test_descriptive_with_items()
Definition: ListingTest.php:90
test_descriptive_invalid_items3()
test_unordered_get_items()
Definition: ListingTest.php:54
test_descriptive_get_items()
Definition: ListingTest.php:63
test_implements_factory_interface()
Definition: ListingTest.php:25
test_render_unordered_listing()
test_ordered_get_items()
Definition: ListingTest.php:45
test_unordered_with_items()
Definition: ListingTest.php:81
test_ordered_with_items()
Definition: ListingTest.php:72
test_descriptive_invalid_items2()
test_render_descriptive_listing()
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79