[BUGFIX] Get unit tests working again
[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 $this->markTestSkipped('Triggers "UnexpectedValueException: Serialized string cannot be empty", with phpunit since PHP in 5.4.29 and 5.5.13, needs investigation, see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/178');
115 $flashMessageQueue = $this->getMock(
116 'TYPO3\\CMS\\Core\\Messaging\\FlashMessageQueue',
117 array('enqueue'),
118 array(),
119 '',
120 FALSE
121 );
122 $flashMessageQueue->expects($this->once())->method('enqueue')->with($this->equalTo($expectedMessage));
123
124 $controllerContext = $this->getMock(
125 '\\TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext',
126 array('getFlashMessageQueue')
127 );
128 $controllerContext->expects($this->once())->method('getFlashMessageQueue')->will($this->returnValue($flashMessageQueue));
129
130 $controller = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController',
131 array(),
132 '',
133 FALSE,
134 TRUE,
135 TRUE,
136 array('dummy')
137 );
138 $this->inject($controller, 'controllerContext', $controllerContext);
139
140 $controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
141 }
142
143 /**
144 * @test
145 * @expectedException \InvalidArgumentException
146 */
147 public function addFlashMessageThrowsExceptionOnInvalidMessageBody() {
148 $controller = $this->getMockForAbstractClass('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\AbstractController',
149 array(),
150 '',
151 FALSE,
152 TRUE,
153 TRUE,
154 array('dummy')
155 );
156
157 $controller->addFlashMessage(new \stdClass());
158 }
159 }