2 declare(strict_types = 1);
18 use GuzzleHttp\Cookie\CookieJar;
19 use GuzzleHttp\Exception\ClientException;
20 use GuzzleHttp\Psr7\Response;
21 use Prophecy\Argument;
22 use Prophecy\Prophecy\ObjectProphecy;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
39 $languageServiceProphecy = $this->prophesize(LanguageService::class);
40 $languageServiceProphecy
41 ->includeLLFile(
'EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf');
42 $languageServiceProphecy->getLL(Argument::any())->willReturn(
'translation string');
43 return $languageServiceProphecy;
51 $responseProphecy = $this->prophesize(Response::class);
52 $responseProphecy->getStatusCode()->willReturn(404);
54 $exceptionProphecy = $this->prophesize(ClientException::class);
55 $exceptionProphecy->hasResponse()
57 $exceptionProphecy->getResponse()
58 ->willReturn($responseProphecy->reveal());
60 $url =
'https://example.org/~not-existing-url';
62 $requestFactoryProphecy = $this->prophesize(RequestFactory::class);
63 $requestFactoryProphecy->request($url,
'HEAD', $options)
64 ->willThrow($exceptionProphecy->reveal());
66 $optionsSecondTryWithGET = array_merge_recursive($options, [
'headers' => [
'Range' =>
'bytes=0-4048']]);
67 $requestFactoryProphecy->request($url,
'GET', $optionsSecondTryWithGET)
68 ->willThrow($exceptionProphecy->reveal());
71 $result = $subject->checkLink($url,
null,
null);
73 self::assertSame(
false, $result);
81 $responseProphecy = $this->prophesize(Response::class);
82 $responseProphecy->getStatusCode()->willReturn(404);
84 $exceptionProphecy = $this->prophesize(ClientException::class);
85 $exceptionProphecy->hasResponse()
87 $exceptionProphecy->getResponse()
88 ->willReturn($responseProphecy->reveal());
92 $url =
'https://example.org/~not-existing-url';
93 $requestFactoryProphecy = $this->prophesize(RequestFactory::class);
94 $requestFactoryProphecy->request($url,
'HEAD', $options)
95 ->willThrow($exceptionProphecy->reveal());
96 $optionsSecondTryWithGET = array_merge_recursive($options, [
'headers' => [
'Range' =>
'bytes=0-4048']]);
97 $requestFactoryProphecy->request($url,
'GET', $optionsSecondTryWithGET)
98 ->willThrow($exceptionProphecy->reveal());
101 $subject->checkLink($url,
null,
null);
102 $result = $subject->getErrorParams()[
'errorType'];
104 self::assertSame(404, $result);
109 $cookieJar = $this->prophesize(CookieJar::class);
110 $cookieJar = $cookieJar->reveal();
111 GeneralUtility::addInstance(CookieJar::class, $cookieJar);
119 'allow_redirects' => [
'strict' =>
true],
121 'User-Agent' =>
'TYPO3 linkvalidator',
123 'Accept-Language' =>
'*',
124 'Accept-Encoding' =>
'*'
132 yield
'faulty URL with mailto' => [
133 'mailto:http://example.org',
134 'mailto:http://example.org'
136 yield
'Relative URL' => [
142 yield
'URL with query parameter and ampersand' => [
143 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829',
144 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829'
146 yield
'URL with query parameter and ampersand with HTML entities' => [
147 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829',
148 'https://standards.cen.eu/dyn/www/f?p=204:6:0::::FSP_ORG_ID,FSP_LANG_ID:,22&cs=1A3FFBC44FAB6B2A181C9525249C3A829'
152 yield
'URL with path with dashes' => [
153 'https://example.com/Unternehmen/Ausbildung-Qualifikation/Weiterbildung-in-Niedersachsen/',
154 'https://example.com/Unternehmen/Ausbildung-Qualifikation/Weiterbildung-in-Niedersachsen/'
156 yield
'URL with path with dashes (2)' => [
157 'https://example.com/startseite/wirtschaft/wirtschaftsfoerderung/beratung-foerderung/gruenderberatung/gruenderforen.html',
158 'https://example.com/startseite/wirtschaft/wirtschaftsfoerderung/beratung-foerderung/gruenderberatung/gruenderforen.html'
160 yield
'URL with path with dashes (3)' => [
161 'http://example.com/universitaet/die-uni-im-ueberblick/lageplan/gebaeude/building/120',
162 'http://example.com/universitaet/die-uni-im-ueberblick/lageplan/gebaeude/building/120'
164 yield
'URL with path and query parameters (including &, ~,; etc.)' => [
165 'http://example.com/tv?bcpid=1701167454001&bckey=AQ~~,AAAAAGL7LqU~,aXlKNnCf9d9Tmck-kOc4PGFfCgHjM5JR&bctid=1040702768001',
166 'http://example.com/tv?bcpid=1701167454001&bckey=AQ~~,AAAAAGL7LqU~,aXlKNnCf9d9Tmck-kOc4PGFfCgHjM5JR&bctid=1040702768001'
170 yield
'URL with query parameters, fragment, user, pass, port etc.' => [
171 'http://usr:pss@example.com:81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment',
172 'http://usr:pss@example.com:81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment'
174 yield
'domain with special characters, URL with query parameters, fragment, user, pass, port etc.' => [
175 'http://usr:pss@äxample.com:81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment',
176 'http://usr:pss@xn--xample-9ta.com:81/mypath/myfile.html?a=b&b[]=2&b[]=3#myfragment'
180 yield
'domain with special characters' => [
181 'https://www.grün-example.org',
182 'https://www.xn--grn-example-uhb.org'
184 yield
'domain with special characters and path' => [
185 'https://www.grün-example.org/a/bcd-efg/sfsfsfsfsf',
186 'https://www.xn--grn-example-uhb.org/a/bcd-efg/sfsfsfsfsf'
197 $method = new \ReflectionMethod($subject,
'preprocessUrl');
198 $method->setAccessible(
true);
199 $result = $method->invokeArgs($subject, [$inputUrl]);
200 $this->assertEquals($result, $expectedResult);