‪TYPO3CMS  ‪main
LinkGeneratorFreeModeTest.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;
23 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerFactory;
24 use TYPO3\TestingFramework\Core\Functional\Framework\DataHandling\Scenario\DataHandlerWriter;
25 use TYPO3\TestingFramework\Core\Functional\Framework\Frontend\InternalRequest;
26 
31 {
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35 
37  'acme-com',
38  $this->‪buildSiteConfiguration(1000, 'https://acme.com/'),
39  [
40  $this->‪buildDefaultLanguageConfiguration('EN', 'https://acme.us/'),
41  $this->‪buildLanguageConfiguration('FR', 'https://acme.fr/', [], 'free'),
42  $this->‪buildLanguageConfiguration('FR-CA', 'https://acme.ca/', ['FR', 'EN']),
43  ]
44  );
46  'products-acme-com',
47  $this->‪buildSiteConfiguration(1300, 'https://products.acme.com/')
48  );
50  'blog-acme-com',
51  $this->‪buildSiteConfiguration(2000, 'https://blog.acme.com/')
52  );
54  'john-blog-acme-com',
55  $this->‪buildSiteConfiguration(2110, 'https://blog.acme.com/john/')
56  );
58  'jane-blog-acme-com',
59  $this->‪buildSiteConfiguration(2120, 'https://blog.acme.com/jane/')
60  );
62  'archive-acme-com',
63  $this->‪buildSiteConfiguration(3000, 'https://archive.acme.com/'),
64  [
65  $this->‪buildDefaultLanguageConfiguration('EN', '/'),
66  $this->‪buildLanguageConfiguration('FR', 'https://archive.acme.com/fr/', ['EN']),
67  $this->‪buildLanguageConfiguration('FR-CA', 'https://archive.acme.com/ca/', ['FR', 'EN']),
68  ]
69  );
71  'common-collection',
72  $this->‪buildSiteConfiguration(7000, 'https://common.acme.com/')
73  );
75  'usual-collection',
76  $this->‪buildSiteConfiguration(8000, 'https://usual.acme.com/')
77  );
78 
79  $this->withDatabaseSnapshot(
80  function () {
81  $this->importCSVDataSet(__DIR__ . '/../Fixtures/be_users.csv');
82  $backendUser = $this->setUpBackendUser(1);
83  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
84  $scenarioFile = __DIR__ . '/Fixtures/SlugScenario.yaml';
85  $factory = DataHandlerFactory::fromYamlFile($scenarioFile);
86  $writer = DataHandlerWriter::withBackendUser($backendUser);
87  $writer->invokeFactory($factory);
88  static::failIfArrayIsNotEmpty($writer->getErrors());
89  $this->setUpFrontendRootPage(1000, ['EXT:frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'], ['title' => 'ACME Root']);
90  $this->setUpFrontendRootPage(2000, ['EXT:frontend/Tests/Functional/SiteHandling/Fixtures/LinkGenerator.typoscript'], ['title' => 'ACME Blog']);
91  },
92  function () {
93  $backendUser = $this->setUpBackendUser(1);
94  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
95  }
96  );
97  }
98 
99  public static function ‪linkIsGeneratedForLanguageDataProvider(): array
100  {
101  $instructions = [
102  // acme.com -> acme.com (same site)
103  ['https://acme.us/', 1100, 1100, 0, '/welcome'],
104  ['https://acme.us/', 1100, 1100, 1, 'https://acme.fr/bienvenue'],
105  ['https://acme.us/', 1100, 1101, 0, 'https://acme.fr/bienvenue'],
106  ['https://acme.us/', 1100, 1102, 0, 'https://acme.ca/bienvenue'],
107  // acme.com -> products.acme.com (nested sub-site)
108  ['https://acme.us/', 1100, 1300, 0, 'https://products.acme.com/products'],
109  ['https://acme.us/', 1100, 1310, 0, 'https://products.acme.com/products/planets'],
110  // acme.com -> products.acme.com (nested sub-site, l18n_cfg=1)
111  ['https://acme.us/', 1100, 1410, 0, ''],
112  ['https://acme.us/', 1100, 1410, 1, 'https://acme.fr/acme-dans-votre-region/groupes'],
113  ['https://acme.us/', 1100, 1411, 0, 'https://acme.fr/acme-dans-votre-region/groupes'],
114  ['https://acme.us/', 1100, 1412, 0, 'https://acme.ca/acme-dans-votre-quebec/groupes'],
115  // acme.com -> archive (outside site)
116  ['https://acme.us/', 1100, 3100, 0, 'https://archive.acme.com/statistics'],
117  ['https://acme.us/', 1100, 3100, 1, 'https://archive.acme.com/fr/statistics'],
118  ['https://acme.us/', 1100, 3101, 0, 'https://archive.acme.com/fr/statistics'],
119  ['https://acme.us/', 1100, 3102, 0, 'https://archive.acme.com/ca/statistics'],
120  // blog.acme.com -> acme.com (different site)
121  ['https://blog.acme.com/', 2100, 1100, 0, 'https://acme.us/welcome'],
122  ['https://blog.acme.com/', 2100, 1100, 1, 'https://acme.fr/bienvenue'],
123  ['https://blog.acme.com/', 2100, 1101, 0, 'https://acme.fr/bienvenue'],
124  ['https://blog.acme.com/', 2100, 1102, 0, 'https://acme.ca/bienvenue'],
125  // blog.acme.com -> archive (outside site)
126  ['https://blog.acme.com/', 2100, 3100, 0, 'https://archive.acme.com/statistics'],
127  ['https://blog.acme.com/', 2100, 3100, 1, 'https://archive.acme.com/fr/statistics'],
128  ['https://blog.acme.com/', 2100, 3101, 0, 'https://archive.acme.com/fr/statistics'],
129  ['https://blog.acme.com/', 2100, 3102, 0, 'https://archive.acme.com/ca/statistics'],
130  // blog.acme.com -> products.acme.com (different sub-site)
131  ['https://blog.acme.com/', 2100, 1300, 0, 'https://products.acme.com/products'],
132  ['https://blog.acme.com/', 2100, 1310, 0, 'https://products.acme.com/products/planets'],
133  ];
134  return self::keysFromTemplate($instructions, '%2$d->%3$d (lang:%4$d)');
135  }
136 
137  #[DataProvider('linkIsGeneratedForLanguageDataProvider')]
138  #[Test]
139  public function ‪linkIsGeneratedForLanguageWithLanguageProperty(string $hostPrefix, int $sourcePageId, int $targetPageId, int $targetLanguageId, string $expectation): void
140  {
141  $response = $this->executeFrontendSubRequest(
142  (new InternalRequest($hostPrefix))
143  ->withPageId($sourcePageId)
144  ->withInstructions([
145  $this->createTypoLinkUrlInstruction([
146  'parameter' => $targetPageId,
147  'language' => $targetLanguageId,
148  ]),
149  ])
150  );
151 
152  self::assertSame($expectation, (string)$response->getBody());
153  }
154 
155  public static function ‪languageMenuIsGeneratedDataProvider(): array
156  {
157  return [
158  'ACME Inc (EN)' => [
159  'https://acme.us/',
160  1100,
161  [
162  ['title' => 'English', 'link' => '/welcome', 'active' => 1, 'current' => 0, 'available' => 1],
163  ['title' => 'French', 'link' => 'https://acme.fr/bienvenue', 'active' => 0, 'current' => 0, 'available' => 1],
164  ['title' => 'Franco-Canadian', 'link' => 'https://acme.ca/bienvenue', 'active' => 0, 'current' => 0, 'available' => 1],
165  ],
166  ],
167  'ACME Inc (FR)' => [
168  'https://acme.fr/',
169  1100,
170  [
171  ['title' => 'English', 'link' => 'https://acme.us/welcome', 'active' => 0, 'current' => 0, 'available' => 1],
172  ['title' => 'French', 'link' => '/bienvenue', 'active' => 1, 'current' => 0, 'available' => 1],
173  ['title' => 'Franco-Canadian', 'link' => 'https://acme.ca/bienvenue', 'active' => 0, 'current' => 0, 'available' => 1],
174  ],
175  ],
176  ];
177  }
178 
179  #[DataProvider('languageMenuIsGeneratedDataProvider')]
180  #[Test]
181  public function ‪languageMenuIsGenerated(string $hostPrefix, int $sourcePageId, array $expectation): void
182  {
183  $response = $this->executeFrontendSubRequest(
184  (new InternalRequest($hostPrefix))
185  ->withPageId($sourcePageId)
186  ->withInstructions([
187  $this->createLanguageMenuProcessorInstruction([
188  'languages' => 'auto',
189  ]),
190  ])
191  );
192 
193  $json = json_decode((string)$response->getBody(), true);
194  $json = $this->filterMenu($json, ['title', 'link', 'available', 'active', 'current']);
195 
196  self::assertSame($expectation, $json);
197  }
198 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildLanguageConfiguration
‪buildLanguageConfiguration(string $identifier, string $base, array $fallbackIdentifiers=[], string $fallbackType=null)
Definition: SiteBasedTestTrait.php:108
‪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\AbstractTestCase
Definition: AbstractTestCase.php:29
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Frontend\Tests\Functional\SiteHandling
Definition: AbstractTestCase.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25