ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ViewControlSortationTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26use ILIAS\Refinery\Factory as Refinery;
28
29require_once('ViewControlTestBase.php');
30
32{
33 public function testViewControlSortationConstruct(): void
34 {
35 $options = [
36 'A' => new Order('opt', 'ASC'),
37 'B' => new Order('opt', 'DESC')
38 ];
39 $vc = $this->buildVCFactory()->sortation($options);
40 $r = ILIAS\UI\Implementation\Component\Input\ViewControl\Renderer::class;
41
42 $this->assertInstanceOf(Signal::class, $vc->getInternalSignal());
43 $this->assertEquals($options, $vc->getOptions());
44 }
45
47 {
48 $this->expectException(\InvalidArgumentException::class);
49 $options = [
50 'A' => new Order('opt', 'ASC'),
51 'B' => new Order('opt', 'DESC')
52 ];
53 $vc = $this->buildVCFactory()->sortation($options)
54 ->withValue('notokvalue:DESC');
55 }
56
57 public function testViewControlSortationWithInput(): void
58 {
59 $options = [
60 'A' => new Order('opt', 'ASC'),
61 'B' => new Order('opt', 'DESC')
62 ];
63 $v = ['opt', 'DESC'];
64
65 $input = $this->createMock(InputData::class);
66 $input->expects($this->exactly(2))
67 ->method("getOr")
68 ->will(
69 $this->onConsecutiveCalls($v[0], $v[1])
70 );
71
72 $vc = $this->buildVCFactory()->sortation($options)
73 ->withNameFrom($this->getNamesource())
74 ->withInput($input);
75
76 $df = $this->buildDataFactory();
77 $this->assertEquals(
78 $df->ok($df->order('opt', 'DESC')),
79 $vc->getContent()
80 );
81 $this->assertEquals($v, $vc->getValue());
82 }
83
85 {
86 $r = $this->getDefaultRenderer();
87 $options = [
88 'A' => new Order('opt', 'ASC'),
89 'B' => new Order('opt', 'DESC')
90 ];
91 $vc = $this->buildVCFactory()->sortation($options)
92 ->withOnChange((new SignalGenerator())->create());
93
94 $expected = $this->brutallyTrimHTML('
95<div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_3">
96 <button class="btn btn-ctrl dropdown-toggle" type="button" data-toggle="dropdown" aria-label="label_sortation" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_ctrl"><span class="glyphicon-sort"></span></button>
97 <ul id="id_3_ctrl" class="dropdown-menu">
98 <li><button class="btn btn-link" id="id_1">A</button></li>
99 <li><button class="btn btn-link" id="id_2">B</button></li>
100 </ul>
101 <div class="il-viewcontrol-value" role="none">
102 <input id="id_4" type="hidden" value="" />
103 <input id="id_5" type="hidden" value="" />
104 </div>
105</div>
106');
107 $html = $this->brutallyTrimHTML($r->render($vc));
108 $this->assertEquals($expected, $html);
109 }
110
112 {
113 $options = ['A' => new Order('opt', 'ASC')];
114 $this->expectException(\LogicException::class);
115 $this->buildVCFactory()->sortation($options)->getOnChangeSignal();
116 }
117
118
120 {
121 $r = $this->getDefaultRenderer();
122 $options = [
123 'A' => new Order('opt', 'ASC'),
124 'B' => new Order('opt', 'DESC')
125 ];
126 $vc = $this->buildVCFactory()->sortation($options)
127 ->withOnChange((new SignalGenerator())->create());
128
129 $expected = $this->brutallyTrimHTML('
130<div class="dropdown il-viewcontrol il-viewcontrol-sortation l-bar__element" id="id_3">
131 <button class="btn btn-ctrl dropdown-toggle" type="button" data-toggle="dropdown" aria-label="label_sortation" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_ctrl"><span class="glyphicon-sort"></span></button>
132 <ul id="id_3_ctrl" class="dropdown-menu">
133 <li><button class="btn btn-link" id="id_1">A</button></li>
134 <li><button class="btn btn-link" id="id_2">B</button></li>
135 </ul>
136 <div class="il-viewcontrol-value" role="none">
137 <input id="id_4" type="hidden" value="" />
138 <input id="id_5" type="hidden" value="" />
139 </div>
140</div>
141');
142 $html = $this->brutallyTrimHTML($r->render($vc));
143 $this->assertEquals($expected, $html);
144 }
145
146}
Builds data types.
Definition: Factory.php:36
Both the subject and the direction need to be specified when expressing an order.
Definition: Order.php:29
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
Describes a source for input names.
Definition: NameSource.php:27
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Factory.php:21