‪TYPO3CMS  9.5
AbstractLocalizedPagesTestCase.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
4 /*
5  * This file is part of TYPO3 GmbHs software toolkit.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * The TYPO3 project - inspiring people to share!
12  */
13 
15 
18 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
19 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
20 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
21 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequestContext;
22 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\ResponseContent;
23 
25 {
26  protected const ‪LANGUAGE_PRESETS = [
27  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8', 'iso' => 'en', 'hrefLang' => 'en-US', 'direction' => ''],
28  'DE' => ['id' => 1, 'title' => 'German', 'locale' => 'de_DE.UTF8', 'iso' => 'de', 'hrefLang' => 'de-DE', 'direction' => ''],
29  'DE-CH' => ['id' => 2, 'title' => 'Swiss German', 'locale' => 'de_CH.UTF8', 'iso' => 'de', 'hrefLang' => 'de-CH', 'direction' => ''],
30  ];
31 
35  protected ‪$siteTitle = 'A Company that Manufactures Everything Inc';
36 
41 
42  public static function ‪setUpBeforeClass(): void
43  {
44  parent::setUpBeforeClass();
45  static::initializeDatabaseSnapshot();
46  }
47 
48  public static function ‪tearDownAfterClass(): void
49  {
50  static::destroyDatabaseSnapshot();
51  parent::tearDownAfterClass();
52  }
53 
54  protected function ‪setUp(): void
55  {
56  parent::setUp();
57 
58  // these settings are forwarded to the frontend sub-request as well
59  $this->internalRequestContext = (new InternalRequestContext())
60  ->withGlobalSettings(['TYPO3_CONF_VARS' => static::TYPO3_CONF_VARS]);
61  }
62 
63  protected function ‪setUpDatabaseWithYamlPayload(string $pathToYamlFile): void
64  {
65  $this->withDatabaseSnapshot(function () use ($pathToYamlFile) {
66  $backendUser = $this->setUpBackendUserFromFixture(1);
68 
69  $factory = DataHandlerFactory::fromYamlFile($pathToYamlFile);
70  $writer = DataHandlerWriter::withBackendUser($backendUser);
71  $writer->invokeFactory($factory);
72  static::failIfArrayIsNotEmpty(
73  $writer->getErrors()
74  );
75  });
76  }
77 
78  protected function ‪tearDown(): void
79  {
80  unset($this->internalRequestContext);
81  parent::tearDown();
82  }
83 
88  protected function ‪assertScopes(string $url, array $scopes): void
89  {
90  $this->setUpFrontendRootPage(
91  1000,
92  ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript'],
93  [
94  'title' => 'ACME Root',
95  'sitetitle' => $this->siteTitle,
96  ]
97  );
98 
99  $response = $this->executeFrontendRequest(new InternalRequest($url), $this->internalRequestContext);
100  $responseStructure = ResponseContent::fromString((string)$response->getBody());
101 
102  foreach ($scopes as $scopePath => $expectedScopeValue) {
103  static::assertSame($expectedScopeValue, $responseStructure->getScopePath($scopePath));
104  }
105  }
106 
111  protected function ‪assertException(string $url, string $exception): void
112  {
113  $this->setUpFrontendRootPage(
114  1000,
115  ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']
116  );
117 
118  $this->expectException($exception);
119  $this->executeFrontendRequest(new InternalRequest($url), $this->internalRequestContext);
120  }
121 
126  protected function ‪assertMenu(string $url, array $expectation): void
127  {
128  $this->setUpFrontendRootPage(
129  1000,
130  ['typo3/sysext/frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'],
131  [
132  'title' => 'ACME Root',
133  'sitetitle' => $this->siteTitle,
134  ]
135  );
136 
137  $response = $this->executeFrontendRequest(
138  (new InternalRequest($url))
139  ->withInstructions([
140  $this->createHierarchicalMenuProcessorInstruction([
141  'levels' => 1,
142  'entryLevel' => 0,
143  'expandAll' => 1,
144  'includeSpacer' => 1,
145  'titleField' => 'title',
146  'as' => 'results',
147  ]),
148  ]),
149  $this->internalRequestContext
150  );
151 
152  $json = json_decode((string)$response->getBody(), true);
153  $json = $this->filterMenu($json);
154 
155  static::assertSame($expectation, $json);
156  }
157 }
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertScopes
‪assertScopes(string $url, array $scopes)
Definition: AbstractLocalizedPagesTestCase.php:86
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertException
‪assertException(string $url, string $exception)
Definition: AbstractLocalizedPagesTestCase.php:109
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUpBeforeClass
‪static setUpBeforeClass()
Definition: AbstractLocalizedPagesTestCase.php:40
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering
Definition: AbstractLocalizedPagesTestCase.php:14
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase
Definition: AbstractLocalizedPagesTestCase.php:25
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUp
‪setUp()
Definition: AbstractLocalizedPagesTestCase.php:52
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\tearDownAfterClass
‪static tearDownAfterClass()
Definition: AbstractLocalizedPagesTestCase.php:46
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertMenu
‪assertMenu(string $url, array $expectation)
Definition: AbstractLocalizedPagesTestCase.php:124
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\setUpDatabaseWithYamlPayload
‪setUpDatabaseWithYamlPayload(string $pathToYamlFile)
Definition: AbstractLocalizedPagesTestCase.php:61
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\$internalRequestContext
‪InternalRequestContext $internalRequestContext
Definition: AbstractLocalizedPagesTestCase.php:38
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: AbstractLocalizedPagesTestCase.php:26
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\$siteTitle
‪string $siteTitle
Definition: AbstractLocalizedPagesTestCase.php:34
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\tearDown
‪tearDown()
Definition: AbstractLocalizedPagesTestCase.php:76
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static Bootstrap null initializeLanguageObject()
Definition: Bootstrap.php:986