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