ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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  $legacy = $this->mock(Legacy::class);
56 
57  $template = $this->mock(ilTemplate::class);
58  $expected = [
59  ['LABEL', htmlentities($translated)],
60  ['HREF', $url]
61  ];
62  $template
63  ->expects(self::exactly(2))
64  ->method('setVariable')
65  ->willReturnCallback(
66  function (string $k, string $v) use (&$expected) {
67  [$ek, $ev] = array_shift($expected);
68  $this->assertEquals($ek, $k);
69  $this->assertEquals($ev, $v);
70  }
71  );
72 
73  $template->expects(self::once())->method('get')->willReturn('Rendered');
74 
75  $instance = new ShowOnLoginPage($this->mockTree(Provide::class, [
76  'document' => ['repository' => ['countAll' => 1]],
77  'publicPage' => ['url' => $url],
78  ]), $this->mockTree(UI::class, [
79  'txt' => $translated,
80  'create' => $this->mockMethod(UIFactory::class, 'legacy', ['Rendered'], $legacy),
81  ]), fn() => $template);
82 
83  $array = $instance();
84 
85  $this->assertSame(1, count($array));
86  $this->assertSame($legacy, $array[0]);
87  }
88 }
$url
Definition: shib_logout.php:63