56ac975cf7eb03515af50d89e9edef498308eba4
[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 /**
18 * Test case
19 */
20 class AbstractControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
21
22 /**
23 * @test
24 */
25 public function constructResolvesExtensionnameFromOldStyle() {
26 $className = uniqid('Tx_Extbase_Tests_Fixtures_Controller');
27 eval('class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController { function getExtensionName() { return $this->extensionName; } }');
28 $mockController = new $className();
29 $expectedResult = 'Extbase';
30 $actualResult = $mockController->getExtensionName();
31 $this->assertEquals($expectedResult, $actualResult);
32 }
33
34 /**
35 * @test
36 */
37 public function constructResolvesExtensionnameFromNamespaced() {
38 $className = uniqid('DummyController');
39 eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController { function getExtensionName() { return $this->extensionName; } }');
40 $classNameNamespaced = __NAMESPACE__ . '\\' . $className;
41 $mockController = new $classNameNamespaced();
42 $expectedResult = 'Extbase';
43 $actualResult = $mockController->getExtensionName();
44 $this->assertEquals($expectedResult, $actualResult);
45 }
46
47 /**
48 * @return array
49 */
50 public function addFlashMessageDataProvider() {
51 return array(
52 array(
53 new \TYPO3\CMS\Core\Messaging\FlashMessage('Simple Message'),
54 'Simple Message',
55 '',
56 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
57 FALSE
58 ),
59 array(
60 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some OK', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE),
61 'Some OK',
62 'Message Title',
63 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
64 TRUE
65 ),
66 array(
67 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Info', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO, TRUE),
68 'Some Info',
69 'Message Title',
70 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO,
71 TRUE
72 ),
73 array(
74 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Notice', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE, TRUE),
75 'Some Notice',
76 'Message Title',
77 \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE,
78 TRUE
79 ),
80
81 array(
82 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Warning', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, TRUE),
83 'Some Warning',
84 'Message Title',
85 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
86 TRUE
87 ),
88 array(
89 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Error', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, TRUE),
90 'Some Error',
91 'Message Title',
92 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
93 TRUE
94 )
95 );
96 }
97
98 /**
99 * @test
100 * @dataProvider addFlashMessageDataProvider
101 */
102 public function addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK, $storeInSession = TRUE) {
103 $flashMessageQueue = $this->getMock(
104 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageQueue',
105 array('enqueue'),
106 array(uniqid('identifier_', TRUE))
107 );
108 $flashMessageQueue->expects($this->once())->method('enqueue')->with($this->equalTo($expectedMessage));
109
110 $controllerContext = $this->getMock(
111 '\\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext',
112 array('getFlashMessageQueue')
113 );
114 $controllerContext->expects($this->once())->method('getFlashMessageQueue')->will($this->returnValue($flashMessageQueue));
115
116 $controller = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController',
117 array(),
118 '',
119 FALSE,
120 TRUE,
121 TRUE,
122 array('dummy')
123 );
124 $this->inject($controller, 'controllerContext', $controllerContext);
125
126 $controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
127 }
128
129 /**
130 * @test
131 * @expectedException \InvalidArgumentException
132 */
133 public function addFlashMessageThrowsExceptionOnInvalidMessageBody() {
134 $controller = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController',
135 array(),
136 '',
137 FALSE,
138 TRUE,
139 TRUE,
140 array('dummy')
141 );
142
143 $controller->addFlashMessage(new \stdClass());
144 }
145 }