ILIAS  release_8 Revision v8.24
ilMailErrorFormatterTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22{
24
25 protected function setUp(): void
26 {
27 parent::setUp();
28
29 $componentFactory = $this->getMockBuilder(ilComponentFactory::class)->getMock();
30
31 $this->setGlobalVariable('component.factory', $componentFactory);
32
33 $languageMock = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
34 $languageMock->method('txt')->willReturnCallback(static function (string $key): string {
35 if ('error1' === $key) {
36 return '-' . $key . '-';
37 }
38
39 if ('error3' === $key) {
40 return $key . ' (1. %s/2. %s/3. %s)';
41 }
42
43 return $key;
44 });
45
46 $this->errorFormatter = new ilMailErrorFormatter($languageMock);
47 }
48
49 public function errorCollectionProvider(): array
50 {
51 return [
52 'Zero errors' => [
53 [],
54 ''
55 ],
56 'Exactly one error' => [
57 [new ilMailError('error1')],
58 'error1'
59 ],
60 'Two errors' => [
61 [new ilMailError('error1'), new ilMailError('error2')],
62 'error1<ul><li>error2</li></ul>'
63 ],
64 'More than two errors with placeholders' => [
65 [new ilMailError('error1'), new ilMailError('error2'), new ilMailError('error3', ['a', 'b', 'c'])],
66 'error1<ul><li>error2</li><li>error3 (1. a/2. b/3. c)</li></ul>'
67 ],
68 ];
69 }
70
77 public function testErrorFormatter(array $errors, string $expectedHtml): void
78 {
79 $this->assertSame($expectedHtml, $this->brutallyTrimHTML($this->errorFormatter->format($errors)));
80 }
81}
Class ilMailBaseTest.
brutallyTrimHTML(string $html)
setGlobalVariable(string $name, $value)
ilMailErrorFormatter $errorFormatter
testErrorFormatter(array $errors, string $expectedHtml)
@dataProvider errorCollectionProvider
Class ilMailErrorFormatter.
Class ilMailError.
$errors
Definition: imgupload.php:65
string $key
Consumer key/client ID value.
Definition: System.php:193