‪TYPO3CMS  10.4
ControllerArgumentsMappingTest.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 
28 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
29 
33 class ‪ControllerArgumentsMappingTest extends FunctionalTestCase
34 {
38  protected ‪$request;
39 
43  protected ‪$response;
44 
48  protected ‪$controller;
49 
53  protected ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
54 
58  protected ‪$coreExtensionsToLoad = ['extbase', 'fluid'];
59 
60  protected function ‪setUp(): void
61  {
62  parent::setUp();
63 
64  $this->importCSVDataSet(ORIGINAL_ROOT . 'typo3/sysext/extbase/Tests/Functional/Persistence/Fixtures/translatedBlogExampleData.csv');
65 
66  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
67  $configuration = [
68  'persistence' => [
69  'storagePid' => 20,
70  'classes' => [
71  'TYPO3\CMS\Extbase\Domain\Model\Category' => [
72  'mapping' => ['tableName' => 'sys_category']
73  ]
74  ]
75  ]
76  ];
77  $configurationManager = $objectManager->get(ConfigurationManagerInterface::class);
78  $configurationManager->setConfiguration($configuration);
79  $this->request = $objectManager->get(Request::class);
80  $this->request->setPluginName('Pi1');
81  $this->request->setControllerExtensionName(BlogController::class);
82  $this->request->setControllerName('Blog');
83  $this->request->setMethod('GET');
84  $this->request->setFormat('html');
85 
86  $this->response = $objectManager->get(Response::class);
87 
88  $this->controller = $objectManager->get(BlogController::class);
89  }
90 
92  {
93  return [
94  [
95  'language' => 0,
96  'blogUid' => 1,
97  'blogTitle' => 'Blog 1',
98  ],
99  [
100  'language' => 1,
101  'blogUid' => 1,
102  'blogTitle' => 'Blog 1 DK',
103  ],
104  ];
105  }
106 
111  public function ‪actionGetsBlogFromUidArgument(int $language, int $blogUid, string $expectedTitle)
112  {
113  $context = GeneralUtility::makeInstance(Context::class);
114  $context->setAspect('language', new ‪LanguageAspect($language, $language, ‪LanguageAspect::OVERLAYS_ON));
115  $this->request->setControllerActionName('details');
116  $this->request->setArgument('blog', $blogUid);
117 
118  $this->controller->processRequest($this->request, $this->response);
119 
120  self::assertEquals($expectedTitle, $this->response->getContent());
121  }
122 }
‪ExtbaseTeam\BlogExample\Controller\BlogController
Definition: BlogController.php:32
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller
Definition: ActionControllerArgumentTest.php:18
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$request
‪TYPO3 CMS Extbase Mvc Web Request $request
Definition: ControllerArgumentsMappingTest.php:37
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface
Definition: ConfigurationManagerInterface.php:28
‪TYPO3\CMS\Core\Context\LanguageAspect\OVERLAYS_ON
‪const OVERLAYS_ON
Definition: LanguageAspect.php:76
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\actionGetsBlogFromUidArgument
‪actionGetsBlogFromUidArgument(int $language, int $blogUid, string $expectedTitle)
Definition: ControllerArgumentsMappingTest.php:106
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\setUp
‪setUp()
Definition: ControllerArgumentsMappingTest.php:55
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\actionGetsBlogFromUidArgumentDataProvider
‪actionGetsBlogFromUidArgumentDataProvider()
Definition: ControllerArgumentsMappingTest.php:86
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: ControllerArgumentsMappingTest.php:53
‪TYPO3\CMS\Extbase\Mvc\Web\Response
Definition: Response.php:26
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: ControllerArgumentsMappingTest.php:49
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:57
‪TYPO3\CMS\Extbase\Mvc\Web\Request
Definition: Request.php:23
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$controller
‪BlogController $controller
Definition: ControllerArgumentsMappingTest.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest
Definition: ControllerArgumentsMappingTest.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$response
‪TYPO3 CMS Extbase Mvc Web Response $response
Definition: ControllerArgumentsMappingTest.php:41
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28