ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
18 public function getListingFactory() {
19 return new \ILIAS\UI\Implementation\Component\Listing\Factory();
20 }
21
22
24 $f = $this->getListingFactory();
25
26 $this->assertInstanceOf("ILIAS\\UI\\Component\\Listing\\Factory", $f);
27 $this->assertInstanceOf
28 ( "ILIAS\\UI\\Component\\Listing\\Ordered"
29 , $f->ordered(array("1"))
30 );
31 $this->assertInstanceOf
32 ( "ILIAS\\UI\\Component\\Listing\\Unordered"
33 , $f->unordered(array("1"))
34 );
35 $this->assertInstanceOf
36 ( "ILIAS\\UI\\Component\\Listing\\Descriptive"
37 , $f->descriptive(array("k1"=>"c1"))
38 );
39 }
40
41
42 public function test_ordered_get_items() {
43 $f = $this->getListingFactory();
44 $l = $f->ordered(array("1","2"));
45
46 $items = array("1","2");
47 $this->assertEquals($l->getItems(), $items);
48 }
49
50 public function test_unordered_get_items() {
51 $f = $this->getListingFactory();
52 $l = $f->unordered(array("1","2"));
53
54 $items = array("1","2");
55 $this->assertEquals($l->getItems(), $items);
56 }
57
58 public function test_descriptive_get_items() {
59 $f = $this->getListingFactory();
60 $l = $f->descriptive(array("k1"=>"c1","k2"=>"c2"));
61
62 $items = array("k1"=>"c1","k2"=>"c2");
63 $this->assertEquals($l->getItems(), $items);
64 }
65
66 public function test_ordered_with_items() {
67 $f = $this->getListingFactory();
68 $l = $f->ordered(array())->withItems(array("1","2"));
69
70 $items = array("1","2");
71 $this->assertEquals($l->getItems(), $items);
72 }
73
74 public function test_unordered_with_items() {
75 $f = $this->getListingFactory();
76 $l = $f->unordered(array())->withItems(array("1","2"));
77
78 $items = array("1","2");
79 $this->assertEquals($l->getItems(), $items);
80 }
81
82 public function test_descriptive_with_items() {
83 $f = $this->getListingFactory();
84 $l = $f->descriptive(array())->withItems(array("k1"=>"c1","k2"=>"c2"));
85
86 $items = array("k1"=>"c1","k2"=>"c2");
87 $this->assertEquals($l->getItems(), $items);
88 }
89
90
91 public function test_render_ordered_listing() {
92 $f = $this->getListingFactory();
93 $r = $this->getDefaultRenderer();
94 $l = $f->ordered(array("1","2"));
95
96 $html = $this->normalizeHTML($r->render($l));
97
98 $expected = "<ol>".
99 "\t\t<li>1</li>".
100 "\t\t<li>2</li>\t".
101 "</ol>";
102
103 $this->assertEquals($expected, $html);
104 }
105
107 $f = $this->getListingFactory();
108
109 try{
110 $f->descriptive(array("1"));
111 }catch(InvalidArgumentException $e){
112 $this->assertEquals(get_class($e), "InvalidArgumentException");
113 }
114 }
115
117 $f = $this->getListingFactory();
118
119 try{
120 $f->descriptive(array("1","1"));
121 }catch(InvalidArgumentException $e){
122 $this->assertEquals(get_class($e), "InvalidArgumentException");
123 }
124 }
125
126
128 $f = $this->getListingFactory();
129 $r = $this->getDefaultRenderer();
130 $l = $f->unordered(array("1","2"));
131
132 $html = $this->normalizeHTML($r->render($l));
133
134 $expected = "<ul>".
135 "\t\t<li>1</li>".
136 "\t\t<li>2</li>\t".
137 "</ul>";
138
139 $this->assertEquals($expected, $html);
140 }
141
143 $f = $this->getListingFactory();
144 $r = $this->getDefaultRenderer();
145 $l = $f->descriptive(array("k1"=>"c1","k2"=>"c2"));
146
147 $html = $this->normalizeHTML($r->render($l));
148
149 $expected = "<dl>".
150 "\t\t<dt>k1</dt>".
151 "\t<dd>c1</dd>".
152 "\t\t<dt>k2</dt>".
153 "\t<dd>c2</dd>\t".
154 "</dl>";
155
156 $this->assertEquals($expected, $html);
157 }
158}
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:69
normalizeHTML($html)
Definition: Base.php:110
getDefaultRenderer()
Definition: Base.php:100
Test on button implementation.
Definition: ListingTest.php:13
test_render_ordered_listing()
Definition: ListingTest.php:91
test_descriptive_with_items()
Definition: ListingTest.php:82
test_descriptive_invalid_items3()
test_unordered_get_items()
Definition: ListingTest.php:50
test_descriptive_get_items()
Definition: ListingTest.php:58
test_implements_factory_interface()
Definition: ListingTest.php:23
test_render_unordered_listing()
test_ordered_get_items()
Definition: ListingTest.php:42
test_unordered_with_items()
Definition: ListingTest.php:74
test_ordered_with_items()
Definition: ListingTest.php:66
test_descriptive_invalid_items2()
test_render_descriptive_listing()
$html
Definition: example_001.php:87
$r
Definition: example_031.php:79