‪TYPO3CMS  10.4
SlugHelperUniqueTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
7 /*
8  * This file is part of the TYPO3 CMS project.
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
24 
26 {
30  protected ‪$scenarioDataSetDirectory = 'typo3/sysext/core/Tests/Functional/DataHandling/Slug/DataSet/';
31 
32  protected function ‪setUp(): void
33  {
34  parent::setUp();
35 
36  $this->‪importScenarioDataSet('PagesForSlugsUnique');
37  $this->‪setUpFrontendSite(1);
38  $this->setUpFrontendRootPage(1, ['typo3/sysext/core/Tests/Functional/Fixtures/Frontend/JsonRenderer.typoscript']);
39  }
40 
45  {
46  $subject = GeneralUtility::makeInstance(
47  SlugHelper::class,
48  'pages',
49  'slug',
50  [
51  'generatorOptions' => [
52  'fields' => ['title'],
53  'prefixParentPageSlug' => true,
54  ],
55  ]
56  );
57 
58  $state = ‪RecordStateFactory::forName('pages')->fromArray(['uid' => 'NEW102', 'pid' => 1]);
59  $overflowSlug = $subject->buildSlugForUniqueInSite('/unique-slug', $state);
60  $parts = explode('-', $overflowSlug);
61  if (count($parts) !== 3) {
62  self::fail('No suffix to the slug was created');
63  }
64  $variablePartOfSlug = end($parts);
65  // shordMd5 return value is 10 chars long, so we can use this to assure the function has been called and returned a value
66  self::assertSame(10, strlen($variablePartOfSlug));
67  }
68 
73  {
74  $subject = GeneralUtility::makeInstance(
75  SlugHelper::class,
76  'pages',
77  'slug',
78  [
79  'generatorOptions' => [
80  'fields' => ['title'],
81  'prefixParentPageSlug' => true,
82  ],
83  ]
84  );
85  $state = ‪RecordStateFactory::forName('pages')->fromArray(['uid' => 'NEW102', 'pid' => 1]);
86  $overflowSlug = $subject->buildSlugForUniqueInPid('/unique-slug', $state);
87  $parts = explode('-', $overflowSlug);
88  if (count($parts) !== 3) {
89  self::fail('No suffix to the slug was created');
90  }
91  $variablePartOfSlug = end($parts);
92  // shordMd5 return value is 10 chars long, so we can use this to assure the function has been called and returned a value
93  self::assertSame(10, strlen($variablePartOfSlug));
94  }
95 
100  {
101  $subject = GeneralUtility::makeInstance(
102  SlugHelper::class,
103  'pages',
104  'slug',
105  [
106  'generatorOptions' => [
107  'fields' => ['title'],
108  'prefixParentPageSlug' => true,
109  ],
110  ]
111  );
112 
113  $state = ‪RecordStateFactory::forName('pages')->fromArray(['uid' => 'NEW102', 'pid' => 1]);
114  $overflowSlug = $subject->buildSlugForUniqueInTable('/unique-slug', $state);
115  $parts = explode('-', $overflowSlug);
116  if (count($parts) !== 3) {
117  self::fail('No suffix to the slug was created');
118  }
119  $variablePartOfSlug = end($parts);
120  // shordMd5 return value is 10 chars long, so we can use this to assure the function has been called and returned a value
121  self::assertSame(10, strlen($variablePartOfSlug));
122  }
123 }
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug
Definition: SlugHelperTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\setUpFrontendSite
‪setUpFrontendSite(int $pageId, array $additionalLanguages=[])
Definition: AbstractDataHandlerActionTestCase.php:143
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase
Definition: AbstractDataHandlerActionTestCase.php:37
‪TYPO3\CMS\Core\DataHandling\Model\RecordStateFactory
Definition: RecordStateFactory.php:26
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\$scenarioDataSetDirectory
‪string $scenarioDataSetDirectory
Definition: SlugHelperUniqueTest.php:29
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest
Definition: SlugHelperUniqueTest.php:26
‪TYPO3\CMS\Core\DataHandling\SlugHelper
Definition: SlugHelper.php:42
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\buildSlugForUniqueInSiteRespectsMaxRetryOverflow
‪buildSlugForUniqueInSiteRespectsMaxRetryOverflow()
Definition: SlugHelperUniqueTest.php:43
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\buildSlugForUniqueInTableRespectsMaxRetryOverflow
‪buildSlugForUniqueInTableRespectsMaxRetryOverflow()
Definition: SlugHelperUniqueTest.php:98
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\buildSlugForUniqueInPidRespectsMaxRetryOverflow
‪buildSlugForUniqueInPidRespectsMaxRetryOverflow()
Definition: SlugHelperUniqueTest.php:71
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\setUp
‪setUp()
Definition: SlugHelperUniqueTest.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\DataHandling\Model\RecordStateFactory\forName
‪static static forName(string $name)
Definition: RecordStateFactory.php:35
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\AbstractDataHandlerActionTestCase\importScenarioDataSet
‪importScenarioDataSet($dataSetName)
Definition: AbstractDataHandlerActionTestCase.php:201