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