‪TYPO3CMS  9.5
SlugHelperTest.php
Go to the documentation of this file.
1 <?php
2 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 
18 use Symfony\Component\Yaml\Yaml;
23 
28 {
32  protected ‪$scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Slug/DataSet/';
33 
38  protected ‪$siteLanguageConfiguration = [
39  1 => [
40  'title' => 'Dansk',
41  'enabled' => true,
42  'languageId' => 1,
43  'base' => '/dk/',
44  'typo3Language' => 'dk',
45  'locale' => 'da_DK.UTF-8',
46  'iso-639-1' => 'da',
47  'flag' => 'dk',
48  'fallbackType' => 'fallback',
49  'fallbacks' => '0'
50  ],
51  2 => [
52  'title' => 'Deutsch',
53  'enabled' => true,
54  'languageId' => 2,
55  'base' => '/de/',
56  'typo3Language' => 'de',
57  'locale' => 'de_DE.UTF-8',
58  'iso-639-1' => 'de',
59  'flag' => 'de',
60  'fallbackType' => 'fallback',
61  'fallbacks' => '0'
62  ],
63  3 => [
64  'title' => 'Schweizer Deutsch',
65  'enabled' => true,
66  'languageId' => 3,
67  'base' => '/de-ch/',
68  'typo3Language' => 'ch',
69  'locale' => 'de_CH.UTF-8',
70  'iso-639-1' => 'ch',
71  'flag' => 'ch',
72  'fallbackType' => 'fallback',
73  'fallbacks' => '2,0'
74  ],
75  ];
76 
77  protected function ‪setUp(): void
78  {
79  parent::setUp();
80 
81  $this->‪importScenarioDataSet('Pages');
82  $this->‪setUpFrontendSite(1, $this->siteLanguageConfiguration);
83  $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
84  }
85 
93  protected function ‪setUpFrontendSite(int $pageId, array $additionalLanguages = [])
94  {
95  $languages = [
96  0 => [
97  'title' => 'English',
98  'enabled' => true,
99  'languageId' => 0,
100  'base' => '/',
101  'typo3Language' => 'default',
102  'locale' => 'en_US.UTF-8',
103  'iso-639-1' => 'en',
104  'navigationTitle' => '',
105  'hreflang' => '',
106  'direction' => '',
107  'flag' => 'us',
108  ]
109  ];
110  $languages = array_merge($languages, $additionalLanguages);
111  $configuration = [
112  'rootPageId' => $pageId,
113  'base' => '/',
114  'languages' => $languages,
115  'errorHandling' => [],
116  'routes' => [],
117  ];
118  GeneralUtility::mkdir_deep($this->instancePath . '/typo3conf/sites/testing/');
119  $yamlFileContents = Yaml::dump($configuration, 99, 2);
120  $fileName = $this->instancePath . '/typo3conf/sites/testing/config.yaml';
121  GeneralUtility::writeFile($fileName, $yamlFileContents);
122  // Ensure that no other site configuration was cached before
123  $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
124  if ($cache->has('site-configuration')) {
125  $cache->remove('site-configuration');
126  }
127  }
128 
144  {
145  return [
146  'default page / default parent' => [
147  '/default-parent/default-page',
148  [
149  'uid' => '13',
150  'title' => 'Default Page',
151  'sys_language_uid' => 0
152  ]
153  ],
154  'Dansk page / default parent' => [
155  '/default-parent/dansk-page',
156  [
157  'uid' => '13',
158  'title' => 'Dansk Page',
159  'sys_language_uid' => 1
160  ],
161  ],
162  'german page / german parent' => [
163  '/german-parent/german-page',
164  [
165  'uid' => '13',
166  'title' => 'German Page',
167  'sys_language_uid' => 2
168  ]
169  ],
170  'swiss page / german fallback parent' => [
171  '/german-parent/swiss-page',
172  [
173  'uid' => '13',
174  'title' => 'Swiss Page',
175  'sys_language_uid' => 3
176  ],
177  ],
178  ];
179  }
180 
187  public function ‪generateRespectsFallbackLanguageOfParentPageSlug(string $expected, array $page)
188  {
189  $slugHelper = GeneralUtility::makeInstance(
190  SlugHelper::class,
191  'pages',
192  'slug',
193  [
194  'generatorOptions' => [
195  'fields' => ['title'],
196  'prefixParentPageSlug' => true,
197  ],
198  ]
199  );
200 
201  self::assertEquals(
202  $expected,
203  $slugHelper->generate(
204  [
205  'title' => $page['title'],
206  'uid' => $page['uid'],
207  'sys_language_uid' => $page['sys_language_uid']
208  ],
209  (int)$page['uid']
210  )
211  );
212  }
213 }
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperTest
Definition: SlugHelperTest.php:28
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperTest\setUp
‪setUp()
Definition: SlugHelperTest.php:75
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperTest\$siteLanguageConfiguration
‪array $siteLanguageConfiguration
Definition: SlugHelperTest.php:36
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug
Definition: SlugHelperTest.php:3
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperTest\setUpFrontendSite
‪setUpFrontendSite(int $pageId, array $additionalLanguages=[])
Definition: SlugHelperTest.php:91
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
Definition: AbstractDataHandlerActionTestCase.php:33
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperTest\generateRespectsFallbackLanguageOfParentPageSlug
‪generateRespectsFallbackLanguageOfParentPageSlug(string $expected, array $page)
Definition: SlugHelperTest.php:185
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperTest\$scenarioDataSetDirectory
‪string $scenarioDataSetDirectory
Definition: SlugHelperTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperTest\generateRespectsFallbackLanguageOfParentPageSlugDataProvider
‪array generateRespectsFallbackLanguageOfParentPageSlugDataProvider()
Definition: SlugHelperTest.php:141
‪TYPO3\CMS\Core\DataHandling\SlugHelper
Definition: SlugHelper.php:36
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\importScenarioDataSet
‪importScenarioDataSet($dataSetName)
Definition: AbstractDataHandlerActionTestCase.php:117