ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilTestBaseTestCase.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
29 use ILIAS\Refinery\Random\Group as RandomGroup;
30 
35 class ilTestBaseTestCase extends TestCase
36 {
37  protected ?Container $dic = null;
38 
42  protected function setUp(): void
43  {
44  global $DIC;
45 
46  $this->dic = is_object($DIC) ? clone $DIC : $DIC;
47 
48  $DIC = new Container();
49 
50  $this->addGlobal_tpl();
51  $this->addGlobal_ilDB();
52  $this->addGlobal_ilias();
53  $this->addGlobal_ilLog();
54  $this->addGlobal_ilErr();
55  $this->addGlobal_tree();
56  $this->addGlobal_lng();
58  $this->addGlobal_objDefinition();
59  $this->addGlobal_refinery();
60 
61  $this->getMockBuilder(\ILIAS\DI\LoggingServices::class)->disableOriginalConstructor()->getMock();
62 
63  $http_mock = $this
64  ->getMockBuilder(\ILIAS\HTTP\Services::class)
65  ->disableOriginalConstructor()
66  ->onlyMethods(['request', 'wrapper'])->getMock();
67 
68  $request_mock = $this
69  ->getMockBuilder(\GuzzleHttp\Psr7\ServerRequest::class)
70  ->disableOriginalConstructor()
71  ->onlyMethods(['getParsedBody'])->getMock();
72  $request_mock->method('getParsedBody')->willReturn(array());
73  $http_mock->method('request')->willReturn($request_mock);
74 
75  $wrapper_mock = $this->createMock(\ILIAS\HTTP\Wrapper\WrapperFactory::class);
76  $http_mock->method('wrapper')->willReturn($wrapper_mock);
77 
78  $this->setGlobalVariable('http', $http_mock);
79 
80  parent::setUp();
81  }
82 
83  protected function tearDown(): void
84  {
85  global $DIC;
86 
87  $DIC = $this->dic;
88 
89  parent::tearDown();
90  }
91 
96  protected function setGlobalVariable(string $name, $value): void
97  {
98  global $DIC;
99 
100  $GLOBALS[$name] = $value;
101 
102  unset($DIC[$name]);
103  $DIC[$name] = static function (Container $c) use ($value) {
104  return $value;
105  };
106  }
107 
111  protected function getGlobalTemplateMock()
112  {
113  return $this->getMockBuilder(ilTemplate::class)->disableOriginalConstructor()->getMock();
114  }
115 
119  protected function getDatabaseMock()
120  {
121  return $this->getMockBuilder(ilDBInterface::class)->disableOriginalConstructor()->getMock();
122  }
123 
127  protected function getIliasMock()
128  {
129  $mock = $this->getMockBuilder(ILIAS::class)->disableOriginalConstructor()->getMock();
130 
131  $account = new stdClass();
132  $account->id = 6;
133  $account->fullname = 'Esther Tester';
134 
135  $mock->account = $account;
136 
137  return $mock;
138  }
139 
140  protected function addGlobal_ilAccess(): void
141  {
142  $this->setGlobalVariable("ilAccess", $this->createMock(ilAccess::class));
143  }
144 
145  protected function addGlobal_ilUser(): void
146  {
147  $this->setGlobalVariable("ilUser", $this->createMock(ilObjUser::class));
148  }
149 
150  protected function addGlobal_objDefinition(): void
151  {
152  $this->setGlobalVariable("objDefinition", $this->createMock(ilObjectDefinition::class));
153  }
154 
155  protected function addGlobal_tree(): void
156  {
157  $this->setGlobalVariable("tree", $this->createMock(ilTree::class));
158  }
159 
160  protected function addGlobal_ilSetting(): void
161  {
162  $this->setGlobalVariable("ilSetting", $this->createMock(ilSetting::class));
163  }
164 
165  protected function addGlobal_rbacsystem(): void
166  {
167  $this->setGlobalVariable("rbacsystem", $this->createMock(ilRbacSystem::class));
168  }
169 
170  protected function addGlobal_ilCtrl(): void
171  {
172  $this->setGlobalVariable("ilCtrl", $this->createMock(ilCtrl::class));
173  }
174 
175  protected function addGlobal_lng(): void
176  {
177  $this->setGlobalVariable("lng", $this->createMock(ilLanguage::class));
178  }
179 
180  protected function addGlobal_filesystem(): void
181  {
182  $this->setGlobalVariable("filesystem", $this->createMock(Filesystems::class));
183  }
184 
185  protected function addGlobal_upload(): void
186  {
187  $this->setGlobalVariable("upload", $this->createMock(FileUpload::class));
188  }
189 
190  protected function addGlobal_ilDB(): void
191  {
192  $this->setGlobalVariable("ilDB", $this->createMock(ilDBInterface::class));
193  }
194 
195  protected function addGlobal_ilLog(): void
196  {
197  $this->setGlobalVariable("ilLog", $this->createMock(ilLogger::class));
198  }
199 
200  protected function addGlobal_ilias(): void
201  {
202  $this->setGlobalVariable("ilias", $this->getIliasMock());
203  }
204 
205  protected function addGlobal_ilErr(): void
206  {
207  $this->setGlobalVariable("ilErr", $this->createMock(ilErrorHandling::class));
208  }
209 
210  protected function addGlobal_ilAppEventHandler(): void
211  {
212  $this->setGlobalVariable("ilAppEventHandler", $this->createMock(ilAppEventHandler::class));
213  }
214 
215  protected function addGlobal_tpl(): void
216  {
217  $this->setGlobalVariable("tpl", $this->createMock(ilGlobalPageTemplate::class));
218  }
219 
220  protected function addGlobal_ilComponentRepository(): void
221  {
222  $this->setGlobalVariable("component.repository", $this->createMock(ilComponentRepository::class));
223  }
224 
225  protected function addGlobal_ilTabs(): void
226  {
227  $this->setGlobalVariable("ilTabs", $this->createMock(ilTabsGUI::class));
228  }
229 
230  protected function addGlobal_ilObjDataCache(): void
231  {
232  $this->setGlobalVariable("ilObjDataCache", $this->createMock(ilObjectDataCache::class));
233  }
234 
235  protected function addGlobal_ilLocator(): void
236  {
237  $this->setGlobalVariable("ilLocator", $this->createMock(ilLocatorGUI::class));
238  }
239 
240  protected function addGlobal_rbacreview(): void
241  {
242  $this->setGlobalVariable("rbacreview", $this->createMock(ilRbacReview::class));
243  }
244 
245  protected function addGlobal_ilToolbar(): void
246  {
247  $this->setGlobalVariable("ilToolbar", $this->createMock(ilToolbarGUI::class));
248  }
249 
250  protected function addGlobal_http(): void
251  {
252  $this->setGlobalVariable("http", $this->createMock(Services::class));
253  }
254 
255  protected function addGlobal_ilIliasIniFile(): void
256  {
257  $this->setGlobalVariable("ilIliasIniFile", $this->createMock(ilIniFile::class));
258  }
259 
260  protected function addGlobal_ilLoggerFactory(): void
261  {
262  $this->setGlobalVariable("ilLoggerFactory", $this->createMock(ilLoggerFactory::class));
263  }
264 
265  protected function addGlobal_ilHelp(): void
266  {
267  $this->setGlobalVariable("ilHelp", $this->createMock(ilHelpGUI::class));
268  }
269 
270  protected function addGlobal_ui(): void
271  {
272  $this->setGlobalVariable("ui", $this->createMock(ILIAS\DI\UIServices::class));
273  }
274 
275  protected function addGlobal_uiFactory(): void
276  {
277  $this->setGlobalVariable("ui.factory", $this->createMock(Factory::class));
278  }
279 
280  protected function addGlobal_uiRenderer(): void
281  {
282  $this->setGlobalVariable("ui.renderer", $this->createMock(ILIAS\UI\Implementation\DefaultRenderer::class));
283  }
284 
285  protected function addGlobal_refinery(): void
286  {
287  $refineryMock = $this->getMockBuilder(RefineryFactory::class)->disableOriginalConstructor()->getMock();
288  $refineryMock->expects(self::any())->method('random')->willReturn($this->getMockBuilder(RandomGroup::class)->getMock());
289  $this->setGlobalVariable("refinery", $refineryMock);
290  }
291 }
Class Factory.
$c
Definition: cli.php:38
Class ChatMainBarProvider .
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
Class HTTPServicesTest.
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
setGlobalVariable(string $name, $value)
Class ilTestBaseClass.