ILIAS  trunk Revision v11.0_alpha-1749-g1a06bdef097
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
UITest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 use ilLanguage;
30 
31 require_once __DIR__ . '/../ContainerMock.php';
32 
33 class UITest extends TestCase
34 {
35  use ContainerMock;
36 
37  public function testConstruct(): void
38  {
39  $this->assertInstanceOf(UI::class, new UI('foo', $this->mock(UIServices::class), $this->mock(ilLanguage::class)));
40  }
41 
42  public function testCreate(): void
43  {
44  $ui_factory = $this->mock(UIFactory::class);
45  $this->assertSame($ui_factory, (new UI('foo', $this->mockTree(UIServices::class, ['factory' => $ui_factory]), $this->mock(ilLanguage::class)))->create());
46  }
47 
48  public function testMainTemplate(): void
49  {
50  $template = $this->mock(ilGlobalTemplateInterface::class);
51  $this->assertSame($template, (new UI('foo', $this->mockTree(UIServices::class, ['mainTemplate' => $template]), $this->mock(ilLanguage::class)))->mainTemplate());
52  }
53 
54  public function testTxt(): void
55  {
56  $language = $this->mockMethod(ilLanguage::class, 'txt', ['ldoc_foo'], 'baz');
57  $consecutive = [
58  ['bar_foo', false],
59  ['ldoc_foo', true]
60  ];
61  $language
62  ->expects(self::exactly(2))
63  ->method('exists')
64  ->willReturnCallback(
65  function (string $txt) use (&$consecutive) {
66  [$expected, $return] = array_shift($consecutive);
67  $this->assertEquals($expected, $txt);
68  return $return;
69  }
70  );
71  $instance = new UI('bar', $this->mock(UIServices::class), $language);
72  $this->assertSame('baz', $instance->txt('foo'));
73  }
74 
75  public function testTxtFallback(): void
76  {
77  $consecutive = ['bar_foo', 'ldoc_foo'];
78  $language = $this->mockMethod(ilLanguage::class, 'txt', ['foo'], 'baz');
79  $language
80  ->expects(self::exactly(2))
81  ->method('exists')
82  ->willReturnCallback(
83  function (string $txt) use (&$consecutive) {
84  $this->assertEquals(array_shift($consecutive), $txt);
85  return false;
86  }
87  );
88 
89  $instance = new UI('bar', $this->mock(UIServices::class), $language);
90  $this->assertSame('baz', $instance->txt('foo'));
91  }
92 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$txt
Definition: error.php:31
mainTemplate()