‪TYPO3CMS  9.5
LinkAnalyzerTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
21 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
22 
23 class ‪LinkAnalyzerTest extends FunctionalTestCase
24 {
26  'seo',
27  'linkvalidator',
28  ];
29 
34  protected function ‪setUp(): void
35  {
36  parent::setUp();
37 
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.xml',
47  '1',
48  'EXT:linkvalidator/Tests/Functional/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.xml',
53  '1',
54  'EXT:linkvalidator/Tests/Functional/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.xml',
59  '1',
60  'EXT:linkvalidator/Tests/Functional/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.xml',
65  '1',
66  'EXT:linkvalidator/Tests/Functional/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.xml',
71  '1',
72  'EXT:linkvalidator/Tests/Functional/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.xml',
77  '1,2',
78  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_links_several_pages.csv'
79  ],
80  ];
81  }
82 
87  public function ‪getLinkStatisticsFindAllBrokenLinks(string $inputFile, string $pidList, string $expectedOutputFile)
88  {
89  $config = [
90  'db' => '1',
91  'file' => '1',
92  'external' => '1',
93  'linkhandler' => '1'
94 
95  ];
96 
97  $tsConfig = [
98  'searchFields' => [
99  'pages' => ['media', 'url', 'canonical_link'],
100  'tt_content' => ['bodytext', 'header_link', 'records']
101  ],
102  'linktypes' => 'db,file,external,linkhandler',
103  'checkhidden' => '0',
104  'linkhandler' => [
105  'reportHiddenRecords' => '0'
106  ]
107  ];
108 
109  $searchFields = $tsConfig['searchFields'];
110 
111  $this->importDataSet($inputFile);
112 
113  $linkAnalyzer = new ‪LinkAnalyzer();
114  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
115  $linkAnalyzer->getLinkStatistics($config);
116 
117  $this->assertCSVDataSet($expectedOutputFile);
118  }
119 
121  {
122  return [
123  // Tests with one broken link
124  'Test with one broken external link' =>
125  [
126  __DIR__ . '/Fixtures/input_content_with_broken_link_external.xml',
127  '1',
128  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
129  ],
130  'Test with one broken page link' =>
131  [
132  __DIR__ . '/Fixtures/input_content_with_broken_link_page.xml',
133  '1',
134  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
135  ],
136  'Test with one broken file link' =>
137  [
138  __DIR__ . '/Fixtures/input_content_with_broken_link_file.xml',
139  '1',
140  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_file.csv'
141  ],
142  ];
143  }
144 
149  public function ‪getLinkStatisticsFindOnlyFileBrokenLinks(string $inputFile, string $pidList, string $expectedOutputFile)
150  {
151  $config = [
152  'db' => '0',
153  'file' => '1',
154  'external' => '0',
155  'linkhandler' => '0'
156 
157  ];
158 
159  $tsConfig = [
160  'searchFields' => [
161  'pages' => ['media', 'url'],
162  'tt_content' => ['bodytext', 'header_link', 'records']
163  ],
164  'linktypes' => 'file',
165  'checkhidden' => '0',
166  'linkhandler' => [
167  'reportHiddenRecords' => '0'
168  ]
169  ];
170 
171  $searchFields = $tsConfig['searchFields'];
172 
173  $this->importDataSet($inputFile);
174 
175  $linkAnalyzer = new ‪LinkAnalyzer();
176  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
177  $linkAnalyzer->getLinkStatistics($config);
178 
179  $this->assertCSVDataSet($expectedOutputFile);
180  }
181 
183  {
184  return [
185  // Tests with one broken link
186  'Test with one broken external link' =>
187  [
188  __DIR__ . '/Fixtures/input_content_with_broken_link_external.xml',
189  '1',
190  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
191  ],
192  'Test with one broken page link' =>
193  [
194  __DIR__ . '/Fixtures/input_content_with_broken_link_page.xml',
195  '1',
196  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_page.csv'
197  ],
198  'Test with one broken file link' =>
199  [
200  __DIR__ . '/Fixtures/input_content_with_broken_link_file.xml',
201  '1',
202  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
203  ],
204  ];
205  }
206 
211  public function ‪getLinkStatisticsFindOnlyPageBrokenLinks(string $inputFile, string $pidList, string $expectedOutputFile)
212  {
213  $config = [
214  'db' => '1',
215  'file' => '0',
216  'external' => '0',
217  'linkhandler' => '0'
218 
219  ];
220 
221  $tsConfig = [
222  'searchFields' => [
223  'pages' => ['media', 'url'],
224  'tt_content' => ['bodytext', 'header_link', 'records']
225  ],
226  'linktypes' => 'db',
227  'checkhidden' => '0',
228  'linkhandler' => [
229  'reportHiddenRecords' => '0'
230  ]
231  ];
232 
233  $searchFields = $tsConfig['searchFields'];
234 
235  $this->importDataSet($inputFile);
236 
237  $linkAnalyzer = new ‪LinkAnalyzer();
238  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
239  $linkAnalyzer->getLinkStatistics($config);
240 
241  $this->assertCSVDataSet($expectedOutputFile);
242  }
243 
245  {
246  return [
247  // Tests with one broken link
248  'Test with one broken external link' =>
249  [
250  __DIR__ . '/Fixtures/input_content_with_broken_link_external.xml',
251  '1',
252  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_external.csv'
253  ],
254  'Test with one broken page link' =>
255  [
256  __DIR__ . '/Fixtures/input_content_with_broken_link_page.xml',
257  '1',
258  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
259  ],
260  'Test with one broken file link' =>
261  [
262  __DIR__ . '/Fixtures/input_content_with_broken_link_file.xml',
263  '1',
264  'EXT:linkvalidator/Tests/Functional/Fixtures/expected_output_content_with_broken_link_none.csv'
265  ],
266  ];
267  }
268 
273  public function ‪getLinkStatisticsFindOnlyExternalBrokenLinksInBodytext(string $inputFile, string $pidList, string $expectedOutputFile)
274  {
275  $config = [
276  'db' => '0',
277  'file' => '0',
278  'external' => '1',
279  'linkhandler' => '0'
280 
281  ];
282 
283  $tsConfig = [
284  'searchFields' => [
285  'tt_content' => ['bodytext']
286  ],
287  'linktypes' => 'external',
288  'checkhidden' => '0',
289  'linkhandler' => [
290  'reportHiddenRecords' => '0'
291  ]
292  ];
293 
294  $searchFields = $tsConfig['searchFields'];
295 
296  $this->importDataSet($inputFile);
297 
298  $linkAnalyzer = new ‪LinkAnalyzer();
299  $linkAnalyzer->init($searchFields, $pidList, $tsConfig);
300  $linkAnalyzer->getLinkStatistics($config);
301 
302  $this->assertCSVDataSet($expectedOutputFile);
303  }
304 }
‪TYPO3\CMS\Linkvalidator\Tests\Functional
Definition: LinkAnalyzerTest.php:4
‪TYPO3\CMS\Core\Core\Bootstrap
Definition: Bootstrap.php:50
‪TYPO3\CMS\Core\Core\Bootstrap\initializeLanguageObject
‪static Bootstrap null initializeLanguageObject()
Definition: Bootstrap.php:986