ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
MailPageTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23require_once('vendor/composer/vendor/autoload.php');
24require_once(__DIR__ . '/../../../Base.php');
25
28use ILIAS\Data\Link as DataLink;
32use NoUIFactory;
33use PHPUnit\Framework\Attributes\DataProvider;
34
36{
39 protected string $logo;
40 protected string $installation_title;
41 protected string $stylesheet_path;
42 protected URI $uri;
44 protected DataLink $footer_url;
45
46 public function setUp(): void
47 {
48 $this->html_content = $this->createMock(Content::class);
49 $this->html_content->method('getContent')->willReturn('ILIAS HTML Content');
50
51 $this->logo = 'cid:ILIAS Logo';
52 $this->installation_title = 'ILIAS Installation Title';
53 $this->stylesheet_path = __FILE__;
54 $this->uri = $this->createMock(URI::class);
55 $this->uri->method('getBaseURI')->willReturn('ILIAS Link URI');
56 $this->footer_url = $this->createMock(DataLink::class);
57 $this->footer_url->method('getLabel')->willReturn('ILIAS Link Label');
58 $this->footer_url->method('getURL')->willReturn($this->uri);
59
60 $this->factory = new Page\Factory();
61 $this->mailpage = $this->factory->mail(
62 $this->stylesheet_path,
63 $this->logo,
64 $this->installation_title,
65 $this->html_content,
66 $this->footer_url,
67 );
68 }
69
70 public function testConstruction(): void
71 {
72 static::assertInstanceOf(
73 Page\Mail::class,
74 $this->mailpage,
75 );
76 }
77
78 public static function provideGetData(): array
79 {
80 return [
81 ['html_content', 'getContent', 'assertContains'],
82 ['logo', 'getLogoURL', 'assertEquals'],
83 ['installation_title', 'getInstallationTitle', 'assertEquals'],
84 ['stylesheet_path', 'getStyleSheetPath', 'assertEquals'],
85 ['footer_url', 'getFooterURL', 'assertEquals'],
86 ];
87 }
88
89 #[DataProvider('provideGetData')]
90 public function testGet(mixed $expected, string $method_to_call, string $assert_method): void
91 {
92 static::$assert_method(
93 $this->$expected,
94 $this->mailpage->$method_to_call(),
95 );
96 }
97
98 public function testRenderMailPage(): void
99 {
100 $renderer = $this->getDefaultRenderer(null, [$this->html_content]);
101 $mailpage = $this->factory->mail(
102 $this->stylesheet_path,
103 $this->logo,
104 $this->installation_title,
105 $this->html_content,
106 $this->footer_url,
107 );
108
109 $html = $this->brutallyTrimHTML($renderer->render($mailpage));
110 $expected = $this->brutallyTrimHTML('
111<body>
112<table class="table">
113 <tr class="header">
114 <td class="spacing">
115 <table class="w-750 center">
116 <tr class="rowheight"></tr>
117 <tr>
118 <td class="image-data">
119 <img class="logo" src="' . $this->logo . '" alt="Logo">
120 </td>
121 <td class="installation-text">
122 <span>
123 <strong>' . $this->installation_title . '</strong>
124 </span>
125 </td>
126 </tr>
127 <tr class="rowheight"></tr>
128 </table>
129 </td>
130 </tr>
131 <tr class="content">
132 <td class="spacing">
133 <table class="w-750 center">
134 <tr class="headerheight"></tr>
135 <tr>
136 <td class="font-definition">
137 ' . $renderer->render($this->html_content) . '
138 </td>
139 </tr>
140 <tr class="headerheight"></tr>
141 </table>
142 </td>
143 </tr>
144 <tr class="footer">
145 <td class="spacing">
146 <table class="w-750 center">
147 <tr>
148 <td class="font-definition">
149 <span>' . $this->installation_title . '</span>
150 <br>
151 <a href="ILIAS Link URI">ILIAS Link Label</a>
152 </td>
153 </tr>
154 </table>
155 </td>
156 </tr>
157</table>
158</body>');
159
160 static::assertStringContainsString($expected, $html);
161 }
162
163 public function getUIFactory(): NoUIFactory
164 {
165 return new class () extends NoUIFactory {
166 public function link(): Link\Factory
167 {
168 return new Link\Factory();
169 }
170 };
171 }
172}
factory()
$renderer
testGet(mixed $expected, string $method_to_call, string $assert_method)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
The scope of this class is split ilias-conform URI's into components.
Definition: URI.php:35
Provides common functionality for UI tests.
Definition: Base.php:337
This describes the Mail.
Definition: Mail.php:27
This describes the Page.
Definition: Page.php:31
link(string $caption, string $href, bool $new_viewport=false)