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