‪TYPO3CMS  10.4
LinkAnalyzerTest.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 Psr\EventDispatcher\EventDispatcherInterface;
24 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
25 
26 class ‪LinkAnalyzerTest extends FunctionalTestCase
27 {
29  'seo',
30  'linkvalidator',
31  ];
32 
37  protected function ‪setUp(): void
38  {
39  parent::setUp();
40  ‪$GLOBALS['LANG'] = ‪LanguageService::create('default');
41  }
42 
43  public function ‪findAllBrokenLinksDataProvider(): array
44  {
45  return [
46  'Test with one broken external link (not existing domain)' =>
47  [
48  __DIR__ . '/Fixtures/input_content_with_broken_link_external.xml',
49  '1',
50  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_external.csv'
51  ],
52  'Test with one broken external link in pages:canonical_link' =>
53  [
54  __DIR__ . '/Fixtures/input_page_with_broken_link_external_in_canonical_link.xml',
55  '1',
56  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_with_broken_link_external_in_canonical_link.csv'
57  ],
58  'Test with one broken page link (not existing page)' =>
59  [
60  __DIR__ . '/Fixtures/input_content_with_broken_link_page.xml',
61  '1',
62  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_page.csv'
63  ],
64  'Test with one broken file link (not existing file)' =>
65  [
66  __DIR__ . '/Fixtures/input_content_with_broken_link_file.xml',
67  '1',
68  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_file.csv'
69  ],
70  'Test with several broken external, page and file links' =>
71  [
72  __DIR__ . '/Fixtures/input_content_with_broken_links_several.xml',
73  '1',
74  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_links_several.csv'
75  ],
76  'Test with several pages with broken external, page and file links' =>
77  [
78  __DIR__ . '/Fixtures/input_content_with_broken_links_several_pages.xml',
79  '1,2',
80  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_links_several_pages.csv'
81  ],
82  ];
83  }
84 
89  public function ‪getLinkStatisticsFindAllBrokenLinks(string $inputFile, string $pidList, string $expectedOutputFile)
90  {
91  $config = [
92  'db' => '1',
93  'file' => '1',
94  'external' => '1',
95  'linkhandler' => '1'
96 
97  ];
98 
99  $tsConfig = [
100  'searchFields' => [
101  'pages' => ['media', 'url', 'canonical_link'],
102  'tt_content' => ['bodytext', 'header_link', 'records']
103  ],
104  'linktypes' => 'db,file,external,linkhandler',
105  'checkhidden' => '0',
106  'linkhandler' => [
107  'reportHiddenRecords' => '0'
108  ]
109  ];
110 
111  $searchFields = $tsConfig['searchFields'];
112 
113  $this->importDataSet($inputFile);
114 
115  $linkAnalyzer = new ‪LinkAnalyzer(
116  $this->prophesize(EventDispatcherInterface::class)->reveal(),
118  );
119  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
120  $linkAnalyzer->getLinkStatistics($config);
121 
122  $this->assertCSVDataSet($expectedOutputFile);
123  }
124 
126  {
127  return [
128  // Tests with one broken link
129  'Test with one broken external link' =>
130  [
131  __DIR__ . '/Fixtures/input_content_with_broken_link_external.xml',
132  '1',
133  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
134  ],
135  'Test with one broken page link' =>
136  [
137  __DIR__ . '/Fixtures/input_content_with_broken_link_page.xml',
138  '1',
139  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
140  ],
141  'Test with one broken file link' =>
142  [
143  __DIR__ . '/Fixtures/input_content_with_broken_link_file.xml',
144  '1',
145  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_file.csv'
146  ],
147  ];
148  }
149 
154  public function ‪getLinkStatisticsFindOnlyFileBrokenLinks(string $inputFile, string $pidList, string $expectedOutputFile)
155  {
156  $config = [
157  'db' => '0',
158  'file' => '1',
159  'external' => '0',
160  'linkhandler' => '0'
161 
162  ];
163 
164  $tsConfig = [
165  'searchFields' => [
166  'pages' => ['media', 'url'],
167  'tt_content' => ['bodytext', 'header_link', 'records']
168  ],
169  'linktypes' => 'file',
170  'checkhidden' => '0',
171  'linkhandler' => [
172  'reportHiddenRecords' => '0'
173  ]
174  ];
175 
176  $searchFields = $tsConfig['searchFields'];
177 
178  $this->importDataSet($inputFile);
179 
180  $linkAnalyzer = new ‪LinkAnalyzer(
181  $this->prophesize(EventDispatcherInterface::class)->reveal(),
183  );
184  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
185  $linkAnalyzer->getLinkStatistics($config);
186 
187  $this->assertCSVDataSet($expectedOutputFile);
188  }
189 
191  {
192  return [
193  // Tests with one broken link
194  'Test with one broken external link' =>
195  [
196  __DIR__ . '/Fixtures/input_content_with_broken_link_external.xml',
197  '1',
198  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
199  ],
200  'Test with one broken page link' =>
201  [
202  __DIR__ . '/Fixtures/input_content_with_broken_link_page.xml',
203  '1',
204  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_page.csv'
205  ],
206  'Test with one broken file link' =>
207  [
208  __DIR__ . '/Fixtures/input_content_with_broken_link_file.xml',
209  '1',
210  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
211  ],
212  ];
213  }
214 
219  public function ‪getLinkStatisticsFindOnlyPageBrokenLinks(string $inputFile, string $pidList, string $expectedOutputFile)
220  {
221  $config = [
222  'db' => '1',
223  'file' => '0',
224  'external' => '0',
225  'linkhandler' => '0'
226 
227  ];
228 
229  $tsConfig = [
230  'searchFields' => [
231  'pages' => ['media', 'url'],
232  'tt_content' => ['bodytext', 'header_link', 'records']
233  ],
234  'linktypes' => 'db',
235  'checkhidden' => '0',
236  'linkhandler' => [
237  'reportHiddenRecords' => '0'
238  ]
239  ];
240 
241  $searchFields = $tsConfig['searchFields'];
242 
243  $this->importDataSet($inputFile);
244 
245  $linkAnalyzer = new ‪LinkAnalyzer(
246  $this->prophesize(EventDispatcherInterface::class)->reveal(),
248  );
249  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
250  $linkAnalyzer->getLinkStatistics($config);
251 
252  $this->assertCSVDataSet($expectedOutputFile);
253  }
254 
256  {
257  return [
258  // Tests with one broken link
259  'Test with one broken external link' =>
260  [
261  __DIR__ . '/Fixtures/input_content_with_broken_link_external.xml',
262  '1',
263  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_external.csv'
264  ],
265  'Test with one broken page link' =>
266  [
267  __DIR__ . '/Fixtures/input_content_with_broken_link_page.xml',
268  '1',
269  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
270  ],
271  'Test with one broken file link' =>
272  [
273  __DIR__ . '/Fixtures/input_content_with_broken_link_file.xml',
274  '1',
275  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
276  ],
277  ];
278  }
279 
284  public function ‪getLinkStatisticsFindOnlyExternalBrokenLinksInBodytext(string $inputFile, string $pidList, string $expectedOutputFile)
285  {
286  $config = [
287  'db' => '0',
288  'file' => '0',
289  'external' => '1',
290  'linkhandler' => '0'
291 
292  ];
293 
294  $tsConfig = [
295  'searchFields' => [
296  'tt_content' => ['bodytext']
297  ],
298  'linktypes' => 'external',
299  'checkhidden' => '0',
300  'linkhandler' => [
301  'reportHiddenRecords' => '0'
302  ]
303  ];
304 
305  $searchFields = $tsConfig['searchFields'];
306 
307  $this->importDataSet($inputFile);
308 
309  $linkAnalyzer = new ‪LinkAnalyzer(
310  $this->prophesize(EventDispatcherInterface::class)->reveal(),
312  );
313  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
314  $linkAnalyzer->getLinkStatistics($config);
315 
316  $this->assertCSVDataSet($expectedOutputFile);
317  }
318 }
‪TYPO3\CMS\Linkvalidator\Tests\Functional
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Localization\LanguageService\create
‪static static create(string $locale)
Definition: LanguageService.php:430