‪TYPO3CMS  10.4
AbstractControllerTest.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 
23 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
24 
28 class ‪AbstractControllerTest extends UnitTestCase
29 {
34  {
35  return [
36  [
37  new ‪FlashMessage('Simple Message'),
38  'Simple Message',
39  '',
41  false
42  ],
43  [
44  new ‪FlashMessage('Some OK', 'Message Title', ‪FlashMessage::OK, true),
45  'Some OK',
46  'Message Title',
48  true
49  ],
50  [
51  new ‪FlashMessage('Some Info', 'Message Title', ‪FlashMessage::INFO, true),
52  'Some Info',
53  'Message Title',
55  true
56  ],
57  [
58  new ‪FlashMessage('Some Notice', 'Message Title', ‪FlashMessage::NOTICE, true),
59  'Some Notice',
60  'Message Title',
62  true
63  ],
64 
65  [
66  new ‪FlashMessage('Some Warning', 'Message Title', ‪FlashMessage::WARNING, true),
67  'Some Warning',
68  'Message Title',
70  true
71  ],
72  [
73  new ‪FlashMessage('Some Error', 'Message Title', ‪FlashMessage::ERROR, true),
74  'Some Error',
75  'Message Title',
77  true
78  ]
79  ];
80  }
81 
86  public function ‪addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle = '', $severity = ‪FlashMessage::OK, $storeInSession = true)
87  {
88  $flashMessageQueue = $this->getMockBuilder(FlashMessageQueue::class)
89  ->setMethods(['enqueue'])
90  ->setConstructorArgs([‪StringUtility::getUniqueId('identifier_')])
91  ->getMock();
92 
93  $flashMessageQueue->expects(self::once())->method('enqueue')->with(self::equalTo($expectedMessage));
94 
95  $controllerContext = $this->getMockBuilder(ControllerContext::class)
96  ->setMethods(['getFlashMessageQueue'])
97  ->getMock();
98  $controllerContext->expects(self::once())->method('getFlashMessageQueue')->willReturn($flashMessageQueue);
99 
100  $controller = $this->getAccessibleMockForAbstractClass(
101  AbstractController::class,
102  [],
103  '',
104  false,
105  true,
106  true,
107  ['dummy']
108  );
109  $controller->_set('controllerContext', $controllerContext);
110 
111  $controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
112  }
113 
118  {
119  $this->expectException(\InvalidArgumentException::class);
120  $this->expectExceptionCode(1243258395);
121  $controller = $this->getMockForAbstractClass(
122  AbstractController::class,
123  [],
124  '',
125  false,
126  true,
127  true,
128  ['dummy']
129  );
130 
131  $controller->addFlashMessage(new \stdClass());
132  }
133 }
‪TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext
Definition: ControllerContext.php:28
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Controller\AbstractControllerTest\addFlashMessageAddsFlashMessageObjectToFlashMessageQueue
‪addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle='', $severity=FlashMessage::OK, $storeInSession=true)
Definition: AbstractControllerTest.php:86
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:30
‪TYPO3\CMS\Extbase\Mvc\Controller\AbstractController
Definition: AbstractController.php:43
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Controller
Definition: AbstractControllerTest.php:16
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:29
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Controller\AbstractControllerTest\addFlashMessageThrowsExceptionOnInvalidMessageBody
‪addFlashMessageThrowsExceptionOnInvalidMessageBody()
Definition: AbstractControllerTest.php:117
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static string getUniqueId($prefix='')
Definition: StringUtility.php:92
‪TYPO3\CMS\Core\Messaging\FlashMessage
Definition: FlashMessage.php:24
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Controller\AbstractControllerTest
Definition: AbstractControllerTest.php:29
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Controller\AbstractControllerTest\addFlashMessageDataProvider
‪array addFlashMessageDataProvider()
Definition: AbstractControllerTest.php:33
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:22
‪TYPO3\CMS\Core\Messaging\FlashMessageQueue
Definition: FlashMessageQueue.php:29
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:31