TYPO3 CMS  TYPO3_8-7
AbstractControllerTest.php
Go to the documentation of this file.
1 <?php
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 
20 class AbstractControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
26  {
27  $className = $this->getUniqueId('Tx_Extbase_Tests_Fixtures_Controller');
28  eval('class ' . $className . ' extends \\' . \TYPO3\CMS\Extbase\Mvc\Controller\AbstractController::class . ' { function getExtensionName() { return $this->extensionName; } }');
29  $mockController = new $className();
30  $expectedResult = 'Extbase';
31  $actualResult = $mockController->getExtensionName();
32  $this->assertEquals($expectedResult, $actualResult);
33  }
34 
39  {
40  $className = $this->getUniqueId('DummyController');
41  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\' . \TYPO3\CMS\Extbase\Mvc\Controller\AbstractController::class . ' { function getExtensionName() { return $this->extensionName; } }');
42  $classNameNamespaced = __NAMESPACE__ . '\\' . $className;
43  $mockController = new $classNameNamespaced();
44  $expectedResult = 'Extbase';
45  $actualResult = $mockController->getExtensionName();
46  $this->assertEquals($expectedResult, $actualResult);
47  }
48 
52  public function addFlashMessageDataProvider()
53  {
54  return [
55  [
56  new \TYPO3\CMS\Core\Messaging\FlashMessage('Simple Message'),
57  'Simple Message',
58  '',
60  false
61  ],
62  [
63  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some OK', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::OK, true),
64  'Some OK',
65  'Message Title',
67  true
68  ],
69  [
70  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Info', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::INFO, true),
71  'Some Info',
72  'Message Title',
74  true
75  ],
76  [
77  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Notice', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE, true),
78  'Some Notice',
79  'Message Title',
81  true
82  ],
83 
84  [
85  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Warning', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, true),
86  'Some Warning',
87  'Message Title',
89  true
90  ],
91  [
92  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Error', 'Message Title', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, true),
93  'Some Error',
94  'Message Title',
96  true
97  ]
98  ];
99  }
100 
105  public function addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle = '', $severity = \TYPO3\CMS\Core\Messaging\FlashMessage::OK, $storeInSession = true)
106  {
107  $flashMessageQueue = $this->getMockBuilder(\TYPO3\CMS\Core\Messaging\FlashMessageQueue::class)
108  ->setMethods(['enqueue'])
109  ->setConstructorArgs([$this->getUniqueId('identifier_')])
110  ->getMock();
111 
112  $flashMessageQueue->expects($this->once())->method('enqueue')->with($this->equalTo($expectedMessage));
113 
114  $controllerContext = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Controller\ControllerContext::class)
115  ->setMethods(['getFlashMessageQueue'])
116  ->getMock();
117  $controllerContext->expects($this->once())->method('getFlashMessageQueue')->will($this->returnValue($flashMessageQueue));
118 
119  $controller = $this->getMockForAbstractClass(
120  \TYPO3\CMS\Extbase\Mvc\Controller\AbstractController::class,
121  [],
122  '',
123  false,
124  true,
125  true,
126  ['dummy']
127  );
128  $this->inject($controller, 'controllerContext', $controllerContext);
129 
130  $controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
131  }
132 
137  {
138  $this->expectException(\InvalidArgumentException::class);
139  $this->expectExceptionCode(1243258395);
140  $controller = $this->getMockForAbstractClass(
141  \TYPO3\CMS\Extbase\Mvc\Controller\AbstractController::class,
142  [],
143  '',
144  false,
145  true,
146  true,
147  ['dummy']
148  );
149 
150  $controller->addFlashMessage(new \stdClass());
151  }
152 }
addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle='', $severity=\TYPO3\CMS\Core\Messaging\FlashMessage::OK, $storeInSession=true)