ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
assBaseTestCase.php
Go to the documentation of this file.
1 <?php
2 
21 use ILIAS\Refinery\Random\Group as RandomGroup;
23 
27 abstract class assBaseTestCase extends TestCase
28 {
29  protected ?Container $dic = null;
30 
34  protected function setUp(): void
35  {
36  global $DIC;
37 
38  $this->dic = is_object($DIC) ? clone $DIC : $DIC;
39 
40  $DIC = new Container();
41 
42  $lng_mock = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->onlyMethods(['txt'])->getMock();
43  $lng_mock->expects($this->any())->method('txt')->willReturn('Test');
44  $this->setGlobalVariable('lng', $lng_mock);
45 
46  $dataCache_mock = $this->getMockBuilder(ilObjectDataCache::class)->disableOriginalConstructor()->getMock();
47  $this->setGlobalVariable('ilObjDataCache', $dataCache_mock);
48 
49  $access_mock = $this->createMock(ilAccessHandler::class);
50  $this->setGlobalVariable('ilAccess', $access_mock);
51 
52  $help_mock = $this->getMockBuilder(ilHelpGUI::class)->disableOriginalConstructor()->getMock();
53  $this->setGlobalVariable('ilHelp', $help_mock);
54 
55  $user_mock = $this->getMockBuilder(ilObjUser::class)->disableOriginalConstructor()->getMock();
56  $this->setGlobalVariable('ilUser', $user_mock);
57 
58  $tabs_mock = $this->getMockBuilder(ilTabsGUI::class)->disableOriginalConstructor()->getMock();
59  $this->setGlobalVariable('ilTabs', $tabs_mock);
60 
61  $rbacsystem_mock = $this->getMockBuilder(ilRbacSystem::class)->disableOriginalConstructor()->getMock();
62  $this->setGlobalVariable('rbacsystem', $rbacsystem_mock);
63 
64  $refineryMock = $this->getMockBuilder(RefineryFactory::class)->disableOriginalConstructor()->getMock();
65  $refineryMock->method('random')->willReturn($this->getMockBuilder(RandomGroup::class)->getMock());
66  $this->setGlobalVariable('refinery', $refineryMock);
67 
68  $dbMock = $this->createMock(ilDBInterface::class);
69  $this->setGlobalVariable('ilDB', $dbMock);
70 
71  $treeMock = $this->createMock(ilTree::class);
72  $this->setGlobalVariable('tree', $treeMock);
73 
74  $repository_mock = $this->createMock(ilComponentRepository::class);
75  $this->setGlobalVariable('component.repository', $repository_mock);
76 
77  $this->setGlobalVariable('http', $this->getMockBuilder(ILIAS\HTTP\Services::class)->disableOriginalConstructor()->getMock());
78 
79  $this->setGlobalVariable('upload', $this->createMock(ILIAS\FileUpload\FileUpload::class));
80 
81  parent::setUp();
82  }
83 
84  protected function tearDown(): void
85  {
86  global $DIC;
87 
88  $DIC = $this->dic;
89 
90  parent::tearDown();
91  }
92 
97  protected function setGlobalVariable(string $name, $value): void
98  {
99  global $DIC;
100 
101  $GLOBALS[$name] = $value;
102 
103  unset($DIC[$name]);
104  $DIC[$name] = static function (Container $c) use ($value) {
105  return $value;
106  };
107  }
108 
109  protected function getGlobalTemplateMock()
110  {
111  return $this->getMockBuilder(\ilGlobalPageTemplate::class)->disableOriginalConstructor()->getMock();
112  }
113 
114  protected function getDatabaseMock()
115  {
116  return $this->getMockBuilder(\ilDBInterface::class)->disableOriginalConstructor()->getMock();
117  }
118 
119  protected function getIliasMock()
120  {
121  $mock = $this->getMockBuilder(\ILIAS::class)->disableOriginalConstructor()->getMock();
122 
123  $account = new stdClass();
124  $account->id = 6;
125  $account->fullname = 'Esther Tester';
126 
127  $mock->account = $account;
128 
129  return $mock;
130  }
131 }
$c
Definition: cli.php:38
Class ChatMainBarProvider .
Class assBaseTestCase.
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:31
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
setGlobalVariable(string $name, $value)