‪TYPO3CMS  11.5
RedirectServiceTest.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 Prophecy\Argument;
21 use Prophecy\PhpUnit\ProphecyTrait;
22 use Prophecy\Prophecy\ObjectProphecy;
23 use Psr\Log\LoggerInterface;
36 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
37 
38 class ‪RedirectServiceTest extends UnitTestCase
39 {
40  use ProphecyTrait;
41 
45  protected ‪$resetSingletonInstances = true;
46 
48  protected ObjectProphecy ‪$redirectCacheServiceProphecy;
49 
51  protected ObjectProphecy ‪$linkServiceProphecy;
52 
54 
56  protected ObjectProphecy ‪$siteFinder;
57 
59  protected ObjectProphecy ‪$redirectRepository;
60 
61  protected function ‪setUp(): void
62  {
63  parent::setUp();
64  $loggerProphecy = $this->prophesize(LoggerInterface::class);
65  $this->redirectCacheServiceProphecy = $this->prophesize(RedirectCacheService::class);
66  $this->linkServiceProphecy = $this->prophesize(LinkService::class);
67  $this->siteFinder = $this->prophesize(SiteFinder::class);
68  $this->redirectRepository = $this->prophesize(RedirectRepository::class);
69 
70  $this->redirectService = new ‪RedirectService($this->redirectCacheServiceProphecy->reveal(), $this->linkServiceProphecy->reveal(), $this->siteFinder->reveal());
71  $this->redirectService->setLogger($loggerProphecy->reveal());
72 
73  ‪$GLOBALS['SIM_ACCESS_TIME'] = 42;
74  }
75 
79  public function ‪matchRedirectReturnsNullIfNoRedirectsExist(): void
80  {
81  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn([]);
82  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
83 
84  $result = $this->redirectService->matchRedirect('example.com', 'foo');
85 
86  self::assertNull($result);
87  }
88 
94  public function ‪matchRedirectReturnsRedirectOnFlatMatch(string $path = ''): void
95  {
96  $row = [
97  'target' => 'https://example.com',
98  'force_https' => '0',
99  'keep_query_parameters' => '0',
100  'target_statuscode' => '307',
101  'disabled' => '0',
102  'starttime' => '0',
103  'endtime' => '0',
104  ];
105  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
106  [
107  'flat' => [
108  $path . '/' => [
109  1 => $row,
110  ],
111  ],
112  ]
113  );
114  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
115 
116  $result = $this->redirectService->matchRedirect('example.com', rawurlencode($path));
117 
118  self::assertSame($row, $result);
119  }
120 
125  {
126  return [
127  'default case' => [
128  'foo',
129  ],
130  'umlauts' => [
131  'äöü',
132  ],
133  'various special chars' => [
134  'special-chars-«-∑-€-®-†-Ω-¨-ø-π-å-‚-∂-ƒ-©-ª-º-∆-@-¥-≈-ç-√-∫-~-µ-∞-…-–',
135  ],
136  'chinese' => [
137  '应用',
138  ],
139  'hindi' => [
140  'कंपनी',
141  ],
142  'cyrilic' => [
143  'cyrilic-АВГДЄЅЗИѲІКЛМНѮѺПЧ',
144  ],
145  ];
146  }
147 
152  {
153  $row = [
154  'target' => 'https://example.com',
155  'force_https' => '0',
156  'keep_query_parameters' => '0',
157  'respect_query_parameters' => '1',
158  'target_statuscode' => '307',
159  'disabled' => '0',
160  'starttime' => '0',
161  'endtime' => '0',
162  ];
163  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
164  [
165  'respect_query_parameters' => [
166  'index.php?id=123' => [
167  1 => $row,
168  ],
169  ],
170  ]
171  );
172  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
173 
174  $result = $this->redirectService->matchRedirect('example.com', 'index.php', 'id=123');
175 
176  self::assertSame($row, $result);
177  }
178 
183  {
184  $row = [
185  'target' => 'https://example.com',
186  'force_https' => '0',
187  'keep_query_parameters' => '0',
188  'respect_query_parameters' => '1',
189  'target_statuscode' => '307',
190  'disabled' => '0',
191  'starttime' => '0',
192  'endtime' => '0',
193  ];
194  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
195  [
196  'respect_query_parameters' => [
197  'index.php/?id=123' => [
198  1 => $row,
199  ],
200  ],
201  ]
202  );
203  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
204 
205  $result = $this->redirectService->matchRedirect('example.com', 'index.php', 'id=123');
206 
207  self::assertSame($row, $result);
208  }
209 
214  {
215  $row = [
216  'target' => 'https://example.com/target',
217  'force_https' => '0',
218  'keep_query_parameters' => '0',
219  'respect_query_parameters' => '1',
220  'target_statuscode' => '307',
221  'disabled' => '0',
222  'starttime' => '0',
223  'endtime' => '0',
224  ];
225  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
226  [
227  'respect_query_parameters' => [
228  'index.php?id=123&a=b' => [
229  1 => $row,
230  ],
231  ],
232  ]
233  );
234  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
235 
236  $result = $this->redirectService->matchRedirect('example.com', 'index.php', 'id=123&a=b');
237 
238  self::assertSame($row, $result);
239  }
240 
245  {
246  $row = [
247  'target' => 'https://example.com/target',
248  'force_https' => '0',
249  'keep_query_parameters' => '0',
250  'respect_query_parameters' => '1',
251  'target_statuscode' => '307',
252  'disabled' => '0',
253  'starttime' => '0',
254  'endtime' => '0',
255  ];
256  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
257  [
258  'respect_query_parameters' => [
259  'index.php?id=123&a=b' => [
260  1 => $row,
261  ],
262  ],
263  ]
264  );
265  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
266 
267  $result = $this->redirectService->matchRedirect('example.com', 'index.php', 'id=123&a=a');
268 
269  self::assertNull($result);
270  }
271 
276  {
277  $row1 = [
278  'target' => 'https://example.com/no-promotion',
279  'force_https' => '0',
280  'keep_query_parameters' => '0',
281  'respect_query_parameters' => '0',
282  'target_statuscode' => '307',
283  'disabled' => '0',
284  'starttime' => '0',
285  'endtime' => '0',
286  ];
287  $row2 = [
288  'target' => 'https://example.com/promotion',
289  'force_https' => '0',
290  'keep_query_parameters' => '0',
291  'respect_query_parameters' => '1',
292  'target_statuscode' => '307',
293  'disabled' => '0',
294  'starttime' => '0',
295  'endtime' => '0',
296  ];
297  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
298  [
299  'flat' => [
300  'special/page/' =>
301  [
302  1 => $row1,
303  ],
304  ],
305  'respect_query_parameters' => [
306  'special/page?key=998877' => [
307  1 => $row2,
308  ],
309  ],
310  ]
311  );
312  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
313 
314  $result = $this->redirectService->matchRedirect('example.com', 'special/page', 'key=998877');
315 
316  self::assertSame($row2, $result);
317  }
318 
323  {
324  $row1 = [
325  'target' => 'https://example.com',
326  'force_https' => '0',
327  'keep_query_parameters' => '0',
328  'target_statuscode' => '307',
329  'disabled' => '0',
330  'starttime' => '0',
331  'endtime' => '0',
332  ];
333  $row2 = [
334  'target' => 'https://example.net',
335  'force_https' => '0',
336  'keep_query_parameters' => '0',
337  'target_statuscode' => '307',
338  'disabled' => '0',
339  'starttime' => '0',
340  'endtime' => '0',
341  ];
342  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
343  [
344  'flat' => [
345  'foo/' => [
346  1 => $row1,
347  ],
348  ],
349  ]
350  );
351  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn(
352  [
353  'flat' => [
354  'foo/' => [
355  2 => $row2,
356  ],
357  ],
358  ]
359  );
360 
361  $result = $this->redirectService->matchRedirect('example.com', 'foo');
362 
363  self::assertSame($row1, $result);
364  }
365 
369  public function ‪matchRedirectReturnsRedirectOnRegexMatch(): void
370  {
371  $row = [
372  'target' => 'https://example.com',
373  'force_https' => '0',
374  'respect_query_parameters' => '0',
375  'keep_query_parameters' => '0',
376  'target_statuscode' => '307',
377  'disabled' => '0',
378  'starttime' => '0',
379  'endtime' => '0',
380  ];
381  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
382  [
383  'regexp_flat' => [
384  '/f.*?/' => [
385  1 => $row,
386  ],
387  ],
388  ]
389  );
390  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
391 
392  $result = $this->redirectService->matchRedirect('example.com', 'foo');
393 
394  self::assertSame($row, $result);
395  }
396 
400  public function ‪matchRedirectReturnsOnlyActiveRedirects(): void
401  {
402  $row1 = [
403  'target' => 'https://example.com',
404  'force_https' => '0',
405  'keep_query_parameters' => '0',
406  'target_statuscode' => '307',
407  'starttime' => '0',
408  'endtime' => '0',
409  'disabled' => '1',
410  ];
411  $row2 = [
412  'target' => 'https://example.net',
413  'force_https' => '0',
414  'keep_query_parameters' => '0',
415  'target_statuscode' => '307',
416  'starttime' => '0',
417  'endtime' => '0',
418  'disabled' => '0',
419  ];
420  $this->redirectCacheServiceProphecy->getRedirects('example.com')->willReturn(
421  [
422  'flat' => [
423  'foo/' => [
424  1 => $row1,
425  2 => $row2,
426  ],
427  ],
428  ]
429  );
430  $this->redirectCacheServiceProphecy->getRedirects('*')->willReturn([]);
431 
432  $result = $this->redirectService->matchRedirect('example.com', 'foo');
433 
434  self::assertSame($row2, $result);
435  }
436 
441  {
442  $this->linkServiceProphecy->resolve(Argument::any())->willThrow(new InvalidPathException('', 1516531195));
443 
444  $result = $this->redirectService->getTargetUrl(['target' => 'invalid'], new ServerRequest(new Uri()));
445 
446  self::assertNull($result);
447  }
448 
452  public function ‪getTargetUrlReturnsUrlForTypeUrl(): void
453  {
454  $redirectTargetMatch = [
455  'target' => 'https://example.com',
456  'force_https' => '0',
457  'keep_query_parameters' => '0',
458  ];
459  $linkDetails = [
460  'type' => ‪LinkService::TYPE_URL,
461  'url' => 'https://example.com/',
462  ];
463  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
464 
465  $source = new Uri('https://example.com');
466  $request = new ServerRequest($source);
467  $request = $request->withAttribute('site', new Site('dummy', 13, []));
468  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
469 
470  $uri = new Uri('https://example.com/');
471  self::assertEquals($uri, $result);
472  }
473 
477  public function ‪getTargetUrlReturnsUrlForTypeFile(): void
478  {
479  $fileProphecy = $this->prophesize(File::class);
480  $fileProphecy->getPublicUrl()->willReturn('https://example.com/file.txt');
481  $redirectTargetMatch = [
482  'target' => 'https://example.com',
483  'force_https' => '0',
484  'keep_query_parameters' => '0',
485  ];
486  $linkDetails = [
487  'type' => ‪LinkService::TYPE_FILE,
488  'file' => $fileProphecy->reveal(),
489  ];
490  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
491 
492  $source = new Uri('https://example.com');
493  $request = new ServerRequest($source);
494  $request = $request->withAttribute('site', new Site('dummy', 13, []));
495  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
496 
497  $uri = new Uri('https://example.com/file.txt');
498  self::assertEquals($uri, $result);
499  }
500 
504  public function ‪getTargetUrlReturnsUrlForTypeFolder(): void
505  {
506  $folderProphecy = $this->prophesize(Folder::class);
507  $folderProphecy->getPublicUrl()->willReturn('https://example.com/folder/');
508  $redirectTargetMatch = [
509  'target' => 'https://example.com',
510  'force_https' => '0',
511  'keep_query_parameters' => '0',
512  ];
513  $folder = $folderProphecy->reveal();
514  $linkDetails = [
515  'type' => ‪LinkService::TYPE_FOLDER,
516  'folder' => $folder,
517  ];
518  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
519 
520  $source = new Uri('https://example.com/');
521  $request = new ServerRequest($source);
522  $request = $request->withAttribute('site', new Site('dummy', 13, []));
523  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
524 
525  $uri = new Uri('https://example.com/folder/');
526  self::assertEquals($uri, $result);
527  }
528 
532  public function ‪getTargetUrlRespectsForceHttps(): void
533  {
534  $redirectTargetMatch = [
535  'target' => 'https://example.com',
536  'keep_query_parameters' => '0',
537  'force_https' => '1',
538  ];
539  $linkDetails = [
540  'type' => ‪LinkService::TYPE_URL,
541  'url' => 'http://example.com',
542  ];
543  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
544 
545  $source = new Uri('https://example.com');
546  $request = new ServerRequest($source);
547  $request = $request->withAttribute('site', new Site('dummy', 13, []));
548  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
549 
550  $uri = new Uri('https://example.com');
551  self::assertEquals($uri, $result);
552  }
553 
557  public function ‪getTargetUrlAddsExistingQueryParams(): void
558  {
559  $redirectTargetMatch = [
560  'target' => 'https://example.com',
561  'force_https' => '0',
562  'keep_query_parameters' => '1',
563  ];
564  $linkDetails = [
565  'type' => ‪LinkService::TYPE_URL,
566  'url' => 'https://example.com/?foo=1&bar=2',
567  ];
568  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
569 
570  $source = new Uri('https://example.com/?bar=2&baz=4&foo=1');
571  $request = new ServerRequest($source);
572  $request = $request->withQueryParams(['bar' => 3, 'baz' => 4]);
573  $request = $request->withAttribute('site', new Site('dummy', 13, []));
574  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
575 
576  $uri = new Uri('https://example.com/?bar=2&baz=4&foo=1');
577  self::assertEquals($uri, $result);
578  }
579 
584  {
585  ‪$redirectService = $this->getAccessibleMock(
586  RedirectService::class,
587  ['getUriFromCustomLinkDetails'],
588  [$this->redirectCacheServiceProphecy->reveal(), $this->linkServiceProphecy->reveal(), $this->siteFinder->reveal(), $this->redirectRepository->reveal()],
589  '',
590  true
591  );
592 
593  $loggerProphecy = $this->prophesize(LoggerInterface::class);
594  ‪$redirectService->setLogger($loggerProphecy->reveal());
595 
596  $pageRecord = 't3://page?uid=13';
597  $redirectTargetMatch = [
598  'target' => $pageRecord . ' - - - foo=bar',
599  'force_https' => 1,
600  'keep_query_parameters' => 1,
601  ];
602 
603  $linkDetails = [
604  'pageuid' => 13,
605  'type' => ‪LinkService::TYPE_PAGE,
606  'typoLinkParameter' => $pageRecord,
607  ];
608  $this->linkServiceProphecy->resolve($pageRecord)->willReturn($linkDetails);
609 
610  $queryParams = [];
611  $queryParams['foo'] = 'bar';
612  $uri = new Uri('/page?foo=bar');
613 
614  $frontendUserAuthentication = new FrontendUserAuthentication();
615  $site = new Site('dummy', 13, []);
616  $request = new ServerRequest($uri);
617  $request = $request->withQueryParams($queryParams);
618  $request = $request->withAttribute('site', $site);
619  $request = $request->withAttribute('frontend.user', $frontendUserAuthentication);
620  ‪$redirectService->method('getUriFromCustomLinkDetails')
621  ->with($redirectTargetMatch, $site, $linkDetails, $queryParams, $request)
622  ->willReturn($uri);
623  $result = ‪$redirectService->‪getTargetUrl($redirectTargetMatch, $request);
624 
625  self::assertEquals($uri, $result);
626  }
627 
631  public function ‪getTargetUrlReplaceRegExpCaptureGroup(): void
632  {
633  $redirectTargetMatch = [
634  'source_path' => '#^/foo/(.*)#',
635  'target' => 'https://anotherdomain.com/$1',
636  'force_https' => '0',
637  'keep_query_parameters' => '1',
638  'is_regexp' => 1,
639  ];
640  $linkDetails = [
641  'type' => ‪LinkService::TYPE_URL,
642  'url' => 'https://anotherdomain.com/$1',
643  ];
644  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
645 
646  $source = new Uri('https://example.com/foo/bar');
647  $request = new ServerRequest($source);
648  $request = $request->withAttribute('site', new Site('dummy', 13, []));
649  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
650 
651  $uri = new Uri('https://anotherdomain.com/bar');
652  self::assertEquals($uri, $result);
653  }
654 
656  {
657  $cyrilicPlain = 'АВГДЄЅЗИѲІКЛМНѮѺПЧ';
658  return [
659  'index.php with query capture group - plain value' => [
660  '#^/index.php\?option=com_content&page=(.*)#',
661  'https://anotherdomain.com/$1',
662  'https://example.com/index.php?option=com_content&page=target',
663  'https://anotherdomain.com/target',
664  ],
665  'index.php with query capture group - cyrilic value' => [
666  '#^/index.php\?option=com_content&page=(.*)#',
667  'https://anotherdomain.com/$1',
668  sprintf('https://example.com/index.php?option=com_content&page=%s', $cyrilicPlain),
669  sprintf('https://anotherdomain.com/%s', $cyrilicPlain),
670  ],
671  'capture group in path and query capture group - cyrilic value' => [
672  '#^/index-(.*).php\?option=com_content&page=(.*)#',
673  'https://anotherdomain.com/$1/$2',
674  sprintf('https://example.com/index-%s.php?option=com_content&page=cyrilic-%s', $cyrilicPlain, $cyrilicPlain),
675  sprintf('https://anotherdomain.com/%s/cyrilic-%s', $cyrilicPlain, $cyrilicPlain),
676  ],
677  'cyrilic path with non-cyrilic capture group' => [
678  sprintf('#^/index-%s.php\?option=com_content&page=(.*)#', $cyrilicPlain),
679  'https://anotherdomain.com/$1',
680  sprintf('https://example.com/index-%s.php?option=com_content&page=cyrilic-%s', $cyrilicPlain, $cyrilicPlain),
681  sprintf('https://anotherdomain.com/cyrilic-%s', $cyrilicPlain),
682  ],
683  'cyrilic path with cyrilic capture group' => [
684  sprintf('#^/index-%s.php\?option=com_content&page=(.*)#', $cyrilicPlain),
685  'https://anotherdomain.com/$1',
686  sprintf('https://example.com/index-%s.php?option=com_content&page=cyrilic-%s', $cyrilicPlain, $cyrilicPlain),
687  sprintf('https://anotherdomain.com/cyrilic-%s', $cyrilicPlain),
688  ],
689  'cyrilic path with cyrilic capture group with cyrilic prefix' => [
690  sprintf('#^/index-%s.php\?option=com_content&page=%s(.*)#', $cyrilicPlain, $cyrilicPlain),
691  'https://anotherdomain.com/$1',
692  sprintf('https://example.com/index-%s.php?option=com_content&page=%scyrilic-%s', $cyrilicPlain, $cyrilicPlain, $cyrilicPlain),
693  sprintf('https://anotherdomain.com/cyrilic-%s', $cyrilicPlain),
694  ],
695  ];
696  }
697 
703  string $redirectSourcePath,
704  string $redirectTarget,
705  string $requestUri,
706  string $expectedRedirectUri
707  ) {
708  $redirectTargetMatch = [
709  'uid' => 1,
710  'source_path' => $redirectSourcePath,
711  'target' => $redirectTarget,
712  'force_https' => '0',
713  'keep_query_parameters' => 0,
714  'is_regexp' => 1,
715  'respect_query_parameters' => 1,
716  ];
717  $linkDetails = [
718  'type' => ‪LinkService::TYPE_URL,
719  'url' => $redirectTarget,
720  'query' => '',
721  ];
722  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
723 
724  $source = new Uri($requestUri);
725  $queryParams = [];
726  parse_str($source->getQuery(), $queryParams);
727  $request = new ServerRequest($source);
728  $request = $request->withQueryParams($queryParams);
729  $request = $request->withAttribute('site', new Site('dummy', 13, []));
730  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
731 
732  $uri = new Uri($expectedRedirectUri);
733  self::assertEquals($uri, $result);
734  }
735 
737  {
738  $cyrilicPlain = 'АВГДЄЅЗИѲІКЛМНѮѺПЧ';
739  return [
740  'index with path slash with query capture group - plain value' => [
741  '#^/index/\?option=com_content&page=(.*)#',
742  'https://anotherdomain.com/$1',
743  'https://example.com/index/?option=com_content&page=target',
744  'https://anotherdomain.com/target?option=com_content&page=target',
745  ],
746  'index with query capture group - cyrilic value' => [
747  '#^/index/\?option=com_content&page=(.*)#',
748  'https://anotherdomain.com/$1',
749  sprintf('https://example.com/index/?option=com_content&page=%s', $cyrilicPlain),
750  sprintf('https://anotherdomain.com/%s?option=com_content&page=%s', $cyrilicPlain, $cyrilicPlain),
751  ],
752  'capture group in path and query capture group - cyrilic value' => [
753  '#^/index-(.*)/\?option=com_content&page=(.*)#',
754  'https://anotherdomain.com/$1/$2',
755  sprintf('https://example.com/index-%s/?option=com_content&page=cyrilic-%s', $cyrilicPlain, $cyrilicPlain),
756  sprintf('https://anotherdomain.com/%s/cyrilic-%s?option=com_content&page=cyrilic-%s', $cyrilicPlain, $cyrilicPlain, $cyrilicPlain),
757  ],
758  'cyrilic path with non-cyrilic capture group' => [
759  sprintf('#^/index-%s/\?option=com_content&page=(.*)#', $cyrilicPlain),
760  'https://anotherdomain.com/$1',
761  sprintf('https://example.com/index-%s/?option=com_content&page=cyrilic', $cyrilicPlain),
762  'https://anotherdomain.com/cyrilic?option=com_content&page=cyrilic',
763  ],
764  'cyrilic path with cyrilic capture group' => [
765  sprintf('#^/index-%s/\?option=com_content&page=(.*)#', $cyrilicPlain),
766  'https://anotherdomain.com/$1',
767  sprintf('https://example.com/index-%s/?option=com_content&page=cyrilic-%s', $cyrilicPlain, $cyrilicPlain),
768  sprintf('https://anotherdomain.com/cyrilic-%s?option=com_content&page=cyrilic-%s', $cyrilicPlain, $cyrilicPlain),
769  ],
770  'cyrilic path with cyrilic capture group with cyrilic prefix' => [
771  sprintf('#^/index-%s/\?option=com_content&page=%s(.*)#', $cyrilicPlain, $cyrilicPlain),
772  'https://anotherdomain.com/$1',
773  sprintf('https://example.com/index-%s/?option=com_content&page=%scyrilic-%s', $cyrilicPlain, $cyrilicPlain, $cyrilicPlain),
774  sprintf('https://anotherdomain.com/cyrilic-%s?option=com_content&page=%scyrilic-%s', $cyrilicPlain, $cyrilicPlain, $cyrilicPlain),
775  ],
776  ];
777  }
778 
784  string $redirectSourcePath,
785  string $redirectTarget,
786  string $requestUri,
787  string $expectedRedirectUri
788  ) {
789  $redirectTargetMatch = [
790  'uid' => 1,
791  'source_path' => $redirectSourcePath,
792  'target' => $redirectTarget,
793  'force_https' => '0',
794  'keep_query_parameters' => '1',
795  'is_regexp' => 1,
796  'respect_query_parameters' => 1,
797  ];
798  $linkDetails = [
799  'type' => ‪LinkService::TYPE_URL,
800  'url' => $redirectTarget,
801  ];
802  $this->linkServiceProphecy->resolve($redirectTargetMatch['target'])->willReturn($linkDetails);
803 
804  $source = new Uri($requestUri);
805  $queryParams = [];
806  parse_str($source->getQuery(), $queryParams);
807  $request = new ServerRequest($source);
808  $request = $request->withQueryParams($queryParams);
809  $request = $request->withAttribute('site', new Site('dummy', 13, []));
810  $result = $this->redirectService->getTargetUrl($redirectTargetMatch, $request);
811 
812  $uri = new Uri($expectedRedirectUri);
813  self::assertEquals($uri, $result);
814  }
815 }
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlReplaceRegExpCaptureGroup
‪getTargetUrlReplaceRegExpCaptureGroup()
Definition: RedirectServiceTest.php:629
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlWithQueryReplaceRegExpCaptureGroup
‪getTargetUrlWithQueryReplaceRegExpCaptureGroup(string $redirectSourcePath, string $redirectTarget, string $requestUri, string $expectedRedirectUri)
Definition: RedirectServiceTest.php:700
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlWithQueryAndSlashReplaceRegExpCaptureGroup
‪getTargetUrlWithQueryAndSlashReplaceRegExpCaptureGroup(string $redirectSourcePath, string $redirectTarget, string $requestUri, string $expectedRedirectUri)
Definition: RedirectServiceTest.php:781
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\$siteFinder
‪ObjectProphecy $siteFinder
Definition: RedirectServiceTest.php:54
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest
Definition: RedirectServiceTest.php:39
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsNullIfNoRedirectsExist
‪matchRedirectReturnsNullIfNoRedirectsExist()
Definition: RedirectServiceTest.php:77
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlReturnsUrlForTypeUrl
‪getTargetUrlReturnsUrlForTypeUrl()
Definition: RedirectServiceTest.php:450
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsRedirectSpecificToDomainOnFlatMatchIfSpecificAndNonSpecificExist
‪matchRedirectReturnsRedirectSpecificToDomainOnFlatMatchIfSpecificAndNonSpecificExist()
Definition: RedirectServiceTest.php:320
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlRespectsAdditionalParametersFromTypolink
‪getTargetUrlRespectsAdditionalParametersFromTypolink()
Definition: RedirectServiceTest.php:581
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsRedirectOnRespectQueryParametersMatchWithSlash
‪matchRedirectReturnsRedirectOnRespectQueryParametersMatchWithSlash()
Definition: RedirectServiceTest.php:180
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlWithQueryAndSlashReplaceRegExpCaptureGroupDataProvider
‪getTargetUrlWithQueryAndSlashReplaceRegExpCaptureGroupDataProvider()
Definition: RedirectServiceTest.php:734
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsOnlyActiveRedirects
‪matchRedirectReturnsOnlyActiveRedirects()
Definition: RedirectServiceTest.php:398
‪TYPO3\CMS\Redirects\Service\RedirectService
Definition: RedirectService.php:50
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsRedirectOnRespectQueryParametersMatch
‪matchRedirectReturnsRedirectOnRespectQueryParametersMatch()
Definition: RedirectServiceTest.php:149
‪TYPO3\CMS\Redirects\Tests\Unit\Service
Definition: RedirectServiceTest.php:18
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsRedirectOnFlatMatch
‪matchRedirectReturnsRedirectOnFlatMatch(string $path='')
Definition: RedirectServiceTest.php:92
‪TYPO3\CMS\Redirects\Service\RedirectService\getTargetUrl
‪getTargetUrl(array $matchedRedirect, ServerRequestInterface $request)
Definition: RedirectService.php:254
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlReturnsNullIfUrlCouldNotBeResolved
‪getTargetUrlReturnsNullIfUrlCouldNotBeResolved()
Definition: RedirectServiceTest.php:438
‪TYPO3\CMS\Core\Http\Uri
Definition: Uri.php:29
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\setUp
‪setUp()
Definition: RedirectServiceTest.php:59
‪TYPO3\CMS\Redirects\Service\RedirectCacheService
Definition: RedirectCacheService.php:34
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsMatchingRedirectWithMatchingQueryParametersOverMatchingPath
‪matchRedirectReturnsMatchingRedirectWithMatchingQueryParametersOverMatchingPath()
Definition: RedirectServiceTest.php:273
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: RedirectServiceTest.php:43
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\$redirectRepository
‪ObjectProphecy $redirectRepository
Definition: RedirectServiceTest.php:57
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlWithQueryReplaceRegExpCaptureGroupDataProvider
‪getTargetUrlWithQueryReplaceRegExpCaptureGroupDataProvider()
Definition: RedirectServiceTest.php:653
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\$redirectService
‪RedirectService $redirectService
Definition: RedirectServiceTest.php:51
‪TYPO3\CMS\Core\Resource\Folder
Definition: Folder.php:37
‪TYPO3\CMS\Core\Resource\File
Definition: File.php:24
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:37
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsRedirectOnFullRespectQueryParametersMatch
‪matchRedirectReturnsRedirectOnFullRespectQueryParametersMatch()
Definition: RedirectServiceTest.php:211
‪TYPO3\CMS\Redirects\Repository\RedirectRepository
Definition: RedirectRepository.php:31
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlReturnsUrlForTypeFile
‪getTargetUrlReturnsUrlForTypeFile()
Definition: RedirectServiceTest.php:475
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsRedirectOnFlatMatchDataProvider
‪array matchRedirectReturnsRedirectOnFlatMatchDataProvider()
Definition: RedirectServiceTest.php:122
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlAddsExistingQueryParams
‪getTargetUrlAddsExistingQueryParams()
Definition: RedirectServiceTest.php:555
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsNullOnPartialRespectQueryParametersMatch
‪matchRedirectReturnsNullOnPartialRespectQueryParametersMatch()
Definition: RedirectServiceTest.php:242
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\matchRedirectReturnsRedirectOnRegexMatch
‪matchRedirectReturnsRedirectOnRegexMatch()
Definition: RedirectServiceTest.php:367
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlReturnsUrlForTypeFolder
‪getTargetUrlReturnsUrlForTypeFolder()
Definition: RedirectServiceTest.php:502
‪TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication
Definition: FrontendUserAuthentication.php:32
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\$redirectCacheServiceProphecy
‪ObjectProphecy $redirectCacheServiceProphecy
Definition: RedirectServiceTest.php:46
‪TYPO3\CMS\Core\Resource\Exception\InvalidPathException
Definition: InvalidPathException.php:23
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\$linkServiceProphecy
‪ObjectProphecy $linkServiceProphecy
Definition: RedirectServiceTest.php:49
‪TYPO3\CMS\Redirects\Tests\Unit\Service\RedirectServiceTest\getTargetUrlRespectsForceHttps
‪getTargetUrlRespectsForceHttps()
Definition: RedirectServiceTest.php:530