‪TYPO3CMS  ‪main
SlugHelperUniqueTest.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\Test;
25 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
26 
27 final class ‪SlugHelperUniqueTest extends FunctionalTestCase
28 {
30 
31  private const ‪LANGUAGE_PRESETS = [
32  'EN' => ['id' => 0, 'title' => 'English', 'locale' => 'en_US.UTF8'],
33  ];
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->importCSVDataSet(__DIR__ . '/DataSet/PagesForSlugsUnique.csv');
39  $this->importCSVDataSet(__DIR__ . '/../../Fixtures/be_users_admin.csv');
41  'test',
42  $this->‪buildSiteConfiguration(1, 'http://localhost/'),
43  [
44  $this->‪buildDefaultLanguageConfiguration('EN', '/en/'),
45  ],
46  );
47  }
48 
49  #[Test]
51  {
52  $subject = GeneralUtility::makeInstance(
53  SlugHelper::class,
54  'pages',
55  'slug',
56  [
57  'generatorOptions' => [
58  'fields' => ['title'],
59  'prefixParentPageSlug' => true,
60  ],
61  ]
62  );
63  $state = ‪RecordStateFactory::forName('pages')->fromArray(['uid' => 'NEW102', 'pid' => 1]);
64  $overflowSlug = $subject->buildSlugForUniqueInSite('/unique-slug', $state);
65  $parts = explode('-', $overflowSlug);
66  if (count($parts) !== 3) {
67  self::fail('No suffix to the slug was created');
68  }
69  $variablePartOfSlug = end($parts);
70  self::assertSame(32, strlen($variablePartOfSlug));
71  }
72 
73  #[Test]
75  {
76  $subject = GeneralUtility::makeInstance(
77  SlugHelper::class,
78  'pages',
79  'slug',
80  [
81  'generatorOptions' => [
82  'fields' => ['title'],
83  'prefixParentPageSlug' => true,
84  ],
85  ]
86  );
87  $state = ‪RecordStateFactory::forName('pages')->fromArray(['uid' => 'NEW102', 'pid' => 1]);
88  $overflowSlug = $subject->buildSlugForUniqueInPid('/unique-slug', $state);
89  $parts = explode('-', $overflowSlug);
90  if (count($parts) !== 3) {
91  self::fail('No suffix to the slug was created');
92  }
93  $variablePartOfSlug = end($parts);
94  self::assertSame(32, strlen($variablePartOfSlug));
95  }
96 
97  #[Test]
99  {
100  $subject = GeneralUtility::makeInstance(
101  SlugHelper::class,
102  'pages',
103  'slug',
104  [
105  'generatorOptions' => [
106  'fields' => ['title'],
107  'prefixParentPageSlug' => true,
108  ],
109  ]
110  );
111  $state = ‪RecordStateFactory::forName('pages')->fromArray(['uid' => 'NEW102', 'pid' => 1]);
112  $overflowSlug = $subject->buildSlugForUniqueInTable('/unique-slug', $state);
113  $parts = explode('-', $overflowSlug);
114  if (count($parts) !== 3) {
115  self::fail('No suffix to the slug was created');
116  }
117  $variablePartOfSlug = end($parts);
118  self::assertSame(32, strlen($variablePartOfSlug));
119  }
120 }
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug
Definition: SlugHelperTest.php:18
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait
Definition: SiteBasedTestTrait.php:37
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\writeSiteConfiguration
‪writeSiteConfiguration(string $identifier, array $site=[], array $languages=[], array $errorHandling=[])
Definition: SiteBasedTestTrait.php:50
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildSiteConfiguration
‪buildSiteConfiguration(int $rootPageId, string $base='')
Definition: SiteBasedTestTrait.php:88
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\LANGUAGE_PRESETS
‪const LANGUAGE_PRESETS
Definition: SlugHelperUniqueTest.php:30
‪TYPO3\CMS\Core\DataHandling\Model\RecordStateFactory
Definition: RecordStateFactory.php:26
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest
Definition: SlugHelperUniqueTest.php:28
‪TYPO3\CMS\Core\DataHandling\SlugHelper
Definition: SlugHelper.php:43
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\buildSlugForUniqueInSiteRespectsMaxRetryOverflow
‪buildSlugForUniqueInSiteRespectsMaxRetryOverflow()
Definition: SlugHelperUniqueTest.php:49
‪TYPO3\CMS\Core\Tests\Functional\SiteHandling\SiteBasedTestTrait\buildDefaultLanguageConfiguration
‪buildDefaultLanguageConfiguration(string $identifier, string $base)
Definition: SiteBasedTestTrait.php:98
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\buildSlugForUniqueInTableRespectsMaxRetryOverflow
‪buildSlugForUniqueInTableRespectsMaxRetryOverflow()
Definition: SlugHelperUniqueTest.php:97
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\buildSlugForUniqueInPidRespectsMaxRetryOverflow
‪buildSlugForUniqueInPidRespectsMaxRetryOverflow()
Definition: SlugHelperUniqueTest.php:73
‪TYPO3\CMS\Core\Tests\Functional\DataHandling\Slug\SlugHelperUniqueTest\setUp
‪setUp()
Definition: SlugHelperUniqueTest.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\DataHandling\Model\RecordStateFactory\forName
‪static forName(string $name)
Definition: RecordStateFactory.php:29