ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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  $language->expects(self::exactly(2))->method('exists')->withConsecutive(['bar_foo'], ['ldoc_foo'])->willReturnOnConsecutiveCalls(false, true);
58 
59  $instance = new UI('bar', $this->mock(UIServices::class), $language);
60  $this->assertSame('baz', $instance->txt('foo'));
61  }
62 
63  public function testTxtFallback(): void
64  {
65  $language = $this->mockMethod(ilLanguage::class, 'txt', ['foo'], 'baz');
66  $language->expects(self::exactly(2))->method('exists')->withConsecutive(['bar_foo'], ['ldoc_foo'])->willReturn(false);
67 
68  $instance = new UI('bar', $this->mock(UIServices::class), $language);
69  $this->assertSame('baz', $instance->txt('foo'));
70  }
71 }