‪TYPO3CMS  ‪main
SlugServiceTest.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;
21 use Psr\EventDispatcher\EventDispatcherInterface;
22 use Psr\Log\NullLogger;
23 use Symfony\Component\DependencyInjection\Container;
40 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
41 
47 final class ‪SlugServiceTest extends FunctionalTestCase
48 {
52  private ‪$subject;
53 
58 
59  private array ‪$languages = [
60  [
61  'title' => 'English',
62  'enabled' => true,
63  'languageId' => '0',
64  'base' => '/en/',
65  'locale' => 'en_US.UTF-8',
66  'navigationTitle' => 'English',
67  'flag' => 'us',
68  ],
69  [
70  'title' => 'German',
71  'enabled' => true,
72  'languageId' => '1',
73  'base' => 'https://de.example.com/',
74  'locale' => 'de_DE.UTF-8',
75  'navigationTitle' => 'German',
76  'flag' => 'de',
77  ],
78  [
79  'title' => 'Spanish',
80  'enabled' => true,
81  'languageId' => '2',
82  'base' => '/es/',
83  'locale' => 'es_ES.UTF-8',
84  'navigationTitle' => 'Spanish',
85  'flag' => 'es',
86  ],
87  ];
88 
89  protected array ‪$coreExtensionsToLoad = ['redirects'];
90 
91  protected function ‪setUp(): void
92  {
93  parent::setUp();
94  $this->correlationId = ‪CorrelationId::forScope(‪StringUtility::getUniqueId('test'));
95  $this->importCSVDataSet(__DIR__ . '/Fixtures/be_users.csv');
96  $backendUser = $this->setUpBackendUser(1);
97  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->createFromUserPreferences($backendUser);
98  }
99 
100  protected function ‪tearDown(): void
101  {
102  unset($this->subject, $this->correlationId);
103  parent::tearDown();
104  }
105 
112  #[Test]
114  {
115  $newPageSlug = '/test-new';
116  $this->‪buildBaseSite();
117  $this->‪createSubject();
118  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test1.csv');
119  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(2);
120  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
121  $this->subject->rebuildSlugsForSlugChange(2, $changeItem, $this->correlationId);
122  $this->‪setPageSlug(2, $newPageSlug);
123 
124  // These are the slugs after rebuildSlugsForSlugChange() has run
125  $slugs = [
126  '/',
127  '/test-new',
128  '/dummy-1-3',
129  '/dummy-1-4',
130  '/test-new/dummy-1-2-5',
131  '/test-new/dummy-1-2-6',
132  '/test-new/dummy-1-2-7',
133  '/dummy-1-3/dummy-1-3-8',
134  '/dummy-1-3/dummy-1-3-9',
135  '/dummy-1-4/dummy-1-4-10',
136  ];
137 
138  // This redirects should exist, after rebuildSlugsForSlugChange() has run
139  $redirects = [
140  ['source_host' => '*', 'source_path' => '/dummy-1-2', 'target' => 't3://page?uid=2&_language=0'],
141  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-5', 'target' => 't3://page?uid=5&_language=0'],
142  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-6', 'target' => 't3://page?uid=6&_language=0'],
143  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-7', 'target' => 't3://page?uid=7&_language=0'],
144  ];
145 
146  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
147  }
148 
155  #[Test]
157  {
158  $newPageSlug = '/new-home';
159  $this->‪buildBaseSite();
160  $this->‪createSubject();
161  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test2.csv');
162  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(1);
163  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
164  $this->subject->rebuildSlugsForSlugChange(1, $changeItem, $this->correlationId);
165  $this->‪setPageSlug(1, $newPageSlug);
166 
167  // These are the slugs after rebuildSlugsForSlugChange() has run
168  $slugs = [
169  '/new-home',
170  '/new-home/dummy-1-2',
171  '/new-home/dummy-1-3',
172  '/new-home/dummy-1-4',
173  '/new-home/dummy-1-2/dummy-1-2-5',
174  '/new-home/dummy-1-2/dummy-1-2-6',
175  '/new-home/dummy-1-2/dummy-1-2-7',
176  '/new-home/dummy-1-3/dummy-1-3-8',
177  '/new-home/dummy-1-3/dummy-1-3-9',
178  '/new-home/dummy-1-4/dummy-1-4-10',
179  ];
180 
181  // This redirects should exist, after rebuildSlugsForSlugChange() has run
182  $redirects = [
183  ['source_host' => '*', 'source_path' => '/', 'target' => 't3://page?uid=1&_language=0'],
184  ['source_host' => '*', 'source_path' => '/dummy-1-2', 'target' => 't3://page?uid=2&_language=0'],
185  ['source_host' => '*', 'source_path' => '/dummy-1-3', 'target' => 't3://page?uid=3&_language=0'],
186  ['source_host' => '*', 'source_path' => '/dummy-1-4', 'target' => 't3://page?uid=4&_language=0'],
187  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-5', 'target' => 't3://page?uid=5&_language=0'],
188  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-6', 'target' => 't3://page?uid=6&_language=0'],
189  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-7', 'target' => 't3://page?uid=7&_language=0'],
190  ['source_host' => '*', 'source_path' => '/dummy-1-3/dummy-1-3-8', 'target' => 't3://page?uid=8&_language=0'],
191  ['source_host' => '*', 'source_path' => '/dummy-1-3/dummy-1-3-9', 'target' => 't3://page?uid=9&_language=0'],
192  ['source_host' => '*', 'source_path' => '/dummy-1-4/dummy-1-4-10', 'target' => 't3://page?uid=10&_language=0'],
193  ];
194 
195  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
196  }
197 
204  #[Test]
206  {
207  $newPageSlug = '/test-new';
209  $this->‪createSubject();
210  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test1.csv');
211  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(2);
212  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
213  $this->subject->rebuildSlugsForSlugChange(2, $changeItem, $this->correlationId);
214  $this->‪setPageSlug(2, $newPageSlug);
215 
216  // These are the slugs after rebuildSlugsForSlugChange() has run
217  $slugs = [
218  '/',
219  '/test-new',
220  '/dummy-1-3',
221  '/dummy-1-4',
222  '/test-new/dummy-1-2-5',
223  '/test-new/dummy-1-2-6',
224  '/test-new/dummy-1-2-7',
225  '/dummy-1-3/dummy-1-3-8',
226  '/dummy-1-3/dummy-1-3-9',
227  '/dummy-1-4/dummy-1-4-10',
228  ];
229 
230  // This redirects should exists, after rebuildSlugsForSlugChange() has run
231  $redirects = [
232  ['source_host' => '*', 'source_path' => '/sub-folder/dummy-1-2', 'target' => 't3://page?uid=2&_language=0'],
233  ['source_host' => '*', 'source_path' => '/sub-folder/dummy-1-2/dummy-1-2-5', 'target' => 't3://page?uid=5&_language=0'],
234  ['source_host' => '*', 'source_path' => '/sub-folder/dummy-1-2/dummy-1-2-6', 'target' => 't3://page?uid=6&_language=0'],
235  ['source_host' => '*', 'source_path' => '/sub-folder/dummy-1-2/dummy-1-2-7', 'target' => 't3://page?uid=7&_language=0'],
236  ];
237 
238  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
239  }
240 
247  #[Test]
249  {
250  $newPageSlug = '/test-new';
252  $this->‪createSubject();
253  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test3.csv');
254  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(31);
255  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
256  $this->subject->rebuildSlugsForSlugChange(31, $changeItem, $this->correlationId);
257  $this->‪setPageSlug(31, $newPageSlug);
258 
259  // These are the slugs after rebuildSlugsForSlugChange() has run
260  $slugs = [
261  '/',
262  '/dummy-1-2',
263  '/test-new',
264  '/dummy-1-3',
265  '/dummy-1-4',
266  '/dummy-1-2/dummy-1-2-5',
267  '/dummy-1-2/dummy-1-2-6',
268  '/dummy-1-2/dummy-1-2-7',
269  '/dummy-1-3/dummy-1-3-8',
270  '/test-new/dummy-1-3-8',
271  '/dummy-1-3/dummy-1-3-9',
272  '/dummy-1-4/dummy-1-4-10',
273  ];
274 
275  // This redirects should exist, after rebuildSlugsForSlugChange() has run
276  $redirects = [
277  ['source_host' => 'de.example.com', 'source_path' => '/dummy-1-3', 'target' => 't3://page?uid=3&_language=1'],
278  ['source_host' => 'de.example.com', 'source_path' => '/dummy-1-3/dummy-1-3-8', 'target' => 't3://page?uid=8&_language=1'],
279  ];
280 
281  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
282  }
283 
290  #[Test]
292  {
293  $newPageSlug = '/test-new';
295  $this->‪createSubject();
296  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test3.csv');
297  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(31);
298  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
299  $this->subject->rebuildSlugsForSlugChange(31, $changeItem, $this->correlationId);
300  $this->‪setPageSlug(31, $newPageSlug);
301 
302  // These are the slugs after rebuildSlugsForSlugChange() has run
303  $slugs = [
304  '/',
305  '/dummy-1-2',
306  '/test-new',
307  '/dummy-1-3',
308  '/dummy-1-4',
309  '/dummy-1-2/dummy-1-2-5',
310  '/dummy-1-2/dummy-1-2-6',
311  '/dummy-1-2/dummy-1-2-7',
312  '/dummy-1-3/dummy-1-3-8',
313  '/test-new/dummy-1-3-8',
314  '/dummy-1-3/dummy-1-3-9',
315  '/dummy-1-4/dummy-1-4-10',
316  ];
317 
318  // This redirects should exist, after rebuildSlugsForSlugChange() has run
319  $redirects = [
320  ['source_host' => 'de.example.com', 'source_path' => '/sub-folder/dummy-1-3', 'target' => 't3://page?uid=3&_language=1'],
321  ['source_host' => 'de.example.com', 'source_path' => '/sub-folder/dummy-1-3/dummy-1-3-8', 'target' => 't3://page?uid=8&_language=1'],
322  ];
323 
324  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
325  }
326 
333  #[Test]
335  {
336  $newPageSlug = '/test-new';
338  $this->‪createSubject();
339  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test3.csv');
340  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(3);
341  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
342  $this->subject->rebuildSlugsForSlugChange(3, $changeItem, $this->correlationId);
343  $this->‪setPageSlug(3, $newPageSlug);
344 
345  // These are the slugs after rebuildSlugsForSlugChange() has run
346  $slugs = [
347  '/',
348  '/dummy-1-2',
349  '/test-new',
350  '/dummy-1-3',
351  '/dummy-1-4',
352  '/dummy-1-2/dummy-1-2-5',
353  '/dummy-1-2/dummy-1-2-6',
354  '/dummy-1-2/dummy-1-2-7',
355  '/dummy-1-3/dummy-1-3-8',
356  '/test-new/dummy-1-3-8',
357  '/test-new/dummy-1-3-9',
358  '/dummy-1-4/dummy-1-4-10',
359  ];
360 
361  // This redirects should exist, after rebuildSlugsForSlugChange() has run
362  $redirects = [
363  ['source_host' => '*', 'source_path' => '/sub-folder/en/dummy-1-3', 'target' => 't3://page?uid=3&_language=0'],
364  ['source_host' => '*', 'source_path' => '/sub-folder/en/dummy-1-3/dummy-1-3-8', 'target' => 't3://page?uid=8&_language=0'],
365  ['source_host' => '*', 'source_path' => '/sub-folder/en/dummy-1-3/dummy-1-3-9', 'target' => 't3://page?uid=9&_language=0'],
366  ];
367 
368  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
369  }
370 
377  #[Test]
379  {
380  $newPageSlug = '/test-new';
382  $this->‪createSubject();
383  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test4.csv');
384  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(5);
385  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
386  $this->subject->rebuildSlugsForSlugChange(5, $changeItem, $this->correlationId);
387  $this->‪setPageSlug(5, $newPageSlug);
388 
389  // These are the slugs after rebuildSlugsForSlugChange() has run
390  $slugs = [
391  '/',
392  '/dummy-1-2',
393  '/dummy-1-3',
394  '/dummy-1-2/dummy-1-2-3',
395  '/test-new',
396  '/test-new/dummy-1-2',
397  '/test-new/dummy-1-3',
398  '/test-new/dummy-1-2/dummy-1-2-3',
399  ];
400 
401  // This redirects should exist, after rebuildSlugsForSlugChange() has run
402  $redirects = [
403  ['source_host' => 'de.example.com', 'source_path' => '/', 'target' => 't3://page?uid=1&_language=1'],
404  ['source_host' => 'de.example.com', 'source_path' => '/dummy-1-2', 'target' => 't3://page?uid=2&_language=1'],
405  ['source_host' => 'de.example.com', 'source_path' => '/dummy-1-3', 'target' => 't3://page?uid=3&_language=1'],
406  ['source_host' => 'de.example.com', 'source_path' => '/dummy-1-2/dummy-1-2-3', 'target' => 't3://page?uid=4&_language=1'],
407  ];
408 
409  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
410  }
411 
412  #[Test]
414  {
415  $newPageSlug = '/test-new';
416  $eventOverrideSource = '/overridden-new';
418  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_ModifyAutoCreateRedirectRecordBeforePersistingEvent.csv');
419 
421  $container = $this->get('service_container');
422  $container->set(
423  'modify-auto-create-redirect-record-before-persisting',
424  static function (‪ModifyAutoCreateRedirectRecordBeforePersistingEvent $event) use (
425  &$modifyAutoCreateRedirectRecordBeforePersisting,
426  $eventOverrideSource
427  ) {
428  $modifyAutoCreateRedirectRecordBeforePersisting = $event;
429  $event->‪setRedirectRecord(
430  array_replace(
431  $event->‪getRedirectRecord(),
432  [
433  'source_path' => $eventOverrideSource,
434  ],
435  )
436  );
437  }
438  );
439  $listenerProvider = $container->get(ListenerProvider::class);
440  $listenerProvider->addListener(ModifyAutoCreateRedirectRecordBeforePersistingEvent::class, 'modify-auto-create-redirect-record-before-persisting');
441  $this->‪createSubject();
442 
444  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(2);
445  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
446  $this->subject->rebuildSlugsForSlugChange(2, $changeItem, $this->correlationId);
447  $this->‪setPageSlug(2, $newPageSlug);
448 
449  self::assertInstanceOf(ModifyAutoCreateRedirectRecordBeforePersistingEvent::class, $modifyAutoCreateRedirectRecordBeforePersisting);
450  self::assertSame($eventOverrideSource, $modifyAutoCreateRedirectRecordBeforePersisting->getRedirectRecord()['source_path']);
451 
453  slugs: [
454  '/',
455  $newPageSlug,
456  ],
457  redirects: [
458  ['source_host' => '*', 'source_path' => $eventOverrideSource, 'target' => 't3://page?uid=2&_language=0'],
459  ],
460  );
461  }
462 
463  #[Test]
465  {
466  $newPageSlug = '/test-new';
468  $this->importCSVDataSet(__DIR__ . '/Fixtures/SlugServiceTest_AfterAutoCreateRedirectHasBeenPersistedEvent.csv');
469 
471  $container = $this->get('service_container');
472  $container->set(
473  'after-auto-create-redirect-has-been-persisted',
474  static function (‪AfterAutoCreateRedirectHasBeenPersistedEvent $event) use (
475  &$afterAutoCreateRedirectHasBeenPersisted
476  ) {
477  $afterAutoCreateRedirectHasBeenPersisted = $event;
478  }
479  );
480  $listenerProvider = $container->get(ListenerProvider::class);
481  $listenerProvider->addListener(AfterAutoCreateRedirectHasBeenPersistedEvent::class, 'after-auto-create-redirect-has-been-persisted');
482  $this->‪createSubject();
483 
485  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(2);
486  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
487  $this->subject->rebuildSlugsForSlugChange(2, $changeItem, $this->correlationId);
488  $this->‪setPageSlug(2, $newPageSlug);
489 
490  self::assertInstanceOf(AfterAutoCreateRedirectHasBeenPersistedEvent::class, $afterAutoCreateRedirectHasBeenPersisted);
491  self::assertSame(1, $afterAutoCreateRedirectHasBeenPersisted->getRedirectRecord()['uid'] ?? null);
492 
494  slugs: [
495  '/',
496  $newPageSlug,
497  ],
498  redirects: [
499  ['uid' => 1, 'source_host' => '*', 'source_path' => '/en/dummy-1-2', 'target' => 't3://page?uid=2&_language=0'],
500  ],
501  withRedirectUid: true,
502  );
503  }
504 
505  #[Test]
507  {
508  $newPageSlug = '/test-new';
509  $this->‪buildBaseSite();
510  $this->‪createSubject();
511  $this->importCSVDataSet(__DIR__ . '/Fixtures/SysFolderSubPages_Test1.csv');
512  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(2);
513  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
514  $this->subject->rebuildSlugsForSlugChange(2, $changeItem, $this->correlationId);
515  $this->‪setPageSlug(2, $newPageSlug);
516 
517  // These are the slugs after rebuildSlugsForSlugChange() has run
518  $slugs = [
519  '/',
520  '/test-new',
521  '/dummy-1-3',
522  '/test-new/dummy-1-2-3',
523  ];
524 
525  // This redirects should exist, after rebuildSlugsForSlugChange() has run
526  $redirects = [
527  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-3', 'target' => 't3://page?uid=4&_language=0'],
528  ];
529  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
530  }
531 
532  #[Test]
534  {
535  $newPageSlug = '/test-new';
536  $this->‪buildBaseSite();
537  $this->‪createSubject();
538  $this->importCSVDataSet(__DIR__ . '/Fixtures/SpacerSubPages_Test1.csv');
539  $changeItem = $this->get(SlugRedirectChangeItemFactory::class)->create(2);
540  $changeItem = $changeItem->withChanged(array_merge($changeItem->getOriginal(), ['slug' => $newPageSlug]));
541  $this->subject->rebuildSlugsForSlugChange(2, $changeItem, $this->correlationId);
542  $this->‪setPageSlug(2, $newPageSlug);
543 
544  // These are the slugs after rebuildSlugsForSlugChange() has run
545  $slugs = [
546  '/',
547  '/test-new',
548  '/dummy-1-3',
549  '/test-new/dummy-1-2-3',
550  ];
551 
552  // This redirects should exist, after rebuildSlugsForSlugChange() has run
553  $redirects = [
554  ['source_host' => '*', 'source_path' => '/dummy-1-2/dummy-1-2-3', 'target' => 't3://page?uid=4&_language=0'],
555  ];
556  $this->‪assertSlugsAndRedirectsExists($slugs, $redirects);
557  }
558 
559  protected function ‪buildBaseSite(): void
560  {
561  $configuration = [
562  'rootPageId' => 1,
563  'base' => '/',
564  ];
565  $siteConfiguration = GeneralUtility::makeInstance(SiteConfiguration::class);
566  $siteConfiguration->write('testing', $configuration);
567  }
568 
569  protected function ‪buildBaseSiteInSubfolder(): void
570  {
571  $configuration = [
572  'rootPageId' => 1,
573  'base' => '/sub-folder',
574  ];
575  $siteConfiguration = GeneralUtility::makeInstance(SiteConfiguration::class);
576  $siteConfiguration->write('testing', $configuration);
577  }
578 
579  protected function ‪buildBaseSiteWithLanguages(): void
580  {
581  $configuration = [
582  'rootPageId' => 1,
583  'base' => '/',
584  'languages' => ‪$this->languages,
585  ];
586  $siteConfiguration = GeneralUtility::makeInstance(SiteConfiguration::class);
587  $siteConfiguration->write('testing', $configuration);
588  }
589 
590  protected function ‪buildBaseSiteWithLanguagesInSubFolder(): void
591  {
593  array_walk(‪$languages, static function (&$languageData) {
594  $languageData['base'] = (
595  !str_contains($languageData['base'], 'http')
596  ? $languageData['base']
597  : $languageData['base'] . 'sub-folder/'
598  );
599  });
600  $configuration = [
601  'rootPageId' => 1,
602  'base' => '/sub-folder',
603  'languages' => ‪$languages,
604  ];
605  $siteConfiguration = GeneralUtility::makeInstance(SiteConfiguration::class);
606  $siteConfiguration->write('testing', $configuration);
607  }
608 
609  protected function ‪createSubject(): void
610  {
611  GeneralUtility::makeInstance(SiteMatcher::class)->refresh();
612  $this->subject = new ‪SlugService(
613  context: GeneralUtility::makeInstance(Context::class),
614  pageRepository: GeneralUtility::makeInstance(PageRepository::class),
615  linkService: GeneralUtility::makeInstance(LinkService::class),
616  redirectCacheService: GeneralUtility::makeInstance(RedirectCacheService::class),
617  slugRedirectChangeItemFactory: $this->get(SlugRedirectChangeItemFactory::class),
618  eventDispatcher: $this->get(EventDispatcherInterface::class),
619  connectionPool: $this->getConnectionPool(),
620  );
621  $this->subject->setLogger(new NullLogger());
622  }
623 
624  protected function ‪assertSlugsAndRedirectsExists(array $slugs, array $redirects, bool $withRedirectUid = false): void
625  {
626  $pageRecords = $this->getAllRecords('pages');
627  self::assertCount(count($slugs), $pageRecords);
628  foreach ($pageRecords as ‪$record) {
629  self::assertContains(‪$record['slug'], $slugs, 'unexpected slug: ' . ‪$record['slug']);
630  }
631 
632  $redirectRecords = $this->getAllRecords('sys_redirect');
633  self::assertCount(count($redirects), $redirectRecords);
634  foreach ($redirectRecords as ‪$record) {
635  $combination = [
636  'source_host' => ‪$record['source_host'],
637  'source_path' => ‪$record['source_path'],
638  'target' => ‪$record['target'],
639  ];
640  if ($withRedirectUid) {
641  $combination = [
642  'uid' => ‪$record['uid'],
643  'source_host' => ‪$record['source_host'],
644  'source_path' => ‪$record['source_path'],
645  'target' => ‪$record['target'],
646  ];
647  }
648  self::assertContains($combination, $redirects, 'wrong redirect found');
649  }
650  }
651 
652  protected function ‪setPageSlug(int $pageId, string $slug): void
653  {
654  $this->getConnectionPool()->getConnectionForTable('pages')
655  ->update(
656  'pages',
657  [
658  'slug' => $slug,
659  ],
660  [
661  'uid' => $pageId,
662  ]
663  );
664  }
665 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Redirects\RedirectUpdate\SlugRedirectChangeItem
Definition: SlugRedirectChangeItem.php:30
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\$subject
‪SlugService $subject
Definition: SlugServiceTest.php:51
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithLanguagesForSiteroot
‪rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithLanguagesForSiteroot()
Definition: SlugServiceTest.php:376
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirects
‪rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirects()
Definition: SlugServiceTest.php:111
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\spacerWithSubPagesDoesNotCreateAutoRedirectForSpacerButUpdatesSubpagesIfReasonable
‪spacerWithSubPagesDoesNotCreateAutoRedirectForSpacerButUpdatesSubpagesIfReasonable()
Definition: SlugServiceTest.php:531
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\setUp
‪setUp()
Definition: SlugServiceTest.php:89
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsForRootChange
‪rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsForRootChange()
Definition: SlugServiceTest.php:154
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\buildBaseSite
‪buildBaseSite()
Definition: SlugServiceTest.php:557
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithLanguagesInSubFolder
‪rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithLanguagesInSubFolder()
Definition: SlugServiceTest.php:289
‪TYPO3\CMS\Redirects\Event\ModifyAutoCreateRedirectRecordBeforePersistingEvent\getRedirectRecord
‪getRedirectRecord()
Definition: ModifyAutoCreateRedirectRecordBeforePersistingEvent.php:49
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId\forScope
‪static forScope(string $scope)
Definition: CorrelationId.php:42
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\sysFolderWithSubPagesDoesNotCreateAutoRedirectForSysFolderButUpdatesSubpagesIfReasonable
‪sysFolderWithSubPagesDoesNotCreateAutoRedirectForSysFolderButUpdatesSubpagesIfReasonable()
Definition: SlugServiceTest.php:504
‪TYPO3\CMS\Redirects\Event\AfterAutoCreateRedirectHasBeenPersistedEvent
Definition: AfterAutoCreateRedirectHasBeenPersistedEvent.php:32
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\buildBaseSiteWithLanguages
‪buildBaseSiteWithLanguages()
Definition: SlugServiceTest.php:577
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithDefaultLanguageInSubFolder
‪rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithDefaultLanguageInSubFolder()
Definition: SlugServiceTest.php:332
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\modifyAutoCreateRedirectRecordBeforePersistingIsTriggered
‪modifyAutoCreateRedirectRecordBeforePersistingIsTriggered()
Definition: SlugServiceTest.php:411
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Redirects\Event\ModifyAutoCreateRedirectRecordBeforePersistingEvent
Definition: ModifyAutoCreateRedirectRecordBeforePersistingEvent.php:32
‪TYPO3\CMS\Core\Configuration\SiteConfiguration
Definition: SiteConfiguration.php:47
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithLanguages
‪rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithLanguages()
Definition: SlugServiceTest.php:246
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\setPageSlug
‪setPageSlug(int $pageId, string $slug)
Definition: SlugServiceTest.php:650
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\assertSlugsAndRedirectsExists
‪assertSlugsAndRedirectsExists(array $slugs, array $redirects, bool $withRedirectUid=false)
Definition: SlugServiceTest.php:622
‪TYPO3\CMS\Redirects\Service\RedirectCacheService
Definition: RedirectCacheService.php:34
‪TYPO3\CMS\Redirects\Tests\Functional\Service
Definition: IntegrityServiceTest.php:18
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\tearDown
‪tearDown()
Definition: SlugServiceTest.php:98
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithSubFolderBase
‪rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithSubFolderBase()
Definition: SlugServiceTest.php:203
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\buildBaseSiteInSubfolder
‪buildBaseSiteInSubfolder()
Definition: SlugServiceTest.php:567
‪TYPO3\CMS\Core\DataHandling\Model\CorrelationId
Definition: CorrelationId.php:29
‪TYPO3\CMS\Redirects\RedirectUpdate\SlugRedirectChangeItemFactory
Definition: SlugRedirectChangeItemFactory.php:31
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\buildBaseSiteWithLanguagesInSubFolder
‪buildBaseSiteWithLanguagesInSubFolder()
Definition: SlugServiceTest.php:588
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest
Definition: SlugServiceTest.php:48
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\$languages
‪array $languages
Definition: SlugServiceTest.php:57
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\$correlationId
‪CorrelationId $correlationId
Definition: SlugServiceTest.php:55
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\afterAutoCreteRedirectHasBeenPersistedIsTriggered
‪afterAutoCreteRedirectHasBeenPersistedIsTriggered()
Definition: SlugServiceTest.php:462
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\$coreExtensionsToLoad
‪array $coreExtensionsToLoad
Definition: SlugServiceTest.php:87
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:69
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Utility\StringUtility
Definition: StringUtility.php:24
‪TYPO3\CMS\Redirects\Service\SlugService
Definition: SlugService.php:52
‪TYPO3\CMS\Core\EventDispatcher\ListenerProvider
Definition: ListenerProvider.php:30
‪TYPO3\CMS\Redirects\Tests\Functional\Service\SlugServiceTest\createSubject
‪createSubject()
Definition: SlugServiceTest.php:607
‪TYPO3\CMS\Core\Routing\SiteMatcher
Definition: SiteMatcher.php:52
‪TYPO3\CMS\Core\Utility\StringUtility\getUniqueId
‪static getUniqueId(string $prefix='')
Definition: StringUtility.php:57
‪TYPO3\CMS\Redirects\Event\ModifyAutoCreateRedirectRecordBeforePersistingEvent\setRedirectRecord
‪setRedirectRecord(array $redirectRecord)
Definition: ModifyAutoCreateRedirectRecordBeforePersistingEvent.php:54