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