ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ShowOnLoginPageTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 use ilTemplate;
30 
31 require_once __DIR__ . '/../../ContainerMock.php';
32 
33 class ShowOnLoginPageTest extends TestCase
34 {
35  use ContainerMock;
36 
37  public function testConstruct(): void
38  {
39  $this->assertInstanceOf(ShowOnLoginPage::class, new ShowOnLoginPage($this->mock(Provide::class), $this->mock(UI::class), $this->fail(...)));
40  }
41 
42  public function testInvokeWithoutDocuments(): void
43  {
44  $instance = new ShowOnLoginPage($this->mockTree(Provide::class, [
45  'document' => ['repository' => ['countAll' => 0]],
46  ]), $this->mock(UI::class), $this->fail(...));
47 
48  $this->assertSame([], $instance());
49  }
50 
51  public function testInvoke(): void
52  {
53  $translated = 'Translated<br/>';
54  $url = 'Dummy URL';
55 
56  $legacy = $this->mock(Legacy\Content::class);
57  $legacy_factory = $this->mock(Legacy\Factory::class);
58  $legacy_factory
59  ->expects($this->once())
60  ->method('content')
61  ->willReturn($legacy);
62 
63 
64  $template = $this->mock(ilTemplate::class);
65  $expected = [
66  ['LABEL', htmlentities($translated)],
67  ['HREF', $url]
68  ];
69  $template
70  ->expects(self::exactly(2))
71  ->method('setVariable')
72  ->willReturnCallback(
73  function (string $k, string $v) use (&$expected) {
74  [$ek, $ev] = array_shift($expected);
75  $this->assertEquals($ek, $k);
76  $this->assertEquals($ev, $v);
77  }
78  );
79 
80  $template->expects(self::once())->method('get')->willReturn('Rendered');
81 
82  $instance = new ShowOnLoginPage($this->mockTree(Provide::class, [
83  'document' => ['repository' => ['countAll' => 1]],
84  'publicPage' => ['url' => $url],
85  ]), $this->mockTree(UI::class, [
86  'txt' => $translated,
87  'create' => $this->mockMethod(UIFactory::class, 'legacy', [], $legacy_factory),
88  ]), fn() => $template);
89 
90  $array = $instance();
91 
92  $this->assertSame(1, count($array));
93  $this->assertSame($legacy, $array[0]);
94  }
95 }
$url
Definition: shib_logout.php:66