‪TYPO3CMS  11.5
IntegrityServiceTest.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\Prophecy\ObjectProphecy;
27 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
28 
29 class ‪IntegrityServiceTest extends FunctionalTestCase
30 {
31  use \Prophecy\PhpUnit\ProphecyTrait;
35  protected ‪$resetSingletonInstances = true;
36 
37  protected ‪$coreExtensionsToLoad = ['redirects'];
38 
42  protected ‪$subject;
43 
44  protected function ‪setUp(): void
45  {
46  parent::setUp();
47  $siteFinder = $this->‪prophesizeSiteFinder()->reveal();
48  $this->subject = new ‪IntegrityService(
51  $this->prophesize(LinkService::class)->reveal(),
52  $siteFinder,
53  ),
54  $siteFinder
55  );
56  }
57 
67  {
68  $this->importCSVDataSet(__DIR__ . '/Fixtures/IntegrityServiceTest_sourcePathWithMatchingSlugInLocalizedPageIsNotReportedAsConflict.csv');
69 
70  $result = $this->subject->findConflictingRedirects('localized-page');
71  $this->‪assertExpectedPathsFromGenerator([], $result);
72  }
73 
78  {
79  $this->importCSVDataSet(__DIR__ . '/Fixtures/SimplePages.csv');
80  $this->importCSVDataSet(__DIR__ . '/Fixtures/sys_redirect.csv');
81 
82  $expectedConflicts = [
83  [
84  'uri' => 'https://example.com/',
85  'redirect' => [
86  'source_host' => 'example.com',
87  'source_path' => '/',
88  ],
89  ],
90  [
91  'uri' => 'https://example.com/about-us/we-are-here',
92  'redirect' => [
93  'source_host' => '*',
94  'source_path' => '/about-us/we-are-here',
95  ],
96  ],
97  [
98  'uri' => 'https://example.com/contact',
99  'redirect' => [
100  'source_host' => 'example.com',
101  'source_path' => '/contact',
102  ],
103  ],
104  [
105  'uri' => 'https://example.com/features',
106  'redirect' => [
107  'source_host' => '*',
108  'source_path' => '/features',
109  ],
110  ],
111  ];
112 
113  $this->‪assertExpectedPathsFromGenerator($expectedConflicts, $this->subject->findConflictingRedirects('simple-page'));
114  }
115 
120  {
121  $this->importCSVDataSet(__DIR__ . '/Fixtures/LocalizedPages.csv');
122  $this->importCSVDataSet(__DIR__ . '/Fixtures/sys_redirect.csv');
123 
124  $expectedConflicts = [
125  [
126  'uri' => 'https://another.example.com/about-us/we-are-here',
127  'redirect' => [
128  'source_host' => '*',
129  'source_path' => '/about-us/we-are-here',
130  ],
131  ],
132  [
133  'uri' => 'https://another.example.com/de/merkmale',
134  'redirect' => [
135  'source_host' => 'another.example.com',
136  'source_path' => '/de/merkmale',
137  ],
138  ],
139  [
140  'uri' => 'https://another.example.com/features',
141  'redirect' => [
142  'source_host' => 'another.example.com',
143  'source_path' => '/features',
144  ],
145  ],
146  ];
147  $conflicts = $this->subject->findConflictingRedirects('localized-page');
148  $this->‪assertExpectedPathsFromGenerator($expectedConflicts, $conflicts);
149  }
150 
154  public function ‪conflictingRedirectsAreFoundForAllSites(): void
155  {
156  $this->importCSVDataSet(__DIR__ . '/Fixtures/SimplePages.csv');
157  $this->importCSVDataSet(__DIR__ . '/Fixtures/LocalizedPages.csv');
158  $this->importCSVDataSet(__DIR__ . '/Fixtures/sys_redirect.csv');
159 
160  $expectedConflicts = [
161  [
162  'uri' => 'https://example.com/',
163  'redirect' => [
164  'source_host' => 'example.com',
165  'source_path' => '/',
166  ],
167  ],
168  [
169  'uri' => 'https://example.com/about-us/we-are-here',
170  'redirect' => [
171  'source_host' => '*',
172  'source_path' => '/about-us/we-are-here',
173  ],
174  ],
175  [
176  'uri' => 'https://another.example.com/about-us/we-are-here',
177  'redirect' => [
178  'source_host' => '*',
179  'source_path' => '/about-us/we-are-here',
180  ],
181  ],
182  [
183  'uri' => 'https://another.example.com/de/merkmale',
184  'redirect' => [
185  'source_host' => 'another.example.com',
186  'source_path' => '/de/merkmale',
187  ],
188  ],
189  [
190  'uri' => 'https://example.com/contact',
191  'redirect' => [
192  'source_host' => 'example.com',
193  'source_path' => '/contact',
194  ],
195  ],
196  [
197  'uri' => 'https://example.com/features',
198  'redirect' => [
199  'source_host' => '*',
200  'source_path' => '/features',
201  ],
202  ],
203  [
204  'uri' => 'https://another.example.com/features',
205  'redirect' => [
206  'source_host' => 'another.example.com',
207  'source_path' => '/features',
208  ],
209  ],
210  ];
211 
212  $this->‪assertExpectedPathsFromGenerator($expectedConflicts, $this->subject->findConflictingRedirects());
213  }
214 
215  private function ‪assertExpectedPathsFromGenerator(array $expectedConflicts, \Generator $generator): void
216  {
217  $matches = 0;
218  foreach ($generator as $reportedConflict) {
219  self::assertContains($reportedConflict, $expectedConflicts);
220  $matches++;
221  }
222  self::assertSame(count($expectedConflicts), $matches);
223  }
224 
225  private function ‪prophesizeSiteFinder(): ObjectProphecy
226  {
227  $siteFinderProphecy = $this->prophesize(SiteFinder::class);
228 
229  $simpleSite = new ‪Site('simple-page', 1, [
230  'base' => 'https://example.com',
231  'languages' => [
232  [
233  'languageId' => 0,
234  'title' => 'United States',
235  'locale' => 'en_US.UTF-8',
236  ],
237  ],
238  ]);
239  $localizedSite = new ‪Site('localized-page', 100, [
240  'base' => 'https://another.example.com',
241  'languages' => [
242  [
243  'languageId' => 0,
244  'title' => 'United States',
245  'locale' => 'en_US.UTF-8',
246  ],
247  [
248  'base' => '/de/',
249  'languageId' => 1,
250  'title' => 'DE',
251  'locale' => 'de_DE.UTF-8',
252  ],
253  [
254  'base' => '/fr/',
255  'languageId' => 2,
256  'title' => 'FR',
257  'locale' => 'fr_FR.UTF-8',
258  ],
259  ],
260  ]);
261 
262  $siteFinderProphecy->getSiteByIdentifier('simple-page')->willReturn($simpleSite);
263  $siteFinderProphecy->getSiteByIdentifier('localized-page')->willReturn($localizedSite);
264  $siteFinderProphecy->getAllSites()->willReturn([$simpleSite, $localizedSite]);
265 
266  return $siteFinderProphecy;
267  }
268 }
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\prophesizeSiteFinder
‪prophesizeSiteFinder()
Definition: IntegrityServiceTest.php:222
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\$coreExtensionsToLoad
‪$coreExtensionsToLoad
Definition: IntegrityServiceTest.php:35
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\assertExpectedPathsFromGenerator
‪assertExpectedPathsFromGenerator(array $expectedConflicts, \Generator $generator)
Definition: IntegrityServiceTest.php:212
‪TYPO3\CMS\Redirects\Service\RedirectService
Definition: RedirectService.php:50
‪TYPO3\CMS\Core\Site\SiteFinder
Definition: SiteFinder.php:31
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest
Definition: IntegrityServiceTest.php:30
‪TYPO3\CMS\Core\Site\Entity\Site
Definition: Site.php:42
‪TYPO3\CMS\Redirects\Service\RedirectCacheService
Definition: RedirectCacheService.php:34
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\sourcePathWithMatchingSlugInLocalizedPageIsNotReportedAsConflict
‪sourcePathWithMatchingSlugInLocalizedPageIsNotReportedAsConflict()
Definition: IntegrityServiceTest.php:63
‪TYPO3\CMS\Redirects\Tests\Functional\Service
Definition: IntegrityServiceTest.php:18
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\conflictingRedirectsAreFoundForDefinedSiteOnly
‪conflictingRedirectsAreFoundForDefinedSiteOnly()
Definition: IntegrityServiceTest.php:74
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: IntegrityServiceTest.php:33
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\conflictingRedirectsAreFoundForLocalizedPages
‪conflictingRedirectsAreFoundForLocalizedPages()
Definition: IntegrityServiceTest.php:116
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\$subject
‪IntegrityService $subject
Definition: IntegrityServiceTest.php:39
‪TYPO3\CMS\Redirects\Service\IntegrityService
Definition: IntegrityService.php:32
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\conflictingRedirectsAreFoundForAllSites
‪conflictingRedirectsAreFoundForAllSites()
Definition: IntegrityServiceTest.php:151
‪TYPO3\CMS\Redirects\Tests\Functional\Service\IntegrityServiceTest\setUp
‪setUp()
Definition: IntegrityServiceTest.php:41