‪TYPO3CMS  11.5
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 
21 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
22 
26 class ‪UrlValidatorTest extends UnitTestCase
27 {
28  protected string ‪$validatorClassName = UrlValidator::class;
29 
33  protected ‪$validator;
34 
35  protected function ‪setUp(): void
36  {
37  parent::setUp();
38  $this->validator = $this->getMockBuilder($this->validatorClassName)
39  ->onlyMethods(['translateErrorMessage'])
40  ->getMock();
41  }
42 
46  public function ‪urlDataProvider(): array
47  {
48  return [
49  'Regular URL' => [
50  'value' => 'https://typo3.org/',
51  'isValid' => true,
52  ],
53  'Regular URL with subdomain' => [
54  'value' => 'https://testify.typo3.org/',
55  'isValid' => true,
56  ],
57  'Valid URL with trailing slash and path segment' => [
58  'value' => 'https://testify.typo3.org/testify/',
59  'isValid' => true,
60  ],
61  'Valid URL without trailing slash and path segment' => [
62  'value' => 'https://testify.typo3.org/testify',
63  'isValid' => true,
64  ],
65  'mailto' => [
66  'value' => 'mailto:foobar@example.com',
67  'isValid' => true,
68  ],
69  'mailto with subject' => [
70  'value' => 'mailto:foobar@example.com?subject=Unit+test+results',
71  'isValid' => true,
72  ],
73  'ftp' => [
74  'value' => 'ftp://remotestorage.org',
75  'isValid' => true,
76  ],
77  'tel' => [
78  'value' => 'tel:01189998819991197253',
79  'isValid' => true,
80  ],
81  'Some scheme that most likely does not exist' => [
82  'value' => 'monk://convert.wololo',
83  'isValid' => true,
84  ],
85  'Umlauts in domain' => [
86  'value' => 'https://bürgerkarte.at',
87  'isValid' => true,
88  ],
89  'Domain without protocol' => [
90  'value' => 'typo3.org',
91  'isValid' => false,
92  ],
93  'Empty value' => [
94  'value' => '',
95  'isValid' => true,
96  ],
97  'Null value' => [
98  'value' => null,
99  'isValid' => true,
100  ],
101  'Invalid value is only a string' => [
102  'value' => 'testify',
103  'isValid' => false,
104  ],
105  'Invalid value is integer' => [
106  'value' => 1,
107  'isValid' => false,
108  ],
109  'Invalid value is object' => [
110  'value' => new \stdClass(),
111  'isValid' => false,
112  ],
113  'Invalid value is closure' => [
114  'value' => static function () {},
115  'isValid' => false,
116  ],
117  ];
118  }
119 
124  public function ‪urlValidatorDetectsUrlsCorrectly($value, $expected): void
125  {
126  self::assertSame($expected, !$this->validator->validate($value)->hasErrors());
127  }
128 }
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\UrlValidatorTest
Definition: UrlValidatorTest.php:27
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\UrlValidatorTest\urlValidatorDetectsUrlsCorrectly
‪urlValidatorDetectsUrlsCorrectly($value, $expected)
Definition: UrlValidatorTest.php:123
‪TYPO3\CMS\Extbase\Validation\Validator\UrlValidator
Definition: UrlValidator.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\UrlValidatorTest\$validatorClassName
‪string $validatorClassName
Definition: UrlValidatorTest.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\UrlValidatorTest\$validator
‪TYPO3 CMS Extbase Validation Validator UrlValidator $validator
Definition: UrlValidatorTest.php:32
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator
Definition: AbstractCompositeValidatorTest.php:18
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\UrlValidatorTest\urlDataProvider
‪array urlDataProvider()
Definition: UrlValidatorTest.php:45
‪TYPO3\CMS\Extbase\Tests\Unit\Validation\Validator\UrlValidatorTest\setUp
‪setUp()
Definition: UrlValidatorTest.php:34