ILIAS  trunk Revision v11.0_alpha-1723-g8e69f309bab
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ItemGroupTest.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 getFactory(): C\Item\Factory
33  {
34  return new I\Component\Item\Factory();
35  }
36 
37  public function testImplementsFactoryInterface(): void
38  {
39  $f = $this->getFactory();
40 
41  $group = $f->group("group", array(
42  $f->standard("title1"),
43  $f->standard("title2")
44  ));
45 
46  $this->assertInstanceOf("ILIAS\\UI\\Component\\Item\\Group", $group);
47  }
48 
49  public function testGetTitle(): void
50  {
51  $f = $this->getFactory();
52  $c = $f->group("group", array(
53  $f->standard("title1"),
54  $f->standard("title2")
55  ));
56 
57  $this->assertEquals("group", $c->getTitle());
58  }
59 
60  public function testGetItems(): void
61  {
62  $f = $this->getFactory();
63 
64  $items = array(
65  $f->standard("title1"),
66  $f->standard("title2")
67  );
68 
69  $c = $f->group("group", $items);
70 
71  $this->assertEquals($c->getItems(), $items);
72  }
73 
74  public function testWithActions(): void
75  {
76  $f = $this->getFactory();
77 
78  $actions = new I\Component\Dropdown\Standard(array(
79  new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
80  new I\Component\Button\Shy("GitHub", "https://www.github.com")
81  ));
82  $items = array(
83  $f->standard("title1"),
84  $f->standard("title2")
85  );
86 
87  $c = $f->group("group", $items)->withActions($actions);
88 
89  $this->assertEquals($c->getActions(), $actions);
90  }
91 
92  public function testRenderBase(): void
93  {
94  $f = $this->getFactory();
95  $r = $this->getDefaultRenderer();
96 
97  $items = array(
98  $f->standard("title1"),
99  $f->standard("title2")
100  );
101 
102  $c = $f->group("group", $items);
103 
104  $html = $r->render($c);
105 
106  $expected = <<<EOT
107 <div class="il-item-group">
108  <h3>group</h3>
109  <div class="il-item-group-items">
110 
111  <ul>
112  <li class="il-std-item-container">
113  <div class="il-item il-std-item ">
114  <h4 class="il-item-title">title1</h4>
115  </div>
116  </li>
117  <li class="il-std-item-container">
118  <div class="il-item il-std-item ">
119  <h4 class="il-item-title">title2</h4>
120  </div>
121  </li>
122  </ul>
123  </div>
124 </div>
125 EOT;
126  $this->assertHTMLEquals(
127  $this->brutallyTrimHTML($expected),
128  $this->brutallyTrimHTML($html)
129  );
130  }
131 
132  public function testRenderWithActions(): void
133  {
134  $f = $this->getFactory();
135  $r = $this->getDefaultRenderer();
136 
137  $actions = new I\Component\Dropdown\Standard(array(
138  new I\Component\Button\Shy("ILIAS", "https://www.ilias.de"),
139  new I\Component\Button\Shy("GitHub", "https://www.github.com")
140  ));
141  $items = array(
142  $f->standard("title1"),
143  $f->standard("title2")
144  );
145 
146  $c = $f->group("group", $items)->withActions($actions);
147 
148  $html = $r->render($c);
149 
150  $expected = <<<EOT
151 <div class="il-item-group">
152  <h3>group</h3>
153  <div class="dropdown" id="id_3">
154  <button class="btn btn-default dropdown-toggle" type="button" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_menu">
155  <span class="caret"></span>
156  </button>
157  <ul id="id_3_menu" class="dropdown-menu">
158  <li>
159  <button class="btn btn-link" data-action="https://www.ilias.de" id="id_1">ILIAS</button>
160  </li>
161  <li>
162  <button class="btn btn-link" data-action="https://www.github.com" id="id_2">GitHub</button>
163  </li>
164  </ul>
165  </div>
166  <div class="il-item-group-items">
167  <ul>
168  <li class="il-std-item-container">
169  <div class="il-item il-std-item ">
170  <h4 class="il-item-title">title1</h4>
171  </div>
172  </li>
173  <li class="il-std-item-container">
174  <div class="il-item il-std-item ">
175  <h4 class="il-item-title">title2</h4>
176  </div>
177  </li>
178  </ul>
179  </div>
180 </div>
181 EOT;
182  $this->assertHTMLEquals(
183  $this->brutallyTrimHTML($expected),
184  $this->brutallyTrimHTML($html)
185  );
186  }
187 }
button(string $caption, string $cmd)
Test items groups.
Interface Observer Contains several chained tasks and infos about them.
$c
Definition: deliver.php:25
testImplementsFactoryInterface()
$r