‪TYPO3CMS  10.4
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\InternalRequestContext;
26 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
27 
29 {
30  protected const ‪LANGUAGE_PRESETS = [
31  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''],
32  'DE' => ['id' => 1, 'title' => 'German', 'locale' => 'de_DE.UTF8', 'iso' => 'de', 'hrefLang' => 'de-DE', 'direction' => ''],
33  'DE-CH' => ['id' => 2, 'title' => 'Swiss German', 'locale' => 'de_CH.UTF8', 'iso' => 'de', 'hrefLang' => 'de-CH', 'direction' => ''],
34  ];
35 
39  protected ‪$siteTitle = 'A Company that Manufactures Everything Inc';
40 
45 
46  public static function ‪setUpBeforeClass(): void
47  {
48  parent::setUpBeforeClass();
49  static::initializeDatabaseSnapshot();
50  }
51 
52  public static function ‪tearDownAfterClass(): void
53  {
54  static::destroyDatabaseSnapshot();
55  parent::tearDownAfterClass();
56  }
57 
58  protected function ‪setUp(): void
59  {
60  parent::setUp();
61 
62  // these settings are forwarded to the frontend sub-request as well
63  $this->internalRequestContext = (new InternalRequestContext())
64  ->withGlobalSettings(['TYPO3_CONF_VARS' => static::TYPO3_CONF_VARS]);
65  }
66 
67  protected function ‪setUpDatabaseWithYamlPayload(string $pathToYamlFile): void
68  {
69  $this->withDatabaseSnapshot(function () use ($pathToYamlFile) {
70  $backendUser = $this->setUpBackendUserFromFixture(1);
72 
73  $factory = DataHandlerFactory::fromYamlFile($pathToYamlFile);
74  $writer = DataHandlerWriter::withBackendUser($backendUser);
75  $writer->invokeFactory($factory);
76  static::failIfArrayIsNotEmpty(
77  $writer->getErrors()
78  );
79  });
80  }
81 
82  protected function ‪tearDown(): void
83  {
84  unset($this->internalRequestContext);
85  parent::tearDown();
86  }
87 
92  protected function ‪assertScopes(string $url, array $scopes): void
93  {
94  $this->setUpFrontendRootPage(
95  1000,
96  ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript'],
97  [
98  'title' => 'ACME Root',
99  'sitetitle' => $this->siteTitle,
100  ]
101  );
102 
103  $response = $this->executeFrontendRequest(new InternalRequest($url), $this->internalRequestContext);
104  $responseStructure = ResponseContent::fromString((string)$response->getBody());
105 
106  foreach ($scopes as $scopePath => $expectedScopeValue) {
107  self::assertSame($expectedScopeValue, $responseStructure->getScopePath($scopePath));
108  }
109  }
110 
115  protected function ‪assertResponseStatusCode(string $url, int $statusCode): void
116  {
117  $this->setUpFrontendRootPage(
118  1000,
119  ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']
120  );
121 
122  $response = $this->executeFrontendRequest(new InternalRequest($url), $this->internalRequestContext);
123  self::assertSame(404, $response->getStatusCode());
124  }
125 
130  protected function ‪assertMenu(string $url, array $expectation): void
131  {
132  $this->setUpFrontendRootPage(
133  1000,
134  ['typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'],
135  [
136  'title' => 'ACME Root',
137  'sitetitle' => $this->siteTitle,
138  ]
139  );
140 
141  $response = $this->executeFrontendRequest(
142  (new InternalRequest($url))
143  ->withInstructions([
144  $this->createHierarchicalMenuProcessorInstruction([
145  'levels' => 1,
146  'entryLevel' => 0,
147  'expandAll' => 1,
148  'includeSpacer' => 1,
149  'titleField' => 'title',
150  'as' => 'results',
151  ]),
152  ]),
153  $this->internalRequestContext
154  );
155 
156  $json = json_decode((string)$response->getBody(), true);
157  $json = $this->filterMenu($json);
158 
159  self::assertSame($expectation, $json);
160  }
161 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertScopes
‪assertScopes(string $url, array $scopes)
Definition: AbstractLocalizedPagesTestCase.php:90
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUpBeforeClass
‪static setUpBeforeClass()
Definition: AbstractLocalizedPagesTestCase.php:44
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering
Definition: AbstractLocalizedPagesTestCase.php:18
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase
Definition: AbstractLocalizedPagesTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertResponseStatusCode
‪assertResponseStatusCode(string $url, int $statusCode)
Definition: AbstractLocalizedPagesTestCase.php:113
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUp
‪setUp()
Definition: AbstractLocalizedPagesTestCase.php:56
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static initializeLanguageObject()
Definition: Bootstrap.php:617
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\tearDownAfterClass
‪static tearDownAfterClass()
Definition: AbstractLocalizedPagesTestCase.php:50
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertMenu
‪assertMenu(string $url, array $expectation)
Definition: AbstractLocalizedPagesTestCase.php:128
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUpDatabaseWithYamlPayload
‪setUpDatabaseWithYamlPayload(string $pathToYamlFile)
Definition: AbstractLocalizedPagesTestCase.php:65
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:66
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\$internalRequestContext
‪InternalRequestContext $internalRequestContext
Definition: AbstractLocalizedPagesTestCase.php:42
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: AbstractLocalizedPagesTestCase.php:30
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\$siteTitle
‪string $siteTitle
Definition: AbstractLocalizedPagesTestCase.php:38
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\tearDown
‪tearDown()
Definition: AbstractLocalizedPagesTestCase.php:80