ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
CombinedSlateTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2019 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 
5 require_once("libs/composer/vendor/autoload.php");
6 require_once(__DIR__ . "/../../../Base.php");
7 
8 use ILIAS\UI\Component as C;
11 
16 {
17  public function setUp() : void
18  {
19  $this->sig_gen = new I\SignalGenerator();
20  $this->button_factory = new I\Button\Factory($this->sig_gen);
21  $this->divider_factory = new I\Divider\Factory();
22  $this->icon_factory = new I\Symbol\Icon\Factory();
23  }
24 
25  public function getUIFactory()
26  {
27  $factory = new class extends NoUIFactory {
28  public function button()
29  {
30  return $this->button_factory;
31  }
32  public function glyph()
33  {
34  return new I\Symbol\Glyph\Factory();
35  }
36 
37  public function divider()
38  {
39  return new I\Divider\Factory();
40  }
41 
42  public function mainControls() : C\MainControls\Factory
43  {
44  return new I\MainControls\Factory($this->sig_gen);
45  }
46  };
47  $factory->button_factory = $this->button_factory;
48  $factory->sig_gen = $this->sig_gen;
49  return $factory;
50  }
51 
52  public function brutallyTrimHTML($html)
53  {
54  $html = str_replace(["\n", "\r", "\t"], "", $html);
55  $html = preg_replace('# {2,}#', " ", $html);
56  return trim($html);
57  }
58 
59  public function testRendering()
60  {
61  $name = 'name';
62  $icon = $this->icon_factory->custom('', '');
63  $slate = new Combined($this->sig_gen, $name, $icon);
64 
65  $r = $this->getDefaultRenderer();
66  $html = $r->render($slate);
67 
68  $expected = '<div class="il-maincontrols-slate disengaged" id="id_1"><div class="il-maincontrols-slate-content" data-replace-marker="content"></div></div>';
69  $this->assertEquals(
70  $expected,
71  $this->brutallyTrimHTML($html)
72  );
73  }
74 
75  public function testRenderingWithAriaRole()
76  {
77  $name = 'name';
78  $icon = $this->icon_factory->custom('', '');
79  $slate = new Combined($this->sig_gen, $name, $icon);
80  $slate = $slate->withAriaRole(Combined::MENU);
81 
82  $r = $this->getDefaultRenderer();
83  $html = $r->render($slate);
84 
85  $expected = '<div class="il-maincontrols-slate disengaged" id="id_1" role="menu"><div class="il-maincontrols-slate-content" data-replace-marker="content"></div></div>';
86  $this->assertEquals(
87  $expected,
88  $this->brutallyTrimHTML($html)
89  );
90  }
91 
92  public function testRenderingWithSubDivider()
93  {
94  $name = 'name';
95  $icon = $this->icon_factory->custom('', '');
96  $subdivider = new I\Divider\Horizontal();
97  $subdivider_with_text = new I\Divider\Horizontal();
98  $subdivider_with_text = $subdivider_with_text->withLabel('Title');
99  $slate = new Combined($this->sig_gen, $name, $icon);
100  $slate = $slate
101  ->withAdditionalEntry($subdivider_with_text)
102  ->withAdditionalEntry($subdivider);
103 
104  $r = $this->getDefaultRenderer();
105  $html = $r->render($slate);
106 
107  $expected = <<<EOT
108  <div class="il-maincontrols-slate disengaged" id="id_1">
109  <div class="il-maincontrols-slate-content" data-replace-marker="content">
110  <hr class="il-divider-with-label" />
111  <h4 class="il-divider">Title</h4>
112  <hr /></div></div>
113 EOT;
114  $this->assertEquals(
115  $this->brutallyTrimHTML($expected),
116  $this->brutallyTrimHTML($html)
117  );
118  }
119 
121  {
122  $name = 'name';
123  $icon = $this->icon_factory->custom('', '');
124  $subslate = new Combined($this->sig_gen, $name, $icon);
125  $subbutton = $this->button_factory->bulky($icon, '', '');
126  $slate = new Combined($this->sig_gen, $name, $icon);
127  $slate = $slate
128  ->withAdditionalEntry($subslate)
129  ->withAdditionalEntry($subbutton);
130 
131  $r = $this->getDefaultRenderer();
132  $html = $r->render($slate);
133 
134  $expected = <<<EOT
135  <div class="il-maincontrols-slate disengaged" id="id_3">
136  <div class="il-maincontrols-slate-content" data-replace-marker="content">
137 
138  <button class="btn btn-bulky" id="id_1" >
139  <div class="icon custom small" aria-label="">
140  <img src="" />
141  </div>
142  <span class="bulky-label">name</span>
143  </button>
144  <div class="il-maincontrols-slate disengaged" id="id_2">
145  <div class="il-maincontrols-slate-content" data-replace-marker="content">
146  </div>
147  </div>
148 
149  <button class="btn btn-bulky" data-action="" >
150  <div class="icon custom small" aria-label="">
151  <img src="" />
152  </div>
153  <span class="bulky-label"></span>
154  </button>
155 
156  </div>
157  </div>
158 EOT;
159  $this->assertEquals(
160  $this->brutallyTrimHTML($expected),
161  $this->brutallyTrimHTML($html)
162  );
163  }
164 }
Title class.
Definition: Title.php:36
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
if($format !==null) $name
Definition: metadata.php:230
Provides common functionality for UI tests.
Definition: Base.php:224
Tests for the Slate.
$factory
Definition: metadata.php:58