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