c5c5fd33a66d9886bd1721c8c342a4c404e81c89
[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 * Copyright notice
6 *
7 * (c) 2012 Stefan Neufeind <info@speedpartner.de>
8 * (c) 2013 Steffen Müller <typo3@t3node.com>
9 * All rights reserved
10 *
11 * This script is part of the TYPO3 project. The TYPO3 project is
12 * free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * The GNU General Public License can be found at
18 * http://www.gnu.org/copyleft/gpl.html.
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Test case
30 */
31 class AbstractControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
32
33 /**
34 * @test
35 */
36 public function constructResolvesExtensionnameFromOldStyle() {
37 $className = uniqid('Tx_Extbase_Tests_Fixtures_Controller');
38 eval('class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController { function getExtensionName() { return $this->extensionName; } }');
39 $mockController = new $className();
40 $expectedResult = 'Extbase';
41 $actualResult = $mockController->getExtensionName();
42 $this->assertEquals($expectedResult, $actualResult);
43 }
44
45 /**
46 * @test
47 */
48 public function constructResolvesExtensionnameFromNamespaced() {
49 $className = uniqid('DummyController');
50 eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController { function getExtensionName() { return $this->extensionName; } }');
51 $classNameNamespaced = __NAMESPACE__ . '\\' . $className;
52 $mockController = new $classNameNamespaced();
53 $expectedResult = 'Extbase';
54 $actualResult = $mockController->getExtensionName();
55 $this->assertEquals($expectedResult, $actualResult);
56 }
57
58 /**
59 * @return array
60 */
61 public function addFlashMessageDataProvider() {
62 return array(
63 array(
64 new \TYPO3\CMS\Core\Messaging\FlashMessage('Simple Message'),
65 'Simple Message',
66 '',
67 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
68 FALSE
69 ),
70 array(
71 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some OK', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, TRUE),
72 'Some OK',
73 'Message Title',
74 \TYPO3\CMS\Core\Messaging\FlashMessage::OK,
75 TRUE
76 ),
77 array(
78 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Info', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO, TRUE),
79 'Some Info',
80 'Message Title',
81 \TYPO3\CMS\Core\Messaging\FlashMessage::INFO,
82 TRUE
83 ),
84 array(
85 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Notice', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE, TRUE),
86 'Some Notice',
87 'Message Title',
88 \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE,
89 TRUE
90 ),
91
92 array(
93 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Warning', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, TRUE),
94 'Some Warning',
95 'Message Title',
96 \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING,
97 TRUE
98 ),
99 array(
100 new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Error', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, TRUE),
101 'Some Error',
102 'Message Title',
103 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR,
104 TRUE
105 )
106 );
107 }
108
109 /**
110 * @test
111 * @dataProvider addFlashMessageDataProvider
112 */
113 public function addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK, $storeInSession = TRUE) {
114 $flashMessageQueue = $this->getMock(
115 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageQueue',
116 array('enqueue'),
117 array(),
118 '',
119 FALSE
120 );
121 $flashMessageQueue->expects($this->once())->method('enqueue')->with($this->equalTo($expectedMessage));
122
123 $controllerContext = $this->getMock(
124 '\\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext',
125 array('getFlashMessageQueue')
126 );
127 $controllerContext->expects($this->once())->method('getFlashMessageQueue')->will($this->returnValue($flashMessageQueue));
128
129 $controller = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController',
130 array(),
131 '',
132 FALSE,
133 TRUE,
134 TRUE,
135 array('dummy')
136 );
137 $this->inject($controller, 'controllerContext', $controllerContext);
138
139 $controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
140 }
141
142 /**
143 * @test
144 * @expectedException \InvalidArgumentException
145 */
146 public function addFlashMessageThrowsExceptionOnInvalidMessageBody() {
147 $controller = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController',
148 array(),
149 '',
150 FALSE,
151 TRUE,
152 TRUE,
153 array('dummy')
154 );
155
156 $controller->addFlashMessage(new \stdClass());
157 }
158 }