ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ViewControlTest.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;
27 
29 {
30  protected array $actions = [
31  "ILIAS" => "http://www.ilias.de",
32  "Github" => "http://www.github.com"
33  ];
34 
35  protected string $aria_label = "Mode View Controler";
36  protected string $role = "group";
37  protected string $active = "Github";
38 
39  public function getViewControlFactory(): I\Component\ViewControl\Factory
40  {
41  return new I\Component\ViewControl\Factory(new SignalGenerator());
42  }
43 
44  public function testImplementsFactoryInterface(): void
45  {
46  $view_control_f = $this->getViewControlFactory();
47 
48  $back = new I\Component\Button\Standard("", "http://www.ilias.de");
49  $next = new I\Component\Button\Standard("", "http://www.github.com");
50  $button = new I\Component\Button\Standard("Today", "");
51 
52  $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $back);
53  $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $next);
54  $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $button);
55  $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Factory", $view_control_f);
56 
57  $section = $view_control_f->section($back, $button, $next);
58  $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Section", $section);
59  }
60 
62  {
64 
65  $back = $button_f->standard("", "http://www.ilias.de");
66  $next = $button_f->standard("", "http://www.github.com");
67  $button = $button_f->standard("Today", "");
68 
69  $action = $this->getViewControlFactory()->section($back, $button, $next)->getPreviousActions();
70 
71  $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $action);
72  }
73 
74  public function testViewControlSectionGetNextActions(): void
75  {
77 
78  $back = $button_f->standard("", "http://www.ilias.de");
79  $next = $button_f->standard("", "http://www.github.com");
80  $button = $button_f->standard("Today", "");
81 
82  $action = $this->getViewControlFactory()->section($back, $button, $next)->getNextActions();
83 
84  $this->assertInstanceOf("ILIAS\\UI\\Component\\Button\\Button", $action);
85  }
86 
87  public function testRenderViewControlSection(): void
88  {
89  $view_control_f = $this->getViewControlFactory();
91 
92  $r = $this->getDefaultRenderer();
93 
94  $back = $button_f->standard("", "http://www.ilias.de");
95  $next = $button_f->standard("", "http://www.github.com");
96  $button = $button_f->standard("Today", "");
97 
98  $section = $view_control_f->section($back, $button, $next);
99 
100  $html = $r->render($section);
101  $this->assertStringContainsString("glyphicon-chevron-left", $html);
102  $this->assertStringContainsString("glyphicon-chevron-right", $html);
103  $this->assertStringContainsString("il-viewcontrol-section", $html);
104  $this->assertStringContainsString("btn", $html);
105 
106  $expected = $this->getSectionExpectedHTML();
107  $this->assertEquals($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($html));
108 
109  $f = $this->getViewControlFactory();
110  $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Factory", $f);
111  }
112 
113  public function testViewControlWithActive(): void
114  {
115  $f = $this->getViewControlFactory();
116 
117  $this->assertEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive($this->active)->getActive());
118  $this->assertNotEquals($this->active, $f->mode($this->actions, $this->aria_label)->withActive("Dummy text")->getActive());
119  }
120 
121  public function testViewControlGetActions(): void
122  {
123  $f = $this->getViewControlFactory();
124 
125  $this->assertIsArray($f->mode($this->actions, $this->aria_label)->getLabelledActions());
126  }
127 
128  public function testViewControlModeRender(): void
129  {
130  $f = $this->getViewControlFactory();
131  $r = $this->getDefaultRenderer();
132  $mode = $f->mode($this->actions, $this->aria_label);
133 
134  $html = $this->normalizeHTML($r->render($mode));
135 
136  $activate_first_item = false;
137  $active = $mode->getActive();
138  if ($active == "") {
139  $activate_first_item = true;
140  }
141 
142  $expected = "<div class=\"il-viewcontrol-mode l-bar__element\" aria-label=\"" . $this->aria_label . "\" role=\"" . $this->role . "\">";
143  foreach ($this->actions as $label => $action) {
144  if ($activate_first_item) {
145  $expected .= "<button class=\"btn btn-default engaged\" aria-pressed=\"true\" data-action=\"$action\" id=\"id_1\">$label</button>";
146  $activate_first_item = false;
147  } elseif ($active == $label) {
148  $expected .= "<button class=\"btn btn-default engaged\" aria-pressed=\"true\" data-action=\"$action\" id=\"id_1\">$label</button>";
149  } else {
150  $expected .= "<button class=\"btn btn-default\" aria-pressed=\"false\" data-action=\"$action\" id=\"id_2\">$label</button>";
151  }
152  }
153  $expected .= "</div>";
154 
155  $this->assertEquals($this->brutallyTrimHTML($expected), $this->brutallyTrimHTML($html));
156  }
157 
158  public function getUIFactory(): NoUIFactory
159  {
160  return new class () extends NoUIFactory {
161  public function counter(): I\Component\Counter\Factory
162  {
163  return new I\Component\Counter\Factory();
164  }
165  public function button(): I\Component\Button\Factory
166  {
167  return new I\Component\Button\Factory();
168  }
169  };
170  }
171 
172  protected function getSectionExpectedHTML(): string
173  {
174  return <<<EOT
175 <div class="il-viewcontrol-section l-bar__element">
176  <a class="btn btn-ctrl browse previous" href="http://www.ilias.de" aria-label="previous" data-action="http://www.ilias.de" id="id_1"><span class="glyphicon glyphicon-chevron-left"></span></a>
177  <button class="btn btn-default" data-action="">Today</button>
178  <a class="btn btn-ctrl browse next" href="http://www.github.com" aria-label="next" data-action="http://www.github.com" id="id_2"><span class="glyphicon glyphicon-chevron-right"></span></a>
179 </div>
180 EOT;
181  }
182 }
button(string $caption, string $cmd)
testViewControlSectionGetNextActions()
testViewControlSectionGetPreviousActions()
$r