ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LSControlBuilderTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
25use ILIAS\Data\Factory as DataFactory;
28
29require_once('IliasMocks.php');
30
31class LSControlBuilderTest extends TestCase
32{
33 use IliasMocks;
34
36
37 protected function setUp(): void
38 {
39 $ui_factory = $this->mockUIFactory();
40 $lang = $this->mockIlLanguage();
41
42 $data_factory = new DataFactory();
43 $uri = $data_factory->uri('https://ilias.de/somepath');
44 $url_builder = new LSUrlBuilder($uri);
45 $settings = new LSGlobalSettings(12);
46 $uri = $data_factory->uri('http://ilias.de/some/other/path');
47 $lp_url_builder = new LSUrlBuilder($uri);
48
49 $this->control_builder = new LSControlBuilder($ui_factory, $url_builder, $lang, $settings, $lp_url_builder);
50 }
51
52 public function testConstruction(): void
53 {
54 $this->assertInstanceOf(ControlBuilder::class, $this->control_builder);
55 }
56
57 public function testInitialValues(): void
58 {
59 $this->assertNull($this->control_builder->getExitControl());
60 $this->assertNull($this->control_builder->getNextControl());
61 $this->assertNull($this->control_builder->getPreviousControl());
62 $this->assertNull($this->control_builder->getDoneControl());
63 $this->assertEquals([], $this->control_builder->getControls());
64 $this->assertNull($this->control_builder->getToc());
65 }
66
67 public function testExit(): void
68 {
69 $cb = $this->control_builder->exit('cmd');
70 $this->assertInstanceOf(ControlBuilder::class, $cb);
71 $this->assertInstanceOf(Button\Bulky::class, $cb->getExitControl());
72 }
73
74 public function testUniqueExit(): void
75 {
76 try {
77 //must not be able to set a second exit-control
78 $this->control_builder
79 ->exit('cmd')
80 ->exit('cmd');
81 $this->assertFalse("This should not happen");
82 } catch (LogicException $e) {
83 $this->assertTrue(true);
84 }
85 }
86
87 public function testNavigationControls(): void
88 {
89 $cb = $this->control_builder
90 ->previous('cmd', -1)
91 ->next('cmd', 1);
92 $this->assertInstanceOf(ControlBuilder::class, $cb);
93 $this->assertInstanceOf(Button\Standard::class, $cb->getPreviousControl());
94 $this->assertInstanceOf(Button\Standard::class, $cb->getNextControl());
95 }
96
97 public function testUniquePrevious(): void
98 {
99 try {
100 $this->control_builder
101 ->previous('cmd', 1)
102 ->previous('cmd', 1);
103 $this->assertFalse("This should not happen");
104 } catch (LogicException $e) {
105 $this->assertTrue(true);
106 }
107 }
108
109 public function testUniqueNext(): void
110 {
111 try {
112 $this->control_builder
113 ->next('cmd', 1)
114 ->next('cmd', 1);
115 $this->assertFalse("This should not happen");
116 } catch (LogicException $e) {
117 $this->assertTrue(true);
118 }
119 }
120
121 public function testToC(): void
122 {
123 $toc = $this->control_builder->tableOfContent('cmd', 'rootnode');
124 $this->assertInstanceOf(TOCBuilder::class, $toc);
125 $this->assertEquals($toc, $this->control_builder->getToc());
126 }
127
128 public function testUniqueToC(): void
129 {
130 try {
131 $this->control_builder->tableOfContent('cmd', 'rootnode')
132 ->end();
133 $this->control_builder->tableOfContent('cmd', 'rootnode');
134 $this->assertFalse("This should not happen");
135 } catch (LogicException $e) {
136 $this->assertTrue(true);
137 }
138 }
139
140 public function testGeneric(): void
141 {
142 $cb = $this->control_builder->generic('label', 'cmd', 1);
143 $this->assertInstanceOf(ControlBuilder::class, $cb);
144 $this->assertInstanceOf(Button\Standard::class, $cb->getControls()[0]);
145 }
146
147 public function testMultipleGeneric(): void
148 {
149 $cb = $this->control_builder
150 ->generic('label', 'cmd', 1)
151 ->generic('label', 'cmd', 2)
152 ->generic('label', 'cmd', 3);
153 $this->assertCount(3, $cb->getControls());
154 }
155
156 public function testDone(): void
157 {
158 $cb = $this->control_builder->done('cmd', 1);
159 $this->assertInstanceOf(ControlBuilder::class, $cb);
160 $this->assertInstanceOf(Button\Primary::class, $cb->getDoneControl());
161 }
162
163 public function testUniqueDone(): void
164 {
165 try {
166 $this->control_builder
167 ->done('cmd', 1)
168 ->done('cmd', 1);
169 $this->assertFalse("This should not happen");
170 } catch (LogicException $e) {
171 $this->assertTrue(true);
172 }
173 }
174
175 public function testMode(): void
176 {
177 $cb = $this->control_builder->mode('cmd', ['m1', 'm2']);
178 $this->assertInstanceOf(ControlBuilder::class, $cb);
179 $this->assertInstanceOf(ViewControl\Mode::class, $cb->getModeControls()[0]);
180 }
181
182 public function testLocator(): void
183 {
184 $cb = $this->control_builder->locator('cmd');
185 $this->assertInstanceOf(LocatorBuilder::class, $cb);
186 }
187
188 public function testUniqueLocator(): void
189 {
190 try {
191 $this->control_builder->locator('cmd')
192 ->end();
193 $this->control_builder->locator('cmd');
194 $this->assertFalse("This should not happen");
195 } catch (LogicException $e) {
196 $this->assertTrue(true);
197 }
198 }
199}
Builds data types.
Definition: Factory.php:36
LSControlBuilder $control_builder
Global Settings of the Learning Sequence.
Build controls for the view.
Build a locator for the view.
Build a nested table of contents for the view.
Definition: TOCBuilder.php:29
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Bulky.php:21
$lang
Definition: xapiexit.php:25