ILIAS  release_8 Revision v8.24
SortationTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21require_once("libs/composer/vendor/autoload.php");
22require_once(__DIR__ . "/../../Base.php");
23
27
32{
33 protected array $options = [
34 'internal_rating' => 'Best',
35 'date_desc' => 'Most Recent',
36 'date_asc' => 'Oldest',
37 ];
38
39 private function getFactory(): I\Component\ViewControl\Factory
40 {
41 return new I\Component\ViewControl\Factory(
42 new SignalGenerator()
43 );
44 }
45
46 public function testConstruction(): void
47 {
48 $f = $this->getFactory();
49 $sortation = $f->sortation($this->options);
50 $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Sortation", $sortation);
51 $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $sortation->getSelectSignal());
52 }
53
54 public function testAttributes(): void
55 {
56 $f = $this->getFactory();
57 $s = $f->sortation($this->options);
58
59 $this->assertEquals($this->options, $s->getOptions());
60
61 $this->assertEquals('label', $s->withLabel('label')->getLabel());
62
63 $s = $s->withTargetURL('#', 'param');
64 $this->assertEquals('#', $s->getTargetURL());
65 $this->assertEquals('param', $s->getParameterName());
66
67 $this->assertEquals(array(), $s->getTriggeredSignals());
68 $generator = new SignalGenerator();
69 $signal = $generator->create();
70 $this->assertEquals($signal, $s->withOnSort($signal)->getTriggeredSignals()[0]->getSignal());
71 }
72
73 public function testRendering(): void
74 {
75 $f = $this->getFactory();
76 $r = $this->getDefaultRenderer();
77 $s = $f->sortation($this->options);
78
79 $html = $this->brutallyTrimHTML($r->render($s));
80 $this->assertEquals($this->getSortationExpectedHTML(true), $html);
81 }
82
83 public function testRenderingWithJsBinding(): void
84 {
85 $f = $this->getFactory();
86 $r = $this->getDefaultRenderer();
87 $s = $f->sortation($this->options)->withAdditionalOnLoadCode(function ($id) {
88 return "";
89 });
90
91 $html = $this->brutallyTrimHTML($r->render($s));
92 $this->assertEquals($this->getSortationExpectedHTML(true), $html);
93 }
94
95 protected function getSortationExpectedHTML(bool $with_id = false): string
96 {
97 $id = "";
98 $button1_id = "id_1";
99 $button2_id = "id_2";
100 $button3_id = "id_3";
101 $dropdown_id = "id_4";
102
103 if ($with_id) {
104 $id = "id=\"id_1\"";
105 $button1_id = "id_2";
106 $button2_id = "id_3";
107 $button3_id = "id_4";
108 $dropdown_id = "id_5";
109 }
110
111 $dropdown_menu_id = $dropdown_id."_menu";
112
113 $expected = <<<EOT
114<div class="il-viewcontrol-sortation" $id><div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" id="$dropdown_id" aria-label="actions" aria-haspopup="true" aria-expanded="false" aria-controls="$dropdown_menu_id" > <span class="caret"></span></button><ul id="$dropdown_menu_id" class="dropdown-menu">
115 <li><button class="btn btn-link" data-action="?sortation=internal_rating" id="$button1_id">Best</button></li>
116 <li><button class="btn btn-link" data-action="?sortation=date_desc" id="$button2_id">Most Recent</button></li>
117 <li><button class="btn btn-link" data-action="?sortation=date_asc" id="$button3_id">Oldest</button></li></ul></div>
118</div>
119EOT;
120 return $this->brutallyTrimHTML($expected);
121 }
122
123 public function getUIFactory(): NoUIFactory
124 {
125 return new class () extends NoUIFactory {
126 public function button(): C\Button\Factory
127 {
128 return new I\Component\Button\Factory();
129 }
130 public function dropdown(): C\Dropdown\Factory
131 {
132 return new I\Component\Dropdown\Factory();
133 }
134 };
135 }
136}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Provides common functionality for UI tests.
Definition: Base.php:299
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
Test on icon implementation.
getSortationExpectedHTML(bool $with_id=false)
testRenderingWithJsBinding()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...