ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
SortationTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 require_once("vendor/composer/vendor/autoload.php");
22 require_once(__DIR__ . "/../../Base.php");
23 
24 use ILIAS\UI\Component as C;
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, 'date_desc');
50  $this->assertInstanceOf("ILIAS\\UI\\Component\\ViewControl\\Sortation", $sortation);
51  $this->assertInstanceOf("ILIAS\\UI\\Component\\Signal", $sortation->getSelectSignal());
52  }
53 
54  public function testFaultyConstruction(): void
55  {
56  $this->expectException(\InvalidArgumentException::class);
57  $f = $this->getFactory();
58  $sortation = $f->sortation($this->options, 'not_in_options');
59  }
60 
61  public function testAttributes(): void
62  {
63  $f = $this->getFactory();
64  $s = $f->sortation($this->options, 'date_desc');
65 
66  $this->assertEquals($this->options, $s->getOptions());
67 
68  $s = $s->withTargetURL('#', 'param');
69  $this->assertEquals('#', $s->getTargetURL());
70  $this->assertEquals('param', $s->getParameterName());
71 
72  $this->assertEquals(array(), $s->getTriggeredSignals());
73  $generator = new SignalGenerator();
74  $signal = $generator->create();
75  $this->assertEquals($signal, $s->withOnSort($signal)->getTriggeredSignals()[0]->getSignal());
76  $this->assertEquals('internal_rating', $s->withSelected('internal_rating')->getSelected());
77  }
78 
79  public function testRendering(): void
80  {
81  $f = $this->getFactory();
82  $r = $this->getDefaultRenderer();
83  $s = $f->sortation($this->options, 'date_desc');
84 
85  $expected = <<<EOT
86 <div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_1">
87  <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="sortation" aria-haspopup="true" aria-expanded="false" aria-controls="id_1_ctrl">
88  <span class="label">vc_sort Most Recent</span>
89  <span class="glyphicon-sort"></span>
90  </button>
91  <ul id="id_1_ctrl" class="dropdown-menu">
92  <li><button class="btn btn-link" data-action="?sortation=internal_rating" id="id_2">Best</button></li>
93  <li class="selected"><button class="btn btn-link" data-action="?sortation=date_desc" id="id_3">Most Recent</button></li>
94  <li><button class="btn btn-link" data-action="?sortation=date_asc" id="id_4">Oldest</button></li>
95  </ul>
96 </div>
97 EOT;
98  $html = $this->brutallyTrimHTML($r->render($s));
99  $this->assertEquals($this->brutallyTrimHTML($expected), $html);
100  }
101 
102  public function testRenderingWithSelected(): void
103  {
104  $f = $this->getFactory();
105  $r = $this->getDefaultRenderer();
106  $s = $f->sortation($this->options, 'internal_rating')
107  ->withSelected('date_desc');
108 
109  $expected = <<<EOT
110 <div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_1">
111  <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="sortation" aria-haspopup="true" aria-expanded="false" aria-controls="id_1_ctrl">
112  <span class="label">vc_sort Most Recent</span>
113  <span class="glyphicon-sort"></span>
114  </button>
115  <ul id="id_1_ctrl" class="dropdown-menu">
116  <li><button class="btn btn-link" data-action="?sortation=internal_rating" id="id_2">Best</button></li>
117  <li class="selected"><button class="btn btn-link" data-action="?sortation=date_desc" id="id_3">Most Recent</button></li>
118  <li><button class="btn btn-link" data-action="?sortation=date_asc" id="id_4">Oldest</button></li>
119  </ul>
120 </div>
121 EOT;
122  $html = $this->brutallyTrimHTML($r->render($s));
123  $this->assertEquals($this->brutallyTrimHTML($expected), $html);
124  }
125 
126  public function testRenderingWithJsBinding(): void
127  {
128  $f = $this->getFactory();
129  $r = $this->getDefaultRenderer();
130  $s = $f->sortation($this->options, array_key_first($this->options))
131  ->withAdditionalOnLoadCode(
132  function ($id) {
133  return "";
134  }
135  );
136 
137  $id = ' id="id_1"';
138  $id_ctrl = "id_1_ctrl";
139  $button1_id = "id_2";
140  $button2_id = "id_3";
141  $button3_id = "id_4";
142  $dropdown_id = "id_5";
143  $dropdown_menu_id = $dropdown_id . "_menu";
144 
145  $expected = <<<EOT
146 <div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element"$id>
147  <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="sortation" aria-haspopup="true" aria-expanded="false" aria-controls="{$id_ctrl}">
148  <span class="label">vc_sort Best</span>
149  <span class="glyphicon-sort"></span>
150  </button>
151  <ul id="{$id_ctrl}" class="dropdown-menu">
152  <li class="selected"><button class="btn btn-link" data-action="?sortation=internal_rating" id="$button1_id">Best</button></li>
153  <li><button class="btn btn-link" data-action="?sortation=date_desc" id="$button2_id">Most Recent</button></li>
154  <li><button class="btn btn-link" data-action="?sortation=date_asc" id="$button3_id">Oldest</button></li>
155  </ul>
156 </div>
157 EOT;
158  $html = $this->brutallyTrimHTML($r->render($s));
159  $this->assertEquals($this->brutallyTrimHTML($expected), $html);
160  }
161 
162  public function getUIFactory(): NoUIFactory
163  {
164  return new class () extends NoUIFactory {
165  public function button(): I\Component\Button\Factory
166  {
167  return new I\Component\Button\Factory();
168  }
169  public function dropdown(): I\Component\Dropdown\Factory
170  {
171  return new I\Component\Dropdown\Factory();
172  }
173  };
174  }
175 }
button(string $caption, string $cmd)
array getFactory()
Test on icon implementation.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
$r