‪TYPO3CMS  10.4
ActionControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
30 
34 class ‪ActionControllerTest extends FunctionalTestCase
35 {
39  protected ‪$request;
40 
44  protected ‪$response;
45 
49  protected ‪$controller;
50 
51  protected function ‪setUp(): void
52  {
53  parent::setUp();
54 
55  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
56 
57  $this->request = $objectManager->get(Request::class);
58  $this->request->setPluginName('Pi1');
59  $this->request->setControllerExtensionName('Extbase\\Tests\\Functional\\Mvc\\Controller\\Fixture');
60  $this->request->setControllerName('Test');
61  $this->request->setMethod('GET');
62  $this->request->setFormat('html');
63 
64  $this->response = $objectManager->get(Response::class);
65 
66  $this->controller = $objectManager->get(TestController::class);
67  }
68 
73  {
74  // Setup
75  $this->request->setControllerActionName('bar');
76  $this->request->setArgument('barParam', '');
77 
78  // Test run
79  $this->controller->processRequest($this->request, $this->response);
80 
81  // Assertions
82  $arguments = $this->controller->getControllerContext()->getArguments();
83  $argument = $arguments->getArgument('barParam');
84 
86  $conjunctionValidator = $argument->getValidator();
87  self::assertInstanceOf(ConjunctionValidator::class, $conjunctionValidator);
88 
90  $validators = $conjunctionValidator->getValidators();
91  self::assertInstanceOf(\SplObjectStorage::class, $validators);
92 
93  $validators->rewind();
94  self::assertInstanceOf(CustomValidator::class, $validators->current());
95  }
96 
101  {
102  // Setup
103  $this->request->setControllerActionName('baz');
104  $this->request->setArgument('bazParam', [ 'notEmpty' ]);
105 
106  // Test run
107  $this->controller->processRequest($this->request, $this->response);
108 
109  // Assertions
110  $arguments = $this->controller->getControllerContext()->getArguments();
111  $argument = $arguments->getArgument('bazParam');
112 
114  $conjunctionValidator = $argument->getValidator();
115  self::assertInstanceOf(ConjunctionValidator::class, $conjunctionValidator);
116 
118  $validators = $conjunctionValidator->getValidators();
119  self::assertInstanceOf(\SplObjectStorage::class, $validators);
120  self::assertCount(1, $validators);
121 
122  $validators->rewind();
123  self::assertInstanceOf(NotEmptyValidator::class, $validators->current());
124  }
125 
130  {
131  // Test setup
132  $reflectionClass = new \ReflectionClass($this->controller);
133  $reflectionMethod = $reflectionClass->getProperty('defaultViewObjectName');
134  $reflectionMethod->setAccessible(true);
135  $reflectionMethod->setValue($this->controller, JsonView::class);
136 
137  $this->request->setControllerActionName('qux');
138 
139  // Test run
140  $this->controller->processRequest($this->request, $this->response);
141 
142  // Assertions
143  $reflectionMethod = $reflectionClass->getProperty('view');
144  $reflectionMethod->setAccessible(true);
145  $reflectionMethod->getValue($this->controller);
146 
147  $view = $reflectionMethod->getValue($this->controller);
148  self::assertInstanceOf(JsonView::class, $view);
149  }
150 }
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:24
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\customValidatorsAreProperlyResolved
‪customValidatorsAreProperlyResolved()
Definition: ActionControllerTest.php:69
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller
Definition: ActionControllerArgumentTest.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\extbaseValidatorsAreProperlyResolved
‪extbaseValidatorsAreProperlyResolved()
Definition: ActionControllerTest.php:97
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\Fixture\Controller\TestController
Definition: TestController.php:30
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\$response
‪TYPO3 CMS Extbase Mvc Web Response $response
Definition: ActionControllerTest.php:42
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\Fixture\Validation\Validator\CustomValidator
Definition: CustomValidator.php:26
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\$request
‪TYPO3 CMS Extbase Mvc Web Request $request
Definition: ActionControllerTest.php:38
‪TYPO3\CMS\Extbase\Mvc\Web\Response
Definition: Response.php:26
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\$controller
‪TYPO3 CMS Extbase Tests Functional Mvc Controller Fixture Controller TestController $controller
Definition: ActionControllerTest.php:46
‪TYPO3\CMS\Extbase\Mvc\Web\Request
Definition: Request.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest
Definition: ActionControllerTest.php:35
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:22
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\resolveViewRespectsDefaultViewObjectName
‪resolveViewRespectsDefaultViewObjectName()
Definition: ActionControllerTest.php:126
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\setUp
‪setUp()
Definition: ActionControllerTest.php:48
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extbase\Mvc\View\JsonView
Definition: JsonView.php:29