ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilRepositoryTreeTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
7 
8 class 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  // no global user available
27  $tree = new ilTree(1);
28  $tree->initLangCode();
29  $tree_reflection = new ReflectionProperty($tree, 'lang_code');
30  $tree_reflection->setAccessible(true);
31  $this->assertEquals('en', $tree_reflection->getValue($tree));
32 
33  // user getCurrentLanguage() from session is empty
34  $tree = new ilTree(1);
35 
36  $user = $this->getMockBuilder(ilObjUser::class)
37  ->disableOriginalConstructor()
38  ->onlyMethods(['getCurrentLanguage'])
39  ->getMock();
40  $user->method('getCurrentLanguage')->willReturn('');
41  $this->setGlobalVariable('ilUser', $user);
42  $tree->initLangCode();
43  $tree_reflection = new ReflectionProperty($tree, 'lang_code');
44  $tree_reflection->setAccessible(true);
45  $this->assertEquals('en', $tree_reflection->getValue($tree));
46  }
47 
52  protected function setGlobalVariable(string $name, $value): void
53  {
54  global $DIC;
55 
56  $GLOBALS[$name] = $value;
57  unset($DIC[$name]);
58  $DIC[$name] = static function (\ILIAS\DI\Container $c) use ($value) {
59  return $value;
60  };
61  }
62 
63  protected function initRepositoryTreeDependencies(): void
64  {
65  $this->dic = new Container();
66  $GLOBALS['DIC'] = $this->dic;
67 
68  $this->setGlobalVariable('ilDB', $this->createMock(ilDBInterface::class));
69  $this->setGlobalVariable('ilAppEventHandler', $this->createMock(ilAppEventHandler::class));
70 
71  $logger = $this->getMockBuilder(ilLogger::class)
72  ->disableOriginalConstructor()
73  ->getMock();
74 
75  $logger_factory = $this->getMockBuilder(ilLoggerFactory::class)
76  ->disableOriginalConstructor()
77  ->onlyMethods(['getComponentLogger'])
78  ->getMock();
79  $logger_factory->method('getComponentLogger')->willReturn($logger);
80  $this->setGlobalVariable('ilLoggerFactory', $logger_factory);
81  }
82 }
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:35
global $DIC
Definition: feed.php:28
$GLOBALS["DIC"]
Definition: wac.php:31
setGlobalVariable(string $name, $value)