ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
UITest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\LegalDocuments\test\ContainerMock;
25use ILIAS\UI\Factory as UIFactory;
26use PHPUnit\Framework\TestCase;
29use ilLanguage;
30
31require_once __DIR__ . '/../ContainerMock.php';
32
33class 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}
mainTemplate()
Provides fluid interface to RBAC services.
Definition: UIServices.php:25
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
language handling
$txt
Definition: error.php:31