ILIAS  release_8 Revision v8.24
ViewControlFieldSelectionTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25use ILIAS\Data;
26use ILIAS\Refinery\Factory as Refinery;
28
29require_once('ViewControlBaseTest.php');
30
32{
34 {
35 $options = [
36 'opt1' => 'A',
37 'opt2' => 'B'
38 ];
39 $vc = $this->buildVCFactory()->fieldSelection($options);
40 $this->assertInstanceOf(Signal::class, $vc->getInternalSignal());
41 $this->assertEquals($options, $vc->getOptions());
42 $this->assertEquals('', $vc->getButtonLabel());
43 }
44
46 {
47 $this->expectException(\Exception::class);
48 $options = [
49 'opt1' => 'A',
50 'opt2' => 'B',
51 'opt3' => 'C',
52 ];
53 $vc = $this->buildVCFactory()->fieldSelection($options)
54 ->withValue('notokvalue,something');
55 }
56
58 {
59 $options = [
60 'opt1' => 'A',
61 'opt2' => 'B',
62 'opt3' => 'C',
63 ];
64 $v = ['opt1','opt2'];
65
66 $input = $this->createMock(InputData::class);
67 $input->expects($this->once())
68 ->method("getOr")
69 ->willReturn($v);
70
71 $vc = $this->buildVCFactory()->fieldSelection($options)
72 ->withNameFrom($this->getNamesource())
73 ->withInput($input);
74
75 $df = $this->buildDataFactory();
76 $this->assertEquals(
77 $df->ok(['opt1','opt2']),
78 $vc->getContent()
79 );
80 $this->assertEquals($v, $vc->getValue());
81 }
82
84 {
85 $r = $this->getDefaultRenderer();
86 $options = [
87 'opt1' => 'A',
88 'opt2' => 'B'
89 ];
90 $vc = $this->buildVCFactory()->fieldSelection($options)
91 ->withOnChange((new SignalGenerator())->create());
92
93 $expected = $this->brutallyTrimHTML('
94<div class="dropdown il-viewcontrol il-viewcontrol-fieldselection l-bar__element" id="id_3">
95 <button class="btn btn-ctrl dropdown-toggle" type="button" data-toggle="dropdown" aria-label="label_fieldselection" aria-haspopup="true" aria-expanded="false" aria-controls="id_3_ctrl"><span class="caret"></span></button>
96 <ul id="id_3_ctrl" class="dropdown-menu">
97 <li><input type="checkbox" value="opt1" id="id_1" /><label for="id_1">A</label></li>
98 <li><input type="checkbox" value="opt2" id="id_2" /><label for="id_2">B</label></li>
99
100 <button class="btn btn-default" id="id_4">label_fieldselection_refresh</button>
101 </ul>
102 <div class="il-viewcontrol-value" role="none"></div>
103</div>
104');
105 $html = $this->brutallyTrimHTML($r->render($vc));
106 $this->assertEquals($expected, $html);
107 }
108
110 {
111 $this->expectException(\LogicException::class);
112 $this->buildVCFactory()->fieldSelection([])->getOnChangeSignal();
113 }
114}
Builds data types.
Definition: Factory.php:21
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
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