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