ILIAS  release_7 Revision v7.30-3-g800a261c036
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
5require_once("libs/composer/vendor/autoload.php");
6require_once(__DIR__ . "/../../../Base.php");
7
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
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>
113EOT;
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 <img class="icon custom small" src="" alt=""/>
140 <span class="bulky-label">name</span>
141 </button>
142 <div class="il-maincontrols-slate disengaged" id="id_2">
143 <div class="il-maincontrols-slate-content" data-replace-marker="content">
144 </div>
145 </div>
146
147 <button class="btn btn-bulky" data-action="" >
148 <img class="icon custom small" src="" alt=""/>
149 <span class="bulky-label"></span>
150 </button>
151
152 </div>
153 </div>
154EOT;
155 $this->assertEquals(
156 $this->brutallyTrimHTML($expected),
157 $this->brutallyTrimHTML($html)
158 );
159 }
160}
An exception for terminatinating execution or to throw for unit testing.
Tests for the Slate.
brutallyTrimHTML($html)
A more radical version of normalizeHTML.
Provides common functionality for UI tests.
Definition: Base.php:263
getDefaultRenderer(JavaScriptBinding $js_binding=null, $with_stub_renderings=[])
Definition: Base.php:311
Title class.
Definition: Title.php:37
$factory
Definition: metadata.php:58
if($format !==null) $name
Definition: metadata.php:230