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