‪TYPO3CMS  10.4
FlashMessagesViewHelperTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
21 use TYPO3\TestingFramework\Fluid\Unit\ViewHelpers\ViewHelperBaseTestcase;
22 
26 class ‪FlashMessagesViewHelperTest extends ViewHelperBaseTestcase
27 {
31  protected ‪$viewHelper;
32 
36  protected ‪$flashMessageQueue;
37 
41  protected function ‪setUp(): void
42  {
43  parent::setUp();
44  $this->flashMessageQueue = $this->prophesize(FlashMessageQueue::class);
45  $this->controllerContext->expects(self::any())->method('getFlashMessageQueue')->willReturn($this->flashMessageQueue->reveal());
46 
47  $this->viewHelper = new ‪FlashMessagesViewHelper();
48  $this->injectDependenciesIntoViewHelper($this->viewHelper);
49  }
50 
55  {
56  $this->setArgumentsUnderTest(
57  $this->viewHelper,
58  [
59  'as' => null
60  ]
61  );
62  $this->flashMessageQueue->getAllMessagesAndFlush()->willReturn();
63  self::assertEmpty($this->viewHelper->initializeArgumentsAndRender());
64  }
65 
69  public function ‪fetchMessagesFromSpecificQueue()
70  {
71  $queueIdentifier = 'myQueue';
72 
73  $this->flashMessageQueue->getAllMessagesAndFlush()->willReturn();
74  $this->controllerContext->expects(self::once())->method('getFlashMessageQueue')->with($queueIdentifier)->willReturn($this->flashMessageQueue->reveal());
75 
76  $this->setArgumentsUnderTest(
77  $this->viewHelper,
78  [
79  'queueIdentifier' => $queueIdentifier
80  ]
81  );
82 
83  self::assertEmpty($this->viewHelper->initializeArgumentsAndRender());
84  }
85 
90  {
91  $this->viewHelper->setRenderChildrenClosure(function () {
92  return 'a simple String';
93  });
94 
95  $flashMessage = new ‪FlashMessage('test message body', 'test message title');
96 
97  $this->flashMessageQueue->getAllMessagesAndFlush()->willReturn([$flashMessage]);
98  $this->setArgumentsUnderTest(
99  $this->viewHelper,
100  [
101  'as' => 'flashy',
102  ]
103  );
104  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
105 
106  self::assertEquals('a simple String', $actualResult);
107  }
108 }
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\FlashMessagesViewHelperTest\$flashMessageQueue
‪FlashMessageQueue $flashMessageQueue
Definition: FlashMessagesViewHelperTest.php:34
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\FlashMessagesViewHelperTest\$viewHelper
‪TYPO3 CMS Fluid ViewHelpers FlashMessagesViewHelper $viewHelper
Definition: FlashMessagesViewHelperTest.php:30
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\FlashMessagesViewHelperTest\renderReturnsEmptyStringIfNoFlashMessagesAreInQueue
‪renderReturnsEmptyStringIfNoFlashMessagesAreInQueue()
Definition: FlashMessagesViewHelperTest.php:52
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\FlashMessagesViewHelperTest\setUp
‪setUp()
Definition: FlashMessagesViewHelperTest.php:39
‪TYPO3\CMS\Fluid\ViewHelpers\FlashMessagesViewHelper
Definition: FlashMessagesViewHelper.php:96
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\FlashMessagesViewHelperTest\fetchMessagesFromSpecificQueue
‪fetchMessagesFromSpecificQueue()
Definition: FlashMessagesViewHelperTest.php:67
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\FlashMessagesViewHelperTest
Definition: FlashMessagesViewHelperTest.php:27
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers
‪TYPO3\CMS\Fluid\Tests\Unit\ViewHelpers\FlashMessagesViewHelperTest\parameterAsStartsRenderingOnTemplate
‪parameterAsStartsRenderingOnTemplate()
Definition: FlashMessagesViewHelperTest.php:87
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:29