ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
ilRepositoryTreeTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23
24class ilRepositoryTreeTest extends TestCase
25{
26 protected Container $dic;
27
28 protected function setUp(): void
29 {
31 parent::setUp();
32 if (!defined("ROOT_FOLDER_ID")) {
33 define("ROOT_FOLDER_ID", 8);
34 }
35 if (!defined("ILIAS_LOG_ENABLED")) {
36 define("ILIAS_LOG_ENABLED", false);
37 }
38 if (!defined("ILIAS_LOG_DIR")) {
39 define("ILIAS_LOG_DIR", '/var/log');
40 }
41 if (!defined("ILIAS_LOG_FILE")) {
42 define("ILIAS_LOG_FILE", '/var/log/ilias.log');
43 }
44 }
45
46 public function testTreeConstruct(): void
47 {
48 $tree = new ilTree(1);
49 $this->assertTrue($tree instanceof ilTree);
50 }
51
52 public function testInitLanguage(): void
53 {
54 // no global user available
55 $tree = new ilTree(1);
56 $tree->initLangCode();
57 $tree_reflection = new ReflectionProperty($tree, 'lang_code');
58 $this->assertEquals('en', $tree_reflection->getValue($tree));
59
60 // user getCurrentLanguage() from session is empty
61 $tree = new ilTree(1);
62
63 $user = $this->getMockBuilder(ilObjUser::class)
64 ->disableOriginalConstructor()
65 ->onlyMethods(['getCurrentLanguage'])
66 ->getMock();
67 $user->method('getCurrentLanguage')->willReturn('');
68 $this->setGlobalVariable('ilUser', $user);
69 $tree->initLangCode();
70 $tree_reflection = new ReflectionProperty($tree, 'lang_code');
71 $this->assertEquals('en', $tree_reflection->getValue($tree));
72 }
73
78 protected function setGlobalVariable(string $name, $value): void
79 {
80 global $DIC;
81
82 $GLOBALS[$name] = $value;
83 unset($DIC[$name]);
84 $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
85 return $value;
86 };
87 }
88
89 protected function initRepositoryTreeDependencies(): void
90 {
91 $this->dic = new Container();
92 $GLOBALS['DIC'] = $this->dic;
93
94 $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
95 $this->setGlobalVariable('ilAppEventHandler', $this->createMock(ilAppEventHandler::class));
96
97 $logger = $this->getMockBuilder(ilLogger::class)
98 ->disableOriginalConstructor()
99 ->getMock();
100
101 $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
102 ->disableOriginalConstructor()
103 ->onlyMethods(['getComponentLogger'])
104 ->getMock();
105 $logger_factory->method('getComponentLogger')->willReturn($logger);
106 $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
107 }
108}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:36
setGlobalVariable(string $name, $value)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
$c
Definition: deliver.php:25
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54