‪TYPO3CMS  ‪main
AbstractLocalizedPagesTestCase.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 
22 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
23 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
24 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
26 
28 {
29  protected const ‪LANGUAGE_PRESETS = [
30  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
31  'DE' => ['id' => 1, 'title' => 'German', 'locale' => 'de_DE.UTF8'],
32  'DE-CH' => ['id' => 2, 'title' => 'Swiss German', 'locale' => 'de_CH.UTF8'],
33  ];
34 
35  protected function ‪setUpDatabaseWithYamlPayload(string $pathToYamlFile): void
36  {
37  $this->withDatabaseSnapshot(function () use ($pathToYamlFile) {
38  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users.csv');
39  $backendUser = $this->setUpBackendUser(1);
40  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
41  $factory = DataHandlerFactory::fromYamlFile($pathToYamlFile);
42  $writer = DataHandlerWriter::withBackendUser($backendUser);
43  $writer->invokeFactory($factory);
44  static::failIfArrayIsNotEmpty($writer->getErrors());
45  });
46  }
47 
48  protected function ‪assertScopes(string ‪$url, array $scopes): void
49  {
50  $this->setUpFrontendRootPage(
51  1000,
52  ['EXT:core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript'],
53  [
54  'title' => 'ACME Root',
55  ]
56  );
57 
58  $response = $this->executeFrontendSubRequest(new InternalRequest(‪$url));
59  $responseStructure = ResponseContent::fromString((string)$response->getBody());
60 
61  foreach ($scopes as $scopePath => $expectedScopeValue) {
62  self::assertSame($expectedScopeValue, $responseStructure->getScopePath($scopePath));
63  }
64  }
65 
66  protected function ‪assertResponseStatusCode(string ‪$url): void
67  {
68  $this->setUpFrontendRootPage(
69  1000,
70  ['EXT:core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']
71  );
72 
73  $response = $this->executeFrontendSubRequest(new InternalRequest(‪$url));
74  self::assertSame(404, $response->getStatusCode());
75  }
76 
77  protected function ‪assertMenu(string ‪$url, array $expectation): void
78  {
79  $this->setUpFrontendRootPage(
80  1000,
81  ['EXT:frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'],
82  [
83  'title' => 'ACME Root',
84  ]
85  );
86 
87  $response = $this->executeFrontendSubRequest(
88  (new InternalRequest(‪$url))
89  ->withInstructions([
90  $this->createHierarchicalMenuProcessorInstruction([
91  'levels' => 1,
92  'entryLevel' => 0,
93  'expandAll' => 1,
94  'includeSpacer' => 1,
95  'titleField' => 'title',
96  'as' => 'results',
97  ]),
98  ])
99  );
100 
101  $json = json_decode((string)$response->getBody(), true);
102  $json = $this->filterMenu($json);
103 
104  self::assertSame($expectation, $json);
105  }
106 
107  protected function ‪createLanguageMenu(string ‪$url): array
108  {
109  $this->setUpFrontendRootPage(
110  1000,
111  ['EXT:frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'],
112  ['title' => 'ACME Root']
113  );
114 
115  $response = $this->executeFrontendSubRequest(
116  (new InternalRequest(‪$url))->withInstructions([$this->createLanguageMenuProcessorInstruction(['languages' => 'auto'])])
117  );
118 
119  $json = json_decode((string)$response->getBody(), true);
120  $json = $this->filterMenu($json);
121 
122  return $json;
123  }
124 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertScopes
‪assertScopes(string $url, array $scopes)
Definition: AbstractLocalizedPagesTestCase.php:48
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertResponseStatusCode
‪assertResponseStatusCode(string $url)
Definition: AbstractLocalizedPagesTestCase.php:66
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering
Definition: AbstractLocalizedPagesTestCase.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase
Definition: AbstractLocalizedPagesTestCase.php:28
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertMenu
‪assertMenu(string $url, array $expectation)
Definition: AbstractLocalizedPagesTestCase.php:77
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\createLanguageMenu
‪createLanguageMenu(string $url)
Definition: AbstractLocalizedPagesTestCase.php:107
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUpDatabaseWithYamlPayload
‪setUpDatabaseWithYamlPayload(string $pathToYamlFile)
Definition: AbstractLocalizedPagesTestCase.php:35
‪TYPO3\CMS\Webhooks\Message\$url
‪identifier readonly UriInterface $url
Definition: LoginErrorOccurredMessage.php:36
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: AbstractLocalizedPagesTestCase.php:29