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