‪TYPO3CMS  9.5
ActionControllerTest.php
Go to the documentation of this file.
1 <?php
2 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 
25 
29 class ‪ActionControllerTest extends \TYPO3\TestingFramework\Core\Functional\FunctionalTestCase
30 {
34  protected ‪$request;
35 
39  protected ‪$response;
40 
44  protected ‪$controller;
45 
46  protected function ‪setUp()
47  {
48  parent::setUp();
49 
50  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
51 
52  $this->request = $objectManager->get(Request::class);
53  $this->request->setControllerVendorName('TYPO3\\CMS');
54  $this->request->setPluginName('Pi1');
55  $this->request->setControllerExtensionName('Extbase\\Tests\\Functional\\Mvc\\Controller\\Fixture');
56  $this->request->setControllerName('Test');
57  $this->request->setMethod('GET');
58  $this->request->setFormat('html');
59 
60  $this->response = $objectManager->get(Response::class);
61 
62  $this->controller = $objectManager->get(Fixture\Controller\TestController::class);
63  }
64 
65  protected function ‪tearDown()
66  {
67  unset($this->request, $this->response, $this->controller);
68  parent::tearDown();
69  }
70 
75  {
76  // Setup
77  $this->request->setControllerActionName('foo');
78  $this->request->setArgument('fooParam', []);
79 
80  // Test run
81  $this->controller->processRequest($this->request, $this->response);
82 
83  // Assertions
84  $arguments = $this->controller->getControllerContext()->getArguments();
85  $argument = $arguments->getArgument('fooParam');
86 
88  $conjunctionValidator = $argument->getValidator();
89  static::assertInstanceOf(ConjunctionValidator::class, $conjunctionValidator);
90 
92  $validators = $conjunctionValidator->getValidators();
93  static::assertInstanceOf(\SplObjectStorage::class, $validators);
94 
95  $validators->rewind();
96 
98  $subConjunctionValidator = $validators->current();
99  static::assertInstanceOf(ConjunctionValidator::class, $subConjunctionValidator);
100 
102  $subValidators = $subConjunctionValidator->getValidators();
103  static::assertInstanceOf(\SplObjectStorage::class, $subValidators);
104 
105  $subValidators->rewind();
106  static::assertInstanceOf(Fixture\Domain\Validator\ModelValidator::class, $subValidators->current());
107  }
108 
113  {
114  // Setup
115  $this->request->setControllerActionName('bar');
116  $this->request->setArgument('barParam', '');
117 
118  // Test run
119  $this->controller->processRequest($this->request, $this->response);
120 
121  // Assertions
122  $arguments = $this->controller->getControllerContext()->getArguments();
123  $argument = $arguments->getArgument('barParam');
124 
126  $conjunctionValidator = $argument->getValidator();
127  static::assertInstanceOf(ConjunctionValidator::class, $conjunctionValidator);
128 
130  $validators = $conjunctionValidator->getValidators();
131  static::assertInstanceOf(\SplObjectStorage::class, $validators);
132 
133  $validators->rewind();
134  static::assertInstanceOf(Fixture\Validation\Validator\CustomValidator::class, $validators->current());
135 
136  $validators->next();
137 
139  $subConjunctionValidator = $validators->current();
140  static::assertInstanceOf(ConjunctionValidator::class, $subConjunctionValidator);
141 
143  $subValidators = $subConjunctionValidator->getValidators();
144  static::assertInstanceOf(\SplObjectStorage::class, $subValidators);
145 
146  $subValidators->rewind();
147  static::assertInstanceOf(StringValidator::class, $subValidators->current());
148  }
149 
154  {
155  // Setup
156  $this->request->setControllerActionName('baz');
157  $this->request->setArgument('bazParam', [ 'notEmpty' ]);
158 
159  // Test run
160  $this->controller->processRequest($this->request, $this->response);
161 
162  // Assertions
163  $arguments = $this->controller->getControllerContext()->getArguments();
164  $argument = $arguments->getArgument('bazParam');
165 
167  $conjunctionValidator = $argument->getValidator();
168  static::assertInstanceOf(ConjunctionValidator::class, $conjunctionValidator);
169 
171  $validators = $conjunctionValidator->getValidators();
172  static::assertInstanceOf(\SplObjectStorage::class, $validators);
173  static::assertCount(1, $validators);
174 
175  $validators->rewind();
176  static::assertInstanceOf(NotEmptyValidator::class, $validators->current());
177  }
178 }
‪TYPO3\CMS\Extbase\Validation\Validator\ConjunctionValidator
Definition: ConjunctionValidator.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\customValidatorsAreProperlyResolved
‪customValidatorsAreProperlyResolved()
Definition: ActionControllerTest.php:109
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller
Definition: ActionControllerArgumentTest.php:3
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\extbaseValidatorsAreProperlyResolved
‪extbaseValidatorsAreProperlyResolved()
Definition: ActionControllerTest.php:150
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\$response
‪TYPO3 CMS Extbase Mvc Web Response $response
Definition: ActionControllerTest.php:37
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\$request
‪TYPO3 CMS Extbase Mvc Web Request $request
Definition: ActionControllerTest.php:33
‪TYPO3\CMS\Extbase\Mvc\Web\Response
Definition: Response.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\tearDown
‪tearDown()
Definition: ActionControllerTest.php:62
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\$controller
‪TYPO3 CMS Extbase Tests Functional Mvc Controller Fixture Controller TestController $controller
Definition: ActionControllerTest.php:41
‪TYPO3\CMS\Extbase\Mvc\Web\Request
Definition: Request.php:21
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\modelValidatorsAreProperlyResolved
‪modelValidatorsAreProperlyResolved()
Definition: ActionControllerTest.php:71
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest
Definition: ActionControllerTest.php:30
‪TYPO3\CMS\Extbase\Validation\Validator\NotEmptyValidator
Definition: NotEmptyValidator.php:21
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ActionControllerTest\setUp
‪setUp()
Definition: ActionControllerTest.php:43
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Validation\Validator\StringValidator
Definition: StringValidator.php:21
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25