ILIAS  trunk Revision v11.0_alpha-1753-gb21ca8c4367
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCtrlTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
26 
32 class ilCtrlTest extends TestCase
33 {
34  public function testCallBaseClassWithoutBaseClass(): void
35  {
36  $ctrl = $this->getMockedCtrl();
37 
38  $this->expectException(ilCtrlException::class);
39  $this->expectExceptionMessage(ilCtrl::class . "::callBaseClass was not given a baseclass and the request doesn't include one either.");
40  $ctrl->callBaseClass();
41  }
42 
44  {
45  $structure = $this->createMock(ilCtrlStructureInterface::class);
47  ->method('isBaseClass')
48  ->willReturn(false)
49  ;
50 
51  $ctrl = new ilCtrl(
52  $structure,
53  $this->createMock(ilCtrlTokenRepositoryInterface::class),
54  $this->createMock(ilCtrlPathFactoryInterface::class),
55  $this->createMock(ilCtrlContextInterface::class),
56  $this->createMock(ResponseSenderStrategy::class),
57  $this->createMock(ServerRequestInterface::class),
58  $this->createMock(RequestWrapper::class),
59  $this->createMock(RequestWrapper::class),
60  $this->createMock(Refinery::class),
61  $this->createMock(ilComponentFactory::class),
62  new ilCtrlSubject(),
63  $this->createMock(ilCtrlQueryParserInterface::class),
64  );
65 
66  $invalid_baseclass = ilCtrlInvalidGuiClass::class;
67 
68  $this->expectException(ilCtrlException::class);
69  $this->expectExceptionMessage("Provided class '$invalid_baseclass' is not a baseclass");
70  $ctrl->callBaseClass($invalid_baseclass);
71  }
72 
73  public function testForwardCommandWithInvalidObject(): void
74  {
75  $ctrl = $this->getMockedCtrl();
76 
77  require_once __DIR__ . '/Data/GUI/class.ilCtrlInvalidGuiClass.php';
78 
79  $this->expectException(ilCtrlException::class);
80  $this->expectExceptionMessage(ilCtrlInvalidGuiClass::class . " doesn't implement executeCommand().");
81  $ctrl->forwardCommand(new ilCtrlInvalidGuiClass());
82  }
83 
84  public function testForwardCommandWithValidObject(): void
85  {
86  $ctrl = $this->getMockedCtrl();
87 
88  require_once __DIR__ . '/Data/GUI/class.ilCtrlCommandClass1TestGUI.php';
89 
90  $this->assertEquals(
91  ilCtrlCommandClass1TestGUI::class,
92  $ctrl->forwardCommand(new ilCtrlCommandClass1TestGUI())
93  );
94  }
95 
96  public function testGetHtmlWithInvalidObject(): void
97  {
98  $ctrl = $this->getMockedCtrl();
99 
100  require_once __DIR__ . '/Data/GUI/class.ilCtrlInvalidGuiClass.php';
101 
102  $this->expectException(ilCtrlException::class);
103  $this->expectExceptionMessage(ilCtrlInvalidGuiClass::class . " doesn't implement getHTML().");
104  $ctrl->getHTML(new ilCtrlInvalidGuiClass());
105  }
106 
107  public function testGetHtmlWithValidObject(): void
108  {
109  $ctrl = $this->getMockedCtrl();
110 
111  require_once __DIR__ . '/Data/GUI/class.ilCtrlCommandClass2TestGUI.php';
112 
113  $this->assertEquals('foo', $ctrl->getHTML(new ilCtrlCommandClass2TestGUI()));
114  }
115 
117  {
118  $ctrl = $this->getMockedCtrl();
119 
120  require_once __DIR__ . '/Data/GUI/class.ilCtrlCommandClass2TestGUI.php';
121 
122  $this->assertEquals('bar', $ctrl->getHTML(new ilCtrlCommandClass2TestGUI(), ['bar']));
123  }
124 
125  public function testGetCmdWithoutProvidedCmd(): void
126  {
127  $ctrl = $this->getMockedCtrl();
128 
129  // @TODO: change this to assertNull() once null coalescing operators are removed.
130  $this->assertEmpty($ctrl->getCmd());
131  }
132 
134  {
135  $ctrl = new ilCtrl(
136  $this->createMock(ilCtrlStructureInterface::class),
137  $this->createMock(ilCtrlTokenRepositoryInterface::class),
138  $this->createMock(ilCtrlPathFactoryInterface::class),
139  $this->createMock(ilCtrlContextInterface::class),
140  $this->createMock(ResponseSenderStrategy::class),
141  $this->createMock(ServerRequestInterface::class),
142  $this->createMock(RequestWrapper::class),
143  $this->createMock(RequestWrapper::class),
144  $this->createMock(Refinery::class),
145  $this->createMock(ilComponentFactory::class),
146  new ilCtrlSubject(),
147  $this->createMock(ilCtrlQueryParserInterface::class),
148  );
149 
150  $fallback_cmd = 'fallback_cmd_test';
151 
152  $this->assertEquals(
153  $fallback_cmd,
154  $ctrl->getCmd($fallback_cmd)
155  );
156  }
157 
158  // @TODO: coming soon, I promise!
159 
160  /*
161  public function testGetCmdWithUnsafePostCmd() : void
162  {
163 
164  }
165 
166  public function testGetCmdWithSafePostCmd() : void
167  {
168 
169  }
170 
171  public function testGetCmdWithUnsafeGetCmd() : void
172  {
173 
174  }
175 
176  public function testGetCmdWithSafeGetCmd() : void
177  {
178 
179  }
180 
181  public function testGetCmdWithValidCsrfToken() : void
182  {
183 
184  }
185 
186  public function testGetCmdWithInvalidCsrfToken() : void
187  {
188 
189  }
190 
191  public function testGetNextClass() : void
192  {
193 
194  }
195 
196  public function testGetParameterArrayByClass() : void
197  {
198 
199  }
200 
201  public function testGetLinkTargetByClass() : void
202  {
203 
204  }
205 
206  public function testGetFormActionByClass() : void
207  {
208 
209  }
210 
211  public function testGetParentReturnByClass() : void
212  {
213 
214  }
215  */
216 
223  private function getMockedCtrl(): ilCtrlInterface
224  {
225  return new ilCtrl(
226  $this->createMock(ilCtrlStructureInterface::class),
227  $this->createMock(ilCtrlTokenRepositoryInterface::class),
228  $this->createMock(ilCtrlPathFactoryInterface::class),
229  $this->createMock(ilCtrlContextInterface::class),
230  $this->createMock(ResponseSenderStrategy::class),
231  $this->createMock(ServerRequestInterface::class),
232  $this->createMock(RequestWrapper::class),
233  $this->createMock(RequestWrapper::class),
234  $this->createMock(Refinery::class),
235  $this->createMock(ilComponentFactory::class),
236  new ilCtrlSubject(),
237  $this->createMock(ilCtrlQueryParserInterface::class),
238  );
239  }
240 }
testForwardCommandWithInvalidObject()
Definition: ilCtrlTest.php:73
Class ilCtrlTest.
Definition: ilCtrlTest.php:32
Class ilCtrlInvalidGuiClass.
testCallBaseClassWithoutBaseClass()
Definition: ilCtrlTest.php:34
getMockedCtrl()
Helper function that returns an ilCtrl instance with mocked dependencies.
Definition: ilCtrlTest.php:223
Class ilCtrlCommandClass1TestGUI.
$structure
TOTAL STRUCTURE.
testGetHtmlWithValidObjectAndParameters()
Definition: ilCtrlTest.php:116
testGetCmdWithoutProvidedCmdAndFallback()
Definition: ilCtrlTest.php:133
testForwardCommandWithValidObject()
Definition: ilCtrlTest.php:84
Class ilCtrlCommandClass2TestGUI.
testGetHtmlWithInvalidObject()
Definition: ilCtrlTest.php:96
testGetCmdWithoutProvidedCmd()
Definition: ilCtrlTest.php:125
testGetHtmlWithValidObject()
Definition: ilCtrlTest.php:107
testCallBaseClassWithInvalidProvidedBaseClass()
Definition: ilCtrlTest.php:43