‪TYPO3CMS  ‪main
ScenarioDTest.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;
22 
50 {
51  protected function ‪setUp(): void
52  {
53  parent::setUp();
54 
56  'acme-com',
57  $this->‪buildSiteConfiguration(1000, 'https://acme.com/'),
58  [
59  $this->‪buildDefaultLanguageConfiguration('EN', 'https://acme.com/en'),
60  $this->‪buildLanguageConfiguration('DE', 'https://acme.com/de'),
61  $this->‪buildLanguageConfiguration('DE-CH', 'https://acme.com/de-ch', ['DE', 'EN']),
62  ]
63  );
64 
65  $this->‪setUpDatabaseWithYamlPayload(__DIR__ . '/Fixtures/ScenarioD.yaml');
66  }
67 
68  public static function ‪resolvablePagesDataProvider(): array
69  {
70  return [
71  'home page in EN' => [
72  'url' => 'https://acme.com/en/hello',
73  'scopes' => [
74  'page/title' => 'EN: Welcome',
75  ],
76  ],
77  'about page in EN' => [
78  'url' => 'https://acme.com/en/about-us',
79  'scopes' => [
80  'page/title' => 'EN: About us',
81  ],
82  ],
83  'about page in DE where page translation exists' => [
84  'url' => 'https://acme.com/de/ueber-uns',
85  'scopes' => [
86  'page/title' => 'DE: Über uns',
87  ],
88  ],
89  'about page in DE-CH where page translation exists' => [
90  'url' => 'https://acme.com/de-ch/ueber-uns',
91  'scopes' => [
92  'page/title' => 'DE-CH: Über uns',
93  ],
94  ],
95  ];
96  }
97 
98  #[DataProvider('resolvablePagesDataProvider')]
99  #[Test]
100  public function ‪resolvedPagesMatchScopes(string ‪$url, array $scopes): void
101  {
102  $this->‪assertScopes($url, $scopes);
103  }
104 
105  public static function ‪pageNotFoundDataProvider(): array
106  {
107  return [
108  'home page in DE where page translation does not exist' => [
109  'url' => 'https://acme.com/de/hello',
110  ],
111  'home page in DE-CH where page translation does not exist and is trapped by l18n_cfg' => [
112  'url' => 'https://acme.com/de-ch/hello',
113  ],
114  'DE-CH shortcut to home page where page translation does not exist and is trapped by l18n_cfg' => [
115  'url' => 'https://acme.com/de-ch/shortcut-to-welcome',
116  ],
117  ];
118  }
119 
120  #[DataProvider('pageNotFoundDataProvider')]
121  #[Test]
122  public function ‪pageNotFound(string ‪$url): void
123  {
124  $this->‪assertResponseStatusCode($url);
125  }
126 
127  public static function ‪menuDataProvider(): array
128  {
129  return [
130  [
131  'url' => 'https://acme.com/en/hello',
132  'expectedMenu' => [
133  ['title' => 'EN: Welcome', 'link' => '/en/hello'],
134  ['title' => 'EN: About us', 'link' => '/en/about-us'],
135  ['title' => 'EN: Products', 'link' => '/en/products'],
136  ['title' => 'EN: Shortcut to welcome', 'link' => '/en/hello'],
137  ['title' => 'EN: Company', 'link' => '/en/company'],
138  ],
139  ],
140  [
141  'url' => 'https://acme.com/en/about-us',
142  'expectedMenu' => [
143  ['title' => 'EN: Welcome', 'link' => '/en/hello'],
144  ['title' => 'EN: About us', 'link' => '/en/about-us'],
145  ['title' => 'EN: Products', 'link' => '/en/products'],
146  ['title' => 'EN: Shortcut to welcome', 'link' => '/en/hello'],
147  ['title' => 'EN: Company', 'link' => '/en/company'],
148  ],
149  ],
150  [
151  'url' => 'https://acme.com/de/ueber-uns',
152  'expectedMenu' => [
153  ['title' => 'DE: Über uns', 'link' => '/de/ueber-uns'],
154  ['title' => 'DE: Unternehmen', 'link' => '/de/ueber-uns'],
155  ],
156  ],
157  [
158  'url' => 'https://acme.com/de-ch/ueber-uns',
159  'expectedMenu' => [
160  ['title' => 'DE-CH: Über uns', 'link' => '/de-ch/ueber-uns'],
161  ['title' => 'DE-CH: Produkte', 'link' => '/de-ch/produkte'],
162  ['title' => 'EN: Shortcut to welcome', 'link' => ''],
163  ['title' => 'DE-CH: Unternehmen', 'link' => '/de-ch/unternehmen'],
164  ],
165  ],
166  ];
167  }
168 
169  #[DataProvider('menuDataProvider')]
170  #[Test]
171  public function ‪pageMenuIsRendered(string ‪$url, array $expectedMenu): void
172  {
173  $this->‪assertMenu($url, $expectedMenu);
174  }
175 
176  #[Test]
178  {
179  $expectedMenu = [
180  ['title' => 'English', 'link' => '/en/company'],
181  ['title' => 'German', 'link' => '/de/ueber-uns'],
182  ['title' => 'Swiss German', 'link' => '/de-ch/unternehmen'],
183  ];
184 
185  self::assertSame($expectedMenu, $this->‪createLanguageMenu('https://acme.com/de-ch/unternehmen'));
186  }
187 }
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:108
‪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\ScenarioDTest
Definition: ScenarioDTest.php:50
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\AbstractLocalizedPagesTestCase\assertResponseStatusCode
‪assertResponseStatusCode(string $url)
Definition: AbstractLocalizedPagesTestCase.php:66
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪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\LocalizedPageRendering\ScenarioDTest\languageMenuHasLanguageShortcutsWithLanguageSpecificUrls
‪languageMenuHasLanguageShortcutsWithLanguageSpecificUrls()
Definition: ScenarioDTest.php:177
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\ScenarioDTest\resolvablePagesDataProvider
‪static resolvablePagesDataProvider()
Definition: ScenarioDTest.php:68
‪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\ScenarioDTest\pageNotFound
‪pageNotFound(string $url)
Definition: ScenarioDTest.php:122
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\ScenarioDTest\setUp
‪setUp()
Definition: ScenarioDTest.php:51
‪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
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\ScenarioDTest\pageNotFoundDataProvider
‪static pageNotFoundDataProvider()
Definition: ScenarioDTest.php:105
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\ScenarioDTest\pageMenuIsRendered
‪pageMenuIsRendered(string $url, array $expectedMenu)
Definition: ScenarioDTest.php:171
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\ScenarioDTest\menuDataProvider
‪static menuDataProvider()
Definition: ScenarioDTest.php:127
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling\LocalizedPageRendering\ScenarioDTest\resolvedPagesMatchScopes
‪resolvedPagesMatchScopes(string $url, array $scopes)
Definition: ScenarioDTest.php:100