ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ilWhiteListUrlValidatorTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use PHPUnit\Framework\TestCase;
23
24final class ilWhiteListUrlValidatorTest extends TestCase
25{
26 public static function domainProvider(): array
27 {
28 return [
29 'Empty String / Empty Whitelist' => ['', [], false],
30 'Host without Schema / Empty Whitelist' => ['ilias.de', [], false],
31 'Schema with Host / Empty Whitelist' => ['https://ilias.de', [], false],
32 'Host without Schema' => ['ilias.de', ['ilias.de'], false],
33 'Schema with Host' => ['https://ilias.de', ['ilias.de'], true],
34 'Sub Domain' => ['https://www.ilias.de', ['ilias.de'], true],
35 'Multiple Sub Domains' => ['https://server01.www.ilias.de', ['ilias.de'], true],
36 'Multiple Sub Domains / Whitelist Entry with Leading Dot' => [
37 'https://server01.www.ilias.de',
38 ['.ilias.de'],
39 true
40 ],
41 'Multiple Sub Domains / Whitelist Entry with Sub Domain' => [
42 'https://server01.www.ilias.de',
43 ['www.ilias.de'],
44 true
45 ],
46 'Multiple Sub Domains / Whitelist Entry with Sub Domain and Leading Dot' => [
47 'https://server01.www.ilias.de',
48 ['.www.ilias.de'],
49 true
50 ],
51 'Multiple Sub Domains / Whitelist Entry with Multiple Sub Domains' => [
52 'https://server01.www.ilias.de',
53 ['server01.www.ilias.de'],
54 true
55 ],
56 'Multiple Sub Domains / Whitelist Entry with Multiple Sub Domains and Leading Dot' => [
57 'https://server01.www.ilias.de',
58 ['.server01.www.ilias.de'],
59 false
60 ],
61 ];
62 }
63
64 #[\PHPUnit\Framework\Attributes\DataProvider('domainProvider')]
65 public function testValidator(string $domain, array $whitelist, bool $result): void
66 {
67 $this->assertSame((new WhiteListUrlValidator($domain, $whitelist))->isValid(), $result);
68 }
69}
return true
testValidator(string $domain, array $whitelist, bool $result)