ILIAS  release_8 Revision v8.24
ilTermsOfServiceBaseTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use PHPUnit\Framework\MockObject\MockObject;
25use PHPUnit\Framework\TestCase;
27
32abstract class ilTermsOfServiceBaseTest extends TestCase
33{
34 protected Container $dic;
35
36 protected function setUp(): void
37 {
38 $this->dic = new Container();
39 $GLOBALS['DIC'] = $this->dic;
40
41 $this->setGlobalVariable('lng', $this->getLanguageMock());
42 $this->setGlobalVariable(
43 'ilCtrl',
44 $this->getMockBuilder(ilCtrl::class)->disableOriginalConstructor()->getMock()
45 );
46 $this->setGlobalVariable(
47 'upload',
48 $this->getMockBuilder(FileUpload::class)->disableOriginalConstructor()->getMock()
49 );
50
51 parent::setUp();
52 }
53
57 protected function getLanguageMock(): ilLanguage
58 {
59 $lng = $this
60 ->getMockBuilder(ilLanguage::class)
61 ->disableOriginalConstructor()
62 ->onlyMethods(['txt', 'getInstalledLanguages', 'loadLanguageModule'])
63 ->getMock();
64
65 return $lng;
66 }
67
71 protected function getUiFactoryMock(): Factory
72 {
73 $ui = $this
74 ->getMockBuilder(Factory::class)
75 ->getMock();
76
77 $ui->method('legacy')->willReturnCallback(function ($content) {
78 $legacyMock = $this
79 ->getMockBuilder(Legacy::class)
80 ->getMock();
81 $legacyMock->method('getContent')->willReturn($content);
82
83 return $legacyMock;
84 });
85
86 return $ui;
87 }
88
93 protected function setGlobalVariable(string $name, $value): void
94 {
95 global $DIC;
96
97 $GLOBALS[$name] = $value;
98
99 unset($DIC[$name]);
100 $DIC[$name] = static function ($c) use ($name) {
101 return $GLOBALS[$name];
102 };
103 }
104
109 protected function getCriterionConfig($value = null): ilTermsOfServiceCriterionConfig
110 {
111 if (null === $value) {
113 }
114
115 return new ilTermsOfServiceCriterionConfig($value);
116 }
117}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
language handling
Class ilTermsOfServiceBaseTest.
setGlobalVariable(string $name, $value)
Class ilTermsOfServiceCriterionConfig.
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
This is how the factory for UI elements looks.
Definition: Factory.php:38
if($format !==null) $name
Definition: metadata.php:247
$lng