TYPO3 CMS  TYPO3_8-7
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 
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->flashMessageQueue->getAllMessagesAndFlush()->willReturn();
56  $this->assertEmpty($this->viewHelper->initializeArgumentsAndRender());
57  }
58 
63  {
64  $queueIdentifier = 'myQueue';
65 
66  $this->flashMessageQueue->getAllMessagesAndFlush()->willReturn();
67  $this->controllerContext->expects($this->once())->method('getFlashMessageQueue')->with($queueIdentifier)->will($this->returnValue($this->flashMessageQueue->reveal()));
68 
69  $this->setArgumentsUnderTest(
70  $this->viewHelper,
71  [
72  'queueIdentifier' => $queueIdentifier
73  ]
74  );
75 
76  $this->assertEmpty($this->viewHelper->initializeArgumentsAndRender());
77  }
78 
83  {
84  $this->viewHelper->setRenderChildrenClosure(function () {
85  return 'a simple String';
86  });
87 
88  $flashMessage = new FlashMessage('test message body', 'test message title');
89 
90  $this->flashMessageQueue->getAllMessagesAndFlush()->willReturn([$flashMessage]);
91  $this->setArgumentsUnderTest(
92  $this->viewHelper,
93  [
94  'as' => 'flashy',
95  ]
96  );
97  $actualResult = $this->viewHelper->initializeArgumentsAndRender();
98 
99  $this->assertEquals('a simple String', $actualResult);
100  }
101 }