ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRBACTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23
29class ilRBACTest extends TestCase
30{
31 protected $backupGlobals = false;
32
33 protected Container $dic;
34
35 protected function setUp(): void
36 {
37 $this->initACDependencies();
38 parent::setUp();
39 }
40
41 public function testConstruct(): void
42 {
43 $system = ilRbacSystem::getInstance();
44 $this->assertTrue($system instanceof ilRbacSystem);
45
46 $admin = new ilRbacAdmin();
47 $this->assertTrue($admin instanceof ilRbacAdmin);
48
49 $review = new ilRbacReview();
50 $this->assertTrue($review instanceof ilRbacReview);
51 }
52
53 protected function setGlobalVariable(string $name, $value): void
54 {
55 global $DIC;
56
57 $GLOBALS[$name] = $value;
58 unset($DIC[$name]);
59 $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
60 return $value;
61 };
62 }
63
64 protected function initACDependencies(): void
65 {
66 $this->dic = new Container();
67 $GLOBALS['DIC'] = $this->dic;
68
69 $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
70 $this->setGlobalVariable('ilUser', $this->createMock(ilObjUser::class));
71 $this->setGlobalVariable('rbacreview', $this->createMock(ilRbacReview::class));
72 $this->setGlobalVariable('ilObjDataCache', $this->createMock(ilObjectDataCache::class));
73 $this->setGlobalVariable('tree', $this->createMock(ilTree::class));
74 $this->setGlobalVariable('http', $this->createMock(\ILIAS\HTTP\Services::class));
75 $this->setGlobalVariable('refinery', $this->createMock(\ILIAS\Refinery\Factory::class));
76
77 $logger = $this->getMockBuilder(ilLogger::class)
78 ->disableOriginalConstructor()
79 ->getMock();
80
81 $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
82 ->disableOriginalConstructor()
83 ->onlyMethods(['getComponentLogger'])
84 ->getMock();
85 $logger_factory->method('getComponentLogger')->willReturn($logger);
86 $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
87
88 if (!defined('ILIAS_LOG_ENABLED')) {
89 define('ILIAS_LOG_ENABLED', true);
90 }
91
92 if (!defined('ILIAS_LOG_DIR')) {
93 define('ILIAS_LOG_DIR', '/var/log');
94 }
95
96 if (!defined('ILIAS_LOG_FILE')) {
97 define('ILIAS_LOG_FILE', '/var/log/ilias.log');
98 }
99 }
100}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
Unit tests for tree table.
Definition: ilRBACTest.php:30
initACDependencies()
Definition: ilRBACTest.php:64
Container $dic
Definition: ilRBACTest.php:33
setGlobalVariable(string $name, $value)
Definition: ilRBACTest.php:53
Class ilRbacAdmin Core functions for role based access control.
class ilRbacReview Contains Review functions of core Rbac.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
$c
Definition: deliver.php:25
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54