ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
LSControlBuilderTest.php
Go to the documentation of this file.
1<?php
2
3use PHPUnit\Framework\TestCase;
7use ILIAS\Data\Factory as DataFactory;
10
11require_once('IliasMocks.php');
12
13class LSControlBuilderTest extends TestCase
14{
15 use IliasMocks;
16
17 public function setUp() : void
18 {
19 $ui_factory = $this->mockUIFactory();
20 $lang = $this->mockIlLanguage();
21
22 $data_factory = new DataFactory();
23 $uri = $data_factory->uri('http://ilias.de/somepath');
24 $url_builder = new LSUrlBuilder($uri);
25 $settings = new LSGlobalSettings(12);
26
27 $this->control_builder = new LSControlBuilder($ui_factory, $url_builder, $lang, $settings);
28 }
29
30 public function testConstruction()
31 {
32 $this->assertInstanceOf(ControlBuilder::class, $this->control_builder);
33 }
34
35 public function testInitialValues()
36 {
37 $this->assertNull($this->control_builder->getExitControl());
38 $this->assertNull($this->control_builder->getNextControl());
39 $this->assertNull($this->control_builder->getPreviousControl());
40 $this->assertNull($this->control_builder->getDoneControl());
41 $this->assertEquals([], $this->control_builder->getControls());
42 $this->assertNull($this->control_builder->getToc());
43 }
44
45 public function testExit()
46 {
47 $cb = $this->control_builder->exit('cmd');
48 $this->assertInstanceOf(ControlBuilder::class, $cb);
49 $this->assertInstanceOf(Button\Bulky::class, $cb->getExitControl());
50 }
51
52 public function testUniqueExit()
53 {
54 try {
55 //must not be able to set a second exit-control
56 $cb = $this->control_builder
57 ->exit('cmd')
58 ->exit('cmd');
59 $this->assertFalse("This should not happen");
60 } catch (\LogicException $e) {
61 $this->assertTrue(true);
62 }
63 }
64
65 public function testNavigationControls()
66 {
67 $cb = $this->control_builder
68 ->previous('cmd', -1)
69 ->next('cmd', 1);
70 $this->assertInstanceOf(ControlBuilder::class, $cb);
71 $this->assertInstanceOf(Button\Standard::class, $cb->getPreviousControl());
72 $this->assertInstanceOf(Button\Standard::class, $cb->getNextControl());
73 }
74
75 public function testUniquePrevious()
76 {
77 try {
78 $cb = $this->control_builder
79 ->previous('cmd', 1)
80 ->previous('cmd', 1);
81 $this->assertFalse("This should not happen");
82 } catch (\LogicException $e) {
83 $this->assertTrue(true);
84 }
85 }
86
87 public function testUniqueNext()
88 {
89 try {
90 $cb = $this->control_builder
91 ->next('cmd', 1)
92 ->next('cmd', 1);
93 $this->assertFalse("This should not happen");
94 } catch (\LogicException $e) {
95 $this->assertTrue(true);
96 }
97 }
98
99 public function testToC()
100 {
101 $toc = $this->control_builder->tableOfContent('cmd', 'rootnode');
102 $this->assertInstanceOf(TOCBuilder::class, $toc);
103 $this->assertEquals($toc, $this->control_builder->getToc());
104 }
105
106 public function testUniqueToC()
107 {
108 try {
109 $toc = $this->control_builder->tableOfContent('cmd', 'rootnode')
110 ->end();
111 $toc = $this->control_builder->tableOfContent('cmd', 'rootnode');
112 $this->assertFalse("This should not happen");
113 } catch (\LogicException $e) {
114 $this->assertTrue(true);
115 }
116 }
117
118 public function testGeneric()
119 {
120 $cb = $this->control_builder->generic('label', 'cmd', 1);
121 $this->assertInstanceOf(ControlBuilder::class, $cb);
122 $this->assertInstanceOf(Button\Standard::class, $cb->getControls()[0]);
123 }
124
125 public function testMultipleGeneric()
126 {
127 $cb = $this->control_builder
128 ->generic('label', 'cmd', 1)
129 ->generic('label', 'cmd', 2)
130 ->generic('label', 'cmd', 3);
131 $this->assertEquals(3, count($cb->getControls()));
132 }
133
134 public function testDone()
135 {
136 $cb = $this->control_builder->done('cmd', 1);
137 $this->assertInstanceOf(ControlBuilder::class, $cb);
138 $this->assertInstanceOf(Button\Primary::class, $cb->getDoneControl());
139 }
140
141 public function testUniqueDone()
142 {
143 try {
144 $cb = $this->control_builder
145 ->done('cmd', 1)
146 ->done('cmd', 1);
147 $this->assertFalse("This should not happen");
148 } catch (\LogicException $e) {
149 $this->assertTrue(true);
150 }
151 }
152
153 public function testMode()
154 {
155 $cb = $this->control_builder->mode('cmd', ['m1', 'm2']);
156 $this->assertInstanceOf(ControlBuilder::class, $cb);
157 $this->assertInstanceOf(ViewControl\Mode::class, $cb->getModeControls()[0]);
158 }
159
160 public function testLocator()
161 {
162 $cb = $this->control_builder->locator('cmd');
163 $this->assertInstanceOf(LocatorBuilder::class, $cb);
164 }
165
166 public function testUniqueLocator()
167 {
168 try {
169 $loc = $this->control_builder->locator('cmd')
170 ->end();
171 $loc = $this->control_builder->locator('cmd');
172 $this->assertFalse("This should not happen");
173 } catch (\LogicException $e) {
174 $this->assertTrue(true);
175 }
176 }
177}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
Class LSControlBuilder.
Global Settings of the Learning Sequence.
Class LSUrlBuilder.
Build controls for the view.
Build a locator for the view.
Build a nested table of contents for the view.
Definition: TOCBuilder.php:12
$lang
Definition: xapiexit.php:8