‪TYPO3CMS  ‪main
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 
20 use PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
29 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
31 
32 final class ‪ControllerArgumentsMappingTest extends FunctionalTestCase
33 {
36 
37  protected array ‪$testExtensionsToLoad = ['typo3/sysext/extbase/Tests/Functional/Fixtures/Extensions/blog_example'];
38 
39  protected function ‪setUp(): void
40  {
41  parent::setUp();
42 
43  $this->importCSVDataSet(__DIR__ . '/Fixture/ControllerArgumentsMappingTestImport.csv');
44 
45  $configuration = [
46  'persistence' => [
47  'storagePid' => 20,
48  ],
49  ];
50  $configurationManager = $this->get(ConfigurationManager::class);
51  $configurationManager->setConfiguration($configuration);
52  $serverRequest = (new ‪ServerRequest())->withAttribute('extbase', new ‪ExtbaseRequestParameters());
53  $this->request = new ‪Request($serverRequest);
54  $this->request = $this->request->withPluginName('Pi1');
55  $this->request = $this->request->withControllerExtensionName(BlogController::class);
56  $this->request = $this->request->withControllerName('Blog');
57  $this->request = $this->request->withFormat('html');
58  $this->request = $this->request->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
59  ‪$GLOBALS['TYPO3_REQUEST'] = ‪$this->request;
60 
61  $this->controller = $this->get(BlogController::class);
62  }
63 
64  public static function ‪actionGetsBlogFromUidArgumentDataProvider(): array
65  {
66  return [
67  [
68  'language' => 0,
69  'blogUid' => 1,
70  'expectedTitle' => 'Blog 1',
71  ],
72  [
73  'language' => 1,
74  'blogUid' => 1,
75  'expectedTitle' => 'Blog 1 DA',
76  ],
77  ];
78  }
79 
80  #[DataProvider('actionGetsBlogFromUidArgumentDataProvider')]
81  #[Test]
82  public function ‪actionGetsBlogFromUidArgument(int $language, int $blogUid, string $expectedTitle): void
83  {
84  $context = $this->get(Context::class);
85  $context->setAspect('language', new ‪LanguageAspect($language, $language, ‪LanguageAspect::OVERLAYS_ON));
86  $this->request = $this->request->withControllerActionName('details');
87  $this->request = $this->request->withArgument('blog', $blogUid);
88 
89  $response = $this->controller->processRequest($this->request);
90 
91  $response->getBody()->rewind();
92  self::assertEquals($expectedTitle, $response->getBody()->getContents());
93  }
94 }
‪TYPO3Tests\BlogExample\Controller\BlogController
Definition: BlogController.php:34
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$request
‪Request $request
Definition: ControllerArgumentsMappingTest.php:34
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\actionGetsBlogFromUidArgumentDataProvider
‪static actionGetsBlogFromUidArgumentDataProvider()
Definition: ControllerArgumentsMappingTest.php:64
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller
Definition: ActionControllerArgumentTest.php:18
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪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:82
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\setUp
‪setUp()
Definition: ControllerArgumentsMappingTest.php:39
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Extbase\Configuration\ConfigurationManager
Definition: ConfigurationManager.php:32
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$testExtensionsToLoad
‪array $testExtensionsToLoad
Definition: ControllerArgumentsMappingTest.php:37
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪TYPO3\CMS\Core\Context\LanguageAspect
Definition: LanguageAspect.php:57
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest\$controller
‪BlogController $controller
Definition: ControllerArgumentsMappingTest.php:35
‪TYPO3\CMS\Extbase\Mvc\ExtbaseRequestParameters
Definition: ExtbaseRequestParameters.php:35
‪TYPO3\CMS\Extbase\Tests\Functional\Mvc\Controller\ControllerArgumentsMappingTest
Definition: ControllerArgumentsMappingTest.php:33
‪TYPO3\CMS\Extbase\Mvc\Request
Definition: Request.php:35