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