[TASK] Use FQCN's when registering plugins/modules
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Mvc / Controller / AbstractControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller;
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
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18
19 /**
20 * Test case
21 */
22 class AbstractControllerTest extends UnitTestCase
23 {
24 /**
25 * @return array
26 */
27 public function addFlashMessageDataProvider()
28 {
29 return [
30 [
31 new \TYPO3\CMS\Core\Messaging\FlashMessage('Simple Message'),
32 'Simple Message',
33 '',
34 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
35 false
36 ],
37 [
38 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some OK', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, true),
39 'Some OK',
40 'Message Title',
41 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
42 true
43 ],
44 [
45 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Info', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO, true),
46 'Some Info',
47 'Message Title',
48 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO,
49 true
50 ],
51 [
52 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Notice', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE, true),
53 'Some Notice',
54 'Message Title',
55 \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE,
56 true
57 ],
58
59 [
60 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Warning', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, true),
61 'Some Warning',
62 'Message Title',
63 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
64 true
65 ],
66 [
67 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Error', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, true),
68 'Some Error',
69 'Message Title',
70 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
71 true
72 ]
73 ];
74 }
75
76 /**
77 * @test
78 * @dataProvider addFlashMessageDataProvider
79 */
80 public function addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK, $storeInSession = true)
81 {
82 $flashMessageQueue = $this->getMockBuilder(\TYPO3\CMS\Core\Messaging\FlashMessageQueue::class)
83 ->setMethods(['enqueue'])
84 ->setConstructorArgs([$this->getUniqueId('identifier_')])
85 ->getMock();
86
87 $flashMessageQueue->expects($this->once())->method('enqueue')->with($this->equalTo($expectedMessage));
88
89 $controllerContext = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class)
90 ->setMethods(['getFlashMessageQueue'])
91 ->getMock();
92 $controllerContext->expects($this->once())->method('getFlashMessageQueue')->will($this->returnValue($flashMessageQueue));
93
94 $controller = $this->getMockForAbstractClass(
95 \TYPO3\CMS\Extbase\Mvc\Controller\AbstractController::class,
96 [],
97 '',
98 false,
99 true,
100 true,
101 ['dummy']
102 );
103 $this->inject($controller, 'controllerContext', $controllerContext);
104
105 $controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
106 }
107
108 /**
109 * @test
110 */
111 public function addFlashMessageThrowsExceptionOnInvalidMessageBody()
112 {
113 $this->expectException(\InvalidArgumentException::class);
114 $this->expectExceptionCode(1243258395);
115 $controller = $this->getMockForAbstractClass(
116 \TYPO3\CMS\Extbase\Mvc\Controller\AbstractController::class,
117 [],
118 '',
119 false,
120 true,
121 true,
122 ['dummy']
123 );
124
125 $controller->addFlashMessage(new \stdClass());
126 }
127 }