ILIAS  trunk Revision v13.0_alpha-52-g21c366bbdd4
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();
39 }
40
41 public function testConstruct(): void
42 {
43 $system = ilRbacSystem::getInstance();
44 $this->assertTrue($system instanceof ilRbacSystem);
45
46 $db = $this->dic['ilDB'];
47 $logger = $this->createStub(\ILIAS\Logging\Logger\LoggerInterface::class);
48 $review = new ilRbacReview($db, $logger);
49 $this->assertTrue($review instanceof ilRbacReview);
50
51 $admin = new ilRbacAdmin($db, $review, $logger);
52 $this->assertTrue($admin instanceof ilRbacAdmin);
53 }
54
55 protected function setGlobalVariable(string $name, $value): void
56 {
57 global $DIC;
58
59 $GLOBALS[$name] = $value;
60 unset($DIC[$name]);
61 $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
62 return $value;
63 };
64 }
65
66 protected function initACDependencies(): void
67 {
68 $this->dic = new Container();
69 $GLOBALS['DIC'] = $this->dic;
70
71 $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
72 $this->setGlobalVariable('ilUser', $this->createMock(ilObjUser::class));
73 $this->setGlobalVariable('rbacreview', $this->createMock(ilRbacReview::class));
74 $this->setGlobalVariable('rbacsystem', $this->createMock(ilRbacSystem::class));
75 $this->setGlobalVariable('ilObjDataCache', $this->createMock(ilObjectDataCache::class));
76 $this->setGlobalVariable('tree', $this->createMock(ilTree::class));
77 $this->setGlobalVariable('http', $this->createMock(\ILIAS\HTTP\Services::class));
78 $this->setGlobalVariable('refinery', $this->createMock(\ILIAS\Refinery\Factory::class));
79
80 $logger = $this->getMockBuilder(ilLogger::class)
81 ->disableOriginalConstructor()
82 ->getMock();
83
84 $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
85 ->disableOriginalConstructor()
86 ->onlyMethods(['getComponentLogger'])
87 ->getMock();
88 $logger_factory->method('getComponentLogger')->willReturn($logger);
89 $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
90
91 if (!defined('ILIAS_LOG_ENABLED')) {
92 define('ILIAS_LOG_ENABLED', true);
93 }
94
95 if (!defined('ILIAS_LOG_DIR')) {
96 define('ILIAS_LOG_DIR', '/var/log');
97 }
98
99 if (!defined('ILIAS_LOG_FILE')) {
100 define('ILIAS_LOG_FILE', '/var/log/ilias.log');
101 }
102 }
103}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:38
Unit tests for tree table.
Definition: ilRBACTest.php:30
initACDependencies()
Definition: ilRBACTest.php:66
Container $dic
Definition: ilRBACTest.php:33
setGlobalVariable(string $name, $value)
Definition: ilRBACTest.php:55
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...
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:66