ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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 $tree_reflection->setAccessible(true);
59 $this->assertEquals('en', $tree_reflection->getValue($tree));
60
61 // user getCurrentLanguage() from session is empty
62 $tree = new ilTree(1);
63
64 $user = $this->getMockBuilder(ilObjUser::class)
65 ->disableOriginalConstructor()
66 ->onlyMethods(['getCurrentLanguage'])
67 ->getMock();
68 $user->method('getCurrentLanguage')->willReturn('');
69 $this->setGlobalVariable('ilUser', $user);
70 $tree->initLangCode();
71 $tree_reflection = new ReflectionProperty($tree, 'lang_code');
72 $tree_reflection->setAccessible(true);
73 $this->assertEquals('en', $tree_reflection->getValue($tree));
74 }
75
80 protected function setGlobalVariable(string $name, $value): void
81 {
82 global $DIC;
83
84 $GLOBALS[$name] = $value;
85 unset($DIC[$name]);
86 $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
87 return $value;
88 };
89 }
90
91 protected function initRepositoryTreeDependencies(): void
92 {
93 $this->dic = new Container();
94 $GLOBALS['DIC'] = $this->dic;
95
96 $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
97 $this->setGlobalVariable('ilAppEventHandler', $this->createMock(ilAppEventHandler::class));
98
99 $logger = $this->getMockBuilder(ilLogger::class)
100 ->disableOriginalConstructor()
101 ->getMock();
102
103 $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
104 ->disableOriginalConstructor()
105 ->onlyMethods(['getComponentLogger'])
106 ->getMock();
107 $logger_factory->method('getComponentLogger')->willReturn($logger);
108 $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
109 }
110}
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