‪TYPO3CMS  ‪main
UrlValidatorTest.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 PHPUnit\Framework\Attributes\DataProvider;
21 use PHPUnit\Framework\Attributes\Test;
26 use TYPO3\TestingFramework\Core\Functional\FunctionalTestCase;
27 
28 final class ‪UrlValidatorTest extends FunctionalTestCase
29 {
30  protected function ‪setUp(): void
31  {
32  parent::setUp();
33  ‪$GLOBALS['LANG'] = $this->get(LanguageServiceFactory::class)->create('default');
34  $request = (new ‪ServerRequest())->withAttribute('applicationType', ‪SystemEnvironmentBuilder::REQUESTTYPE_BE);
35  ‪$GLOBALS['TYPO3_REQUEST'] = $request;
36  }
37 
38  public static function ‪urlDataProvider(): array
39  {
40  return [
41  'Regular URL' => [
42  'value' => 'https://typo3.org/',
43  'isValid' => true,
44  ],
45  'Regular URL with subdomain' => [
46  'value' => 'https://testify.typo3.org/',
47  'isValid' => true,
48  ],
49  'Valid URL with trailing slash and path segment' => [
50  'value' => 'https://testify.typo3.org/testify/',
51  'isValid' => true,
52  ],
53  'Valid URL without trailing slash and path segment' => [
54  'value' => 'https://testify.typo3.org/testify',
55  'isValid' => true,
56  ],
57  'mailto' => [
58  'value' => 'mailto:foobar@example.com',
59  'isValid' => true,
60  ],
61  'mailto with subject' => [
62  'value' => 'mailto:foobar@example.com?subject=Unit+test+results',
63  'isValid' => true,
64  ],
65  'ftp' => [
66  'value' => 'ftp://remotestorage.org',
67  'isValid' => true,
68  ],
69  'tel' => [
70  'value' => 'tel:01189998819991197253',
71  'isValid' => true,
72  ],
73  'Some scheme that most likely does not exist' => [
74  'value' => 'monk://convert.wololo',
75  'isValid' => true,
76  ],
77  'Umlauts in domain' => [
78  'value' => 'https://bürgerkarte.at',
79  'isValid' => true,
80  ],
81  'Domain without protocol' => [
82  'value' => 'typo3.org',
83  'isValid' => false,
84  ],
85  'Empty value' => [
86  'value' => '',
87  'isValid' => true,
88  ],
89  'Null value' => [
90  'value' => null,
91  'isValid' => true,
92  ],
93  'Invalid value is only a string' => [
94  'value' => 'testify',
95  'isValid' => false,
96  ],
97  'Invalid value is integer' => [
98  'value' => 1,
99  'isValid' => false,
100  ],
101  'Invalid value is object' => [
102  'value' => new \stdClass(),
103  'isValid' => false,
104  ],
105  'Invalid value is closure' => [
106  'value' => static function () {},
107  'isValid' => false,
108  ],
109  ];
110  }
111 
112  #[DataProvider('urlDataProvider')]
113  #[Test]
114  public function ‪urlValidatorDetectsUrlsCorrectly($value, $isValid): void
115  {
117  ‪$validator->setOptions([]);
118  self::assertSame($isValid, !‪$validator->validate($value)->hasErrors());
119  }
120 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\UrlValidatorTest
Definition: UrlValidatorTest.php:29
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator
Definition: AlphanumericValidatorTest.php:18
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder
Definition: SystemEnvironmentBuilder.php:41
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\UrlValidatorTest\urlValidatorDetectsUrlsCorrectly
‪urlValidatorDetectsUrlsCorrectly($value, $isValid)
Definition: UrlValidatorTest.php:114
‪TYPO3\CMS\Core\Core\SystemEnvironmentBuilder\REQUESTTYPE_BE
‪const REQUESTTYPE_BE
Definition: SystemEnvironmentBuilder.php:45
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\UrlValidatorTest\urlDataProvider
‪static urlDataProvider()
Definition: UrlValidatorTest.php:38
‪TYPO3\CMS\Extbase\Validation\Validator\UrlValidator
Definition: UrlValidator.php:26
‪$validator
‪if(isset($args['d'])) $validator
Definition: validateRstFiles.php:262
‪TYPO3\CMS\Core\Http\ServerRequest
Definition: ServerRequest.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extbase\Tests\Functional\Validation\Validator\UrlValidatorTest\setUp
‪setUp()
Definition: UrlValidatorTest.php:30