‪TYPO3CMS  ‪main
BootstrapRendererTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
20 use PHPUnit\Framework\Attributes\Test;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪BootstrapRendererTest extends UnitTestCase
30 {
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34 
35  $iconMock = $this->createMock(Icon::class);
36  $iconMock->method('render')->willReturn('');
37 
38  $iconFactoryMock = $this->createMock(IconFactory::class);
39  $iconFactoryMock->method('getIcon')->with(self::anything())->willReturn($iconMock);
40  GeneralUtility::addInstance(IconFactory::class, $iconFactoryMock);
41  }
42 
43  protected function ‪tearDown(): void
44  {
45  GeneralUtility::purgeInstances();
46  parent::tearDown();
47  }
48 
49  #[Test]
51  {
52  $rendererClass = GeneralUtility::makeInstance(BootstrapRenderer::class);
53  $flashMessage = GeneralUtility::makeInstance(
54  FlashMessage::class,
55  'messageBody',
56  'messageTitle',
57  ContextualFeedbackSeverity::NOTICE
58  );
59  ‪$output = $rendererClass->render([$flashMessage]);
60  self::assertStringContainsString('<div class="typo3-messages">', ‪$output);
61  self::assertStringContainsString('<div class="alert alert-notice">', ‪$output);
62  self::assertStringContainsString('<div class="media-body">', ‪$output);
63  self::assertStringContainsString('<h4 class="alert-title">messageTitle</h4>', ‪$output);
64  self::assertStringContainsString('<p class="alert-message">messageBody</p>', ‪$output);
65  }
66 
67  #[Test]
69  {
70  $rendererClass = GeneralUtility::makeInstance(BootstrapRenderer::class);
71  $flashMessage = GeneralUtility::makeInstance(
72  FlashMessage::class,
73  'messageBody',
74  '',
75  ContextualFeedbackSeverity::NOTICE
76  );
77  ‪$output = $rendererClass->render([$flashMessage]);
78  self::assertStringContainsString('<div class="typo3-messages">', ‪$output);
79  self::assertStringContainsString('<div class="alert alert-notice">', ‪$output);
80  self::assertStringContainsString('<div class="media-body">', ‪$output);
81  self::assertStringContainsString('<p class="alert-message">messageBody</p>', ‪$output);
82  self::assertStringNotContainsString('<h4 class="alert-title">messageTitle</h4>', ‪$output);
83  }
84 }
‪TYPO3\CMS\Core\Imaging\Icon
Definition: Icon.php:27
‪TYPO3\CMS\Core\Tests\Unit\Messaging\Renderer
Definition: BootstrapRendererTest.php:18
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:34
‪TYPO3\CMS\Core\Tests\Unit\Messaging\Renderer\BootstrapRendererTest
Definition: BootstrapRendererTest.php:30
‪TYPO3\CMS\Core\Type\ContextualFeedbackSeverity
‪ContextualFeedbackSeverity
Definition: ContextualFeedbackSeverity.php:25
‪TYPO3\CMS\Core\Tests\Unit\Messaging\Renderer\BootstrapRendererTest\renderCreatesCorrectOutputForFlashMessage
‪renderCreatesCorrectOutputForFlashMessage()
Definition: BootstrapRendererTest.php:50
‪TYPO3\CMS\Core\Tests\Unit\Messaging\Renderer\BootstrapRendererTest\renderCreatesCorrectOutputForFlashMessageWithoutTitle
‪renderCreatesCorrectOutputForFlashMessageWithoutTitle()
Definition: BootstrapRendererTest.php:68
‪TYPO3\CMS\Core\Messaging\Renderer\BootstrapRenderer
Definition: BootstrapRenderer.php:33
‪$output
‪$output
Definition: annotationChecker.php:114
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Tests\Unit\Messaging\Renderer\BootstrapRendererTest\tearDown
‪tearDown()
Definition: BootstrapRendererTest.php:43
‪TYPO3\CMS\Core\Tests\Unit\Messaging\Renderer\BootstrapRendererTest\setUp
‪setUp()
Definition: BootstrapRendererTest.php:31