ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ViewControlModeTest.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()->mode($options);
40 $this->assertEquals($options, $vc->getOptions());
41 }
42
43 public function testViewControlModeWithWrongValue(): void
44 {
45 $this->expectException(\Exception::class);
46 $options = [
47 'opt1' => 'A',
48 'opt2' => 'B',
49 'opt3' => 'C',
50 ];
51 $vc = $this->buildVCFactory()->mode($options)
52 ->withValue(123);
53 }
54
55 public function testViewControlModeWithInput(): void
56 {
57 $options = [
58 'opt1' => 'A',
59 'opt2' => 'B',
60 'opt3' => 'C',
61 ];
62 $v = 'opt2';
63
64 $input = $this->createMock(InputData::class);
65 $input->expects($this->once())
66 ->method("getOr")
67 ->willReturn($v);
68
69 $vc = $this->buildVCFactory()->mode($options)
70 ->withNameFrom($this->getNamesource())
71 ->withInput($input);
72
73 $df = $this->buildDataFactory();
74 $this->assertEquals(
75 $df->ok('opt2'),
76 $vc->getContent()
77 );
78 $this->assertEquals($v, $vc->getValue());
79 }
80
81 public function testViewControlModeRendering(): void
82 {
83 $r = $this->getDefaultRenderer();
84 $options = [
85 'opt1' => 'A',
86 'opt2' => 'B'
87 ];
88 $vc = $this->buildVCFactory()->mode($options)
89 ->withOnChange((new SignalGenerator())->create());
90
91 $expected = $this->brutallyTrimHTML('
92 <div class="il-viewcontrol il-viewcontrol-mode l-bar__element" aria-label="label_modeviewcontrol" role="group">
93 <button class="btn btn-default engaged" aria-pressed="true" data-action="#" id="id_1">A</button>
94 <button class="btn btn-default" aria-pressed="false" data-action="#" id="id_2">B</button>
95 <div class="il-viewcontrol-value" role="none">
96 <input type="hidden" name="" value="opt1" />
97 </div>
98 </div>
99 ');
100 $html = $this->brutallyTrimHTML($r->render($vc));
101 $this->assertEquals($expected, $html);
102 }
103
105 {
106 $this->expectException(\LogicException::class);
107 $this->buildVCFactory()->mode([])->getOnChangeSignal();
108 }
109
110 public function testViewControlModeWithoutOptions(): void
111 {
112 $this->expectException(\InvalidArgumentException::class);
113 $vc = $this->buildVCFactory()->mode([]);
114 }
115
117 {
118 $this->expectException(\InvalidArgumentException::class);
119 $vc = $this->buildVCFactory()->mode([1,2,3]);
120 }
121
122}
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