‪TYPO3CMS  9.5
SlugUniqueTest.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 Symfony\Component\Yaml\Yaml;
25 
30 {
31  protected function ‪setUp(): void
32  {
33  parent::setUp();
34  $this->‪setUpFrontendSite(1);
35  }
36 
44  protected function ‪setUpFrontendSite(int $pageId, array $additionalLanguages = [])
45  {
46  $languages = [
47  0 => [
48  'title' => 'English',
49  'enabled' => true,
50  'languageId' => 0,
51  'base' => '/',
52  'typo3Language' => 'default',
53  'locale' => 'en_US.UTF-8',
54  'iso-639-1' => 'en',
55  'navigationTitle' => '',
56  'hreflang' => '',
57  'direction' => '',
58  'flag' => 'us',
59  ]
60  ];
61  $languages = array_merge($languages, $additionalLanguages);
62  $configuration = [
63  'rootPageId' => $pageId,
64  'base' => '/',
65  'languages' => $languages,
66  'errorHandling' => [],
67  'routes' => [],
68  ];
69  GeneralUtility::mkdir_deep($this->instancePath . '/typo3conf/sites/testing/');
70  $yamlFileContents = Yaml::dump($configuration, 99, 2);
71  $fileName = $this->instancePath . '/typo3conf/sites/testing/config.yaml';
72  GeneralUtility::writeFile($fileName, $yamlFileContents);
73  // Ensure that no other site configuration was cached before
74  $cache = GeneralUtility::makeInstance(CacheManager::class)->getCache('cache_core');
75  if ($cache->has('site-configuration')) {
76  $cache->remove('site-configuration');
77  }
78  }
79 
84  public function ‪getEvalSettingDataProvider(): array
85  {
86  return [
87  'uniqueInSite' => ['uniqueInSite'],
88  'unique' => ['unique'],
89  'uniqueInPid' => ['uniqueInPid'],
90  ];
91  }
92 
98  public function ‪differentUniqueEvalSettingsDeDuplicateSlug(string $uniqueSetting): void
99  {
100  $this->importCSVDataSet(__DIR__ . '/DataSet/TestSlugUniqueBase.csv');
101  ‪$GLOBALS['TCA']['pages']['columns']['slug']['config']['eval'] = $uniqueSetting;
102  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
103  $dataHandler->enableLogging = false;
104  $dataHandler->start(
105  [
106  'pages' => [
107  3 => [
108  'title' => 'Page One',
109  'slug' => 'page-one',
110  ],
111  ],
112  ],
113  []
114  );
115  $dataHandler->process_datamap();
116  $this->assertCSVDataSet('typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TestSlugUniqueResult.csv');
117  }
118 
124  public function ‪currentRecordIsExcludedWhenDeDuplicateSlug(string $uniqueSetting): void
125  {
126  $this->importCSVDataSet(__DIR__ . '/DataSet/TestSlugUniqueWithDeduplicatedSlugBase.csv');
127  ‪$GLOBALS['TCA']['pages']['columns']['slug']['config']['eval'] = $uniqueSetting;
128  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
129  $dataHandler->enableLogging = false;
130  $dataHandler->start(
131  [
132  'pages' => [
133  3 => [
134  'slug' => 'page-one-1',
135  ],
136  ],
137  ],
138  []
139  );
140  $dataHandler->process_datamap();
141 
142  $this->assertCSVDataSet('typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TestSlugUniqueResult.csv');
143  }
144 
150  public function ‪differentUniqueEvalSettingsDeDuplicateSlugWhenCreatingNewRecords(string $uniqueSetting): void
151  {
152  $this->importCSVDataSet(__DIR__ . '/DataSet/TestSlugUniqueBase.csv');
153  ‪$GLOBALS['TCA']['pages']['columns']['slug']['config']['eval'] = $uniqueSetting;
154  $dataHandler = GeneralUtility::makeInstance(DataHandler::class);
155  $dataHandler->enableLogging = false;
156  $dataHandler->start(
157  [
158  'pages' => [
159  'NEW-1' => [
160  'pid' => 1,
161  'title' => 'Page Two',
162  'slug' => '',
163  ],
164  ],
165  ],
166  []
167  );
168  $dataHandler->process_datamap();
169 
170  $this->assertCSVDataSet('typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TestSlugUniqueNewRecordResult.csv');
171  }
172 }
‪TYPO3\CMS\Core\DataHandling\DataHandler
Definition: DataHandler.php:81
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\SlugUniqueTest\differentUniqueEvalSettingsDeDuplicateSlugWhenCreatingNewRecords
‪differentUniqueEvalSettingsDeDuplicateSlugWhenCreatingNewRecords(string $uniqueSetting)
Definition: SlugUniqueTest.php:150
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler
Definition: DefaultValuesTest.php:17
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\SlugUniqueTest\setUp
‪setUp()
Definition: SlugUniqueTest.php:31
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\SlugUniqueTest\setUpFrontendSite
‪setUpFrontendSite(int $pageId, array $additionalLanguages=[])
Definition: SlugUniqueTest.php:44
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\SlugUniqueTest\differentUniqueEvalSettingsDeDuplicateSlug
‪differentUniqueEvalSettingsDeDuplicateSlug(string $uniqueSetting)
Definition: SlugUniqueTest.php:98
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
Definition: AbstractDataHandlerActionTestCase.php:33
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\SlugUniqueTest
Definition: SlugUniqueTest.php:30
‪TYPO3\CMS\Core\Cache\CacheManager
Definition: CacheManager.php:34
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\SlugUniqueTest\getEvalSettingDataProvider
‪array getEvalSettingDataProvider()
Definition: SlugUniqueTest.php:84
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\DataHandler\SlugUniqueTest\currentRecordIsExcludedWhenDeDuplicateSlug
‪currentRecordIsExcludedWhenDeDuplicateSlug(string $uniqueSetting)
Definition: SlugUniqueTest.php:124
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45