‪TYPO3CMS  9.5
FlashMessageQueueTest.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 
19 
23 class ‪FlashMessageQueueTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
24 {
29  {
30  $this->setUpBackendUserFromFixture(1);
31  $flashMessage = new ‪FlashMessage('Foo', 'Bar', ‪FlashMessage::OK, true);
32  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
33  $flashMessageQueue->addMessage($flashMessage);
34  $this->assertEquals([$flashMessage], $flashMessageQueue->getAllMessages());
35  }
36 
41  {
42  $this->setUpBackendUserFromFixture(1);
43  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
44  $messages = [
45  0 => new ‪FlashMessage('This is a test message', '1', ‪FlashMessage::NOTICE),
46  1 => new ‪FlashMessage('This is another test message', '2', ‪FlashMessage::WARNING)
47  ];
48  $flashMessageQueue->enqueue($messages[0]);
49  $flashMessageQueue->enqueue($messages[1]);
50 
51  $filteredFlashMessages = $flashMessageQueue->getAllMessages(‪FlashMessage::NOTICE);
52 
53  $this->assertEquals(count($filteredFlashMessages), 1);
54 
55  reset($filteredFlashMessages);
56  $flashMessage = current($filteredFlashMessages);
57  $this->assertEquals($messages[0], $flashMessage);
58  }
59 
64  {
65  $this->setUpBackendUserFromFixture(1);
66  $flashMessage = new ‪FlashMessage('Foo', 'Bar', ‪FlashMessage::OK, true);
67  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
68  $flashMessageQueue->addMessage($flashMessage);
69  $this->assertEquals([$flashMessage], $flashMessageQueue->getAllMessagesAndFlush());
70  }
71 
76  {
77  $this->setUpBackendUserFromFixture(1);
78  $flashMessage = new ‪FlashMessage('Foo', 'Bar', ‪FlashMessage::OK, true);
79  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
80  $flashMessageQueue->addMessage($flashMessage);
81  $flashMessageQueue->getAllMessagesAndFlush();
82  $this->assertEquals([], $flashMessageQueue->getAllMessagesAndFlush());
83  }
84 
89  {
90  $this->setUpBackendUserFromFixture(1);
91  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
92  $messages = [
93  0 => new ‪FlashMessage('This is a test message', '1', ‪FlashMessage::NOTICE),
94  1 => new ‪FlashMessage('This is another test message', '2', ‪FlashMessage::WARNING)
95  ];
96  $flashMessageQueue->addMessage($messages[0]);
97  $flashMessageQueue->addMessage($messages[1]);
98 
99  $filteredFlashMessages = $flashMessageQueue->getAllMessagesAndFlush(‪FlashMessage::NOTICE);
100 
101  $this->assertEquals(count($filteredFlashMessages), 1);
102 
103  reset($filteredFlashMessages);
104  $flashMessage = current($filteredFlashMessages);
105  $this->assertEquals($messages[0], $flashMessage);
106 
107  $this->assertEquals([], $flashMessageQueue->getAllMessages(‪FlashMessage::NOTICE));
108  $this->assertEquals([$messages[1]], array_values($flashMessageQueue->getAllMessages()));
109  }
110 
115  {
116  $this->setUpBackendUserFromFixture(1);
117  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
118  $flashMessage1 = new ‪FlashMessage('Transient', 'Title', ‪FlashMessage::OK, false);
119  $flashMessage2 = new ‪FlashMessage('Session', 'Title', ‪FlashMessage::OK, true);
120  $flashMessageQueue->addMessage($flashMessage1);
121  $flashMessageQueue->addMessage($flashMessage2);
122 
123  $this->assertCount(2, $flashMessageQueue->getAllMessages());
124  }
125 
129  public function ‪clearClearsTheQueue()
130  {
131  $this->setUpBackendUserFromFixture(1);
132  $flashMessage = new ‪FlashMessage('Foo', 'Bar', ‪FlashMessage::OK, true);
133  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
134  $flashMessageQueue->addMessage($flashMessage);
135  $flashMessageQueue->clear();
136  $this->assertCount(0, $flashMessageQueue);
137  }
138 
143  {
144  $this->setUpBackendUserFromFixture(1);
145  $flashMessageQueue = new ‪FlashMessageQueue('core.template.flashMessages');
146  $flashMessage1 = new ‪FlashMessage('Transient', 'Title', ‪FlashMessage::OK, false);
147  $flashMessage2 = new ‪FlashMessage('Session', 'Title', ‪FlashMessage::OK, true);
148  $flashMessageQueue->addMessage($flashMessage1);
149  $flashMessageQueue->addMessage($flashMessage2);
150 
151  $this->assertCount(1, $flashMessageQueue);
152  }
153 }
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\getAllMessagesContainsEnqueuedMessage
‪getAllMessagesContainsEnqueuedMessage()
Definition: FlashMessageQueueTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\toArrayOnlyRespectsTransientFlashMessages
‪toArrayOnlyRespectsTransientFlashMessages()
Definition: FlashMessageQueueTest.php:142
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\getAllMessagesAndFlushClearsSessionStack
‪getAllMessagesAndFlushClearsSessionStack()
Definition: FlashMessageQueueTest.php:75
‪TYPO3\CMS\Core\Tests\Functional\Messaging
Definition: FlashMessageQueueTest.php:2
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\getMessagesAndFlushCanFilterBySeverity
‪getMessagesAndFlushCanFilterBySeverity()
Definition: FlashMessageQueueTest.php:88
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\messagesCanBeFilteredBySeverity
‪messagesCanBeFilteredBySeverity()
Definition: FlashMessageQueueTest.php:40
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\getAllMessagesAndFlushContainsEnqueuedMessage
‪getAllMessagesAndFlushContainsEnqueuedMessage()
Definition: FlashMessageQueueTest.php:63
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\clearClearsTheQueue
‪clearClearsTheQueue()
Definition: FlashMessageQueueTest.php:129
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:22
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest
Definition: FlashMessageQueueTest.php:24
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Core\Tests\Functional\Messaging\FlashMessageQueueTest\getAllMessagesReturnsSessionFlashMessageAndTransientFlashMessage
‪getAllMessagesReturnsSessionFlashMessageAndTransientFlashMessage()
Definition: FlashMessageQueueTest.php:114
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:25