ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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('ViewControlTestBase.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="glyphicon-columnSelection"></span></button>
96 <div id="id_3_ctrl" class="dropdown-menu">
97 <ul class="dropdown-menu-list">
98 <li><input type="checkbox" value="opt1" id="id_1" /><label for="id_1">A</label></li>
99 <li><input type="checkbox" value="opt2" id="id_2" /><label for="id_2">B</label></li>
100 </ul>
101 <button class="btn btn-default" id="id_4">label_fieldselection_refresh</button>
102 </div>
103 <div class="il-viewcontrol-value" role="none"></div>
104</div>
105');
106 $html = $this->brutallyTrimHTML($r->render($vc));
107 $this->assertEquals($expected, $html);
108 }
109
111 {
112 $this->expectException(\LogicException::class);
113 $this->buildVCFactory()->fieldSelection([])->getOnChangeSignal();
114 }
115}
Builds data types.
Definition: Factory.php:36
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