ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
SortationTest.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 2017 Nils Haagen <nils.haagen@concepts-and-training.de> Extended GPL, see docs/LICENSE */
3
4require_once("libs/composer/vendor/autoload.php");
5require_once(__DIR__ . "/../../Base.php");
6
7use \ILIAS\UI\Component as C;
8use \ILIAS\UI\Implementation as I;
10
15{
16 protected $options = array(
17 'internal_rating' => 'Best',
18 'date_desc' => 'Most Recent',
19 'date_asc' => 'Oldest',
20 );
21
22 private function getFactory()
23 {
24 return new I\Component\ViewControl\Factory(
25 new SignalGenerator()
26 );
27 }
28
29 public function testConstruction()
30 {
31 $f = $this->getFactory();
32 $sortation = $f->sortation($this->options);
33 $this->assertInstanceOf(
34 "ILIAS\\UI\\Component\\ViewControl\\Sortation",
35 $sortation
36 );
37 $this->assertInstanceOf(
38 "ILIAS\\UI\\Component\\Signal",
39 $sortation->getSelectSignal()
40 );
41 }
42
43 public function testAttributes()
44 {
45 $f = $this->getFactory();
46 $s = $f->sortation($this->options);
47
48 $this->assertEquals($this->options, $s->getOptions());
49
50 $this->assertEquals('label', $s->withLabel('label')->getLabel());
51
52 $s = $s->withTargetURL('#', 'param');
53 $this->assertEquals('#', $s->getTargetURL());
54 $this->assertEquals('param', $s->getParameterName());
55
56 $this->assertEquals(array(), $s->getTriggeredSignals());
57 $generator = new SignalGenerator();
58 $signal = $generator->create();
59 $this->assertEquals(
60 $signal,
61 $s->withOnSort($signal)->getTriggeredSignals()[0]->getSignal()
62 );
63 }
64
65 public function testRendering()
66 {
67 $f = $this->getFactory();
68 $r = $this->getDefaultRenderer();
69 $s = $f->sortation($this->options);
70
71 $html = $this->normalizeHTML($r->render($s));
72 $this->assertEquals(
74 $html
75 );
76 }
77
78 protected function getSortationExpectedHTML()
79 {
80 $expected = <<<EOT
81<div class="il-viewcontrol-sortation" id=""><div class="dropdown"><button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown" aria-label="actions" aria-haspopup="true" aria-expanded="false" > <span class="caret"></span></button><ul class="dropdown-menu">
82 <li><button class="btn btn-link" data-action="?sortation=internal_rating" id="id_1">Best</button></li>
83 <li><button class="btn btn-link" data-action="?sortation=date_desc" id="id_2">Most Recent</button></li>
84 <li><button class="btn btn-link" data-action="?sortation=date_asc" id="id_3">Oldest</button></li></ul></div>
85</div>
86EOT;
87 return $this->normalizeHTML($expected);
88 }
89
90 public function getUIFactory()
91 {
92 $factory = new class extends NoUIFactory {
93 public function button()
94 {
95 return new I\Component\Button\Factory();
96 }
97 public function dropdown()
98 {
99 return new I\Component\Dropdown\Factory();
100 }
101 };
102 return $factory;
103 }
104}
An exception for terminatinating execution or to throw for unit testing.
Provides common functionality for UI tests.
Definition: Base.php:225
getDefaultRenderer(JavaScriptBinding $js_binding=null)
Definition: Base.php:268
normalizeHTML($html)
Definition: Base.php:317
Test on icon implementation.
$factory
Definition: metadata.php:58