‪TYPO3CMS  9.5
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 
17 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
18 
22 class ‪AbstractControllerTest extends UnitTestCase
23 {
28  {
29  $className = $this->getUniqueId('DummyController');
30  eval('namespace ' . __NAMESPACE__ . '; class ' . $className . ' extends \\' . \‪TYPO3\CMS\‪Extbase\Mvc\Controller\AbstractController::class . ' { function getExtensionName() { return $this->extensionName; } }');
31  $classNameNamespaced = __NAMESPACE__ . '\\' . $className;
32  $mockController = new $classNameNamespaced();
33  $expectedResult = 'Extbase';
34  $actualResult = $mockController->getExtensionName();
35  $this->assertEquals($expectedResult, $actualResult);
36  }
37 
42  {
43  return [
44  [
45  new \TYPO3\CMS\Core\Messaging\FlashMessage('Simple Message'),
46  'Simple Message',
47  '',
49  false
50  ],
51  [
52  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some OK', 'Message Title', \‪TYPO3\CMS\Core\Messaging\FlashMessage::OK, true),
53  'Some OK',
54  'Message Title',
56  true
57  ],
58  [
59  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Info', 'Message Title', \‪TYPO3\CMS\Core\Messaging\FlashMessage::INFO, true),
60  'Some Info',
61  'Message Title',
63  true
64  ],
65  [
66  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Notice', 'Message Title', \‪TYPO3\CMS\Core\Messaging\FlashMessage::NOTICE, true),
67  'Some Notice',
68  'Message Title',
70  true
71  ],
72 
73  [
74  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Warning', 'Message Title', \‪TYPO3\CMS\Core\Messaging\FlashMessage::WARNING, true),
75  'Some Warning',
76  'Message Title',
78  true
79  ],
80  [
81  new \TYPO3\CMS\Core\Messaging\FlashMessage('Some Error', 'Message Title', \‪TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, true),
82  'Some Error',
83  'Message Title',
85  true
86  ]
87  ];
88  }
89 
94  public function ‪addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle = '', $severity = \‪TYPO3\CMS\Core\Messaging\FlashMessage::OK, $storeInSession = true)
95  {
96  $flashMessageQueue = $this->getMockBuilder(\‪TYPO3\CMS\Core\Messaging\FlashMessageQueue::class)
97  ->setMethods(['enqueue'])
98  ->setConstructorArgs([$this->getUniqueId('identifier_')])
99  ->getMock();
100 
101  $flashMessageQueue->expects($this->once())->method('enqueue')->with($this->equalTo($expectedMessage));
102 
103  $controllerContext = $this->getMockBuilder(\‪TYPO3\CMS\‪Extbase\Mvc\Controller\ControllerContext::class)
104  ->setMethods(['getFlashMessageQueue'])
105  ->getMock();
106  $controllerContext->expects($this->once())->method('getFlashMessageQueue')->will($this->returnValue($flashMessageQueue));
107 
108  $controller = $this->getMockForAbstractClass(
109  \‪TYPO3\CMS\‪Extbase\Mvc\Controller\AbstractController::class,
110  [],
111  '',
112  false,
113  true,
114  true,
115  ['dummy']
116  );
117  $this->inject($controller, 'controllerContext', $controllerContext);
118 
119  $controller->addFlashMessage($messageBody, $messageTitle, $severity, $storeInSession);
120  }
121 
126  {
127  $this->expectException(\InvalidArgumentException::class);
128  $this->expectExceptionCode(1243258395);
129  $controller = $this->getMockForAbstractClass(
130  \‪TYPO3\CMS\‪Extbase\Mvc\Controller\AbstractController::class,
131  [],
132  '',
133  false,
134  true,
135  true,
136  ['dummy']
137  );
138 
139  $controller->addFlashMessage(new \stdClass());
140  }
141 }
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller
Definition: AbstractControllerTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\AbstractControllerTest
Definition: AbstractControllerTest.php:23
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\AbstractControllerTest\constructResolvesExtensionnameFromNamespaced
‪constructResolvesExtensionnameFromNamespaced()
Definition: AbstractControllerTest.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\WARNING
‪const WARNING
Definition: AbstractMessage.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\AbstractControllerTest\addFlashMessageThrowsExceptionOnInvalidMessageBody
‪addFlashMessageThrowsExceptionOnInvalidMessageBody()
Definition: AbstractControllerTest.php:125
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\AbstractControllerTest\addFlashMessageAddsFlashMessageObjectToFlashMessageQueue
‪addFlashMessageAddsFlashMessageObjectToFlashMessageQueue($expectedMessage, $messageBody, $messageTitle='', $severity=\TYPO3\CMS\Core\Messaging\FlashMessage::OK, $storeInSession=true)
Definition: AbstractControllerTest.php:94
‪TYPO3\CMS\Extbase\Tests\Unit\Mvc\Controller\AbstractControllerTest\addFlashMessageDataProvider
‪array addFlashMessageDataProvider()
Definition: AbstractControllerTest.php:41
‪TYPO3\CMS\Core\Messaging\AbstractMessage\OK
‪const OK
Definition: AbstractMessage.php:27
‪TYPO3\CMS\Core\Messaging\AbstractMessage\INFO
‪const INFO
Definition: AbstractMessage.php:26
‪TYPO3\CMS\Core\Messaging\AbstractMessage\NOTICE
‪const NOTICE
Definition: AbstractMessage.php:25
‪TYPO3\CMS\Core\Messaging\AbstractMessage\ERROR
‪const ERROR
Definition: AbstractMessage.php:29