ILIAS  release_8 Revision v8.24
ilRepositoryTreeTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
5use PHPUnit\Framework\TestCase;
7
8class ilRepositoryTreeTest extends TestCase
9{
10 protected Container $dic;
11
12 protected function setUp(): void
13 {
15 parent::setUp();
16 }
17
18 public function testTreeConstruct(): void
19 {
20 $tree = new ilTree(1);
21 $this->assertTrue($tree instanceof ilTree);
22 }
23
24 public function testInitLanguage(): void
25 {
26
27 // no global user available
28 $tree = new ilTree(1);
29 $tree->initLangCode();
30 $tree_reflection = new ReflectionProperty($tree, 'lang_code');
31 $tree_reflection->setAccessible(true);
32 $this->assertEquals('en', $tree_reflection->getValue($tree));
33
34 // user getCurrentLanguage() from session is empty
35 $tree = new ilTree(1);
36
37 $user = $this->getMockBuilder(ilObjUser::class)
38 ->disableOriginalConstructor()
39 ->onlyMethods(['getCurrentLanguage'])
40 ->getMock();
41 $user->method('getCurrentLanguage')->willReturn('');
42 $this->setGlobalVariable('ilUser', $user);
43 $tree->initLangCode();
44 $tree_reflection = new ReflectionProperty($tree, 'lang_code');
45 $tree_reflection->setAccessible(true);
46 $this->assertEquals('en', $tree_reflection->getValue($tree));
47 }
48
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 initRepositoryTreeDependencies(): void
65 {
66 $this->dic = new Container();
67 $GLOBALS['DIC'] = $this->dic;
68
69 $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
70 $this->setGlobalVariable('ilAppEventHandler', $this->createMock(ilAppEventHandler::class));
71
72 $logger = $this->getMockBuilder(ilLogger::class)
73 ->disableOriginalConstructor()
74 ->getMock();
75
76 $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
77 ->disableOriginalConstructor()
78 ->onlyMethods(['getComponentLogger'])
79 ->getMock();
80 $logger_factory->method('getComponentLogger')->willReturn($logger);
81 $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
82 }
83}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
setGlobalVariable(string $name, $value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$c
Definition: cli.php:38
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247