ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
URLTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use PHPUnit\Framework\TestCase;
25use ValueError;
26use TypeError;
27use PHPUnit\Framework\Attributes\DataProvider;
28
29class URLTest extends TestCase
30{
31 public function testConstruct(): void
32 {
33 $this->assertInstanceOf(URL::class, new URL());
34 }
35
36 #[DataProvider('provideTransformData')]
37 public function testTransform(string $exptected, string $in): void
38 {
39 $this->assertSame($exptected, (new URL())->transform($in));
40 }
41
42 public function testInvalidEncoding(): void
43 {
44 $this->expectException(ValueError::class);
45 (new URL())->transform(chr(128));
46 }
47
48 public function testInvalidType(): void
49 {
50 $this->expectException(TypeError::class);
51 (new URL())->transform(9);
52 }
53
54 public static function provideTransformData(): array
55 {
56 $alpha = implode('', range(ord('A'), ord('z')));
57 $numbers = implode('', range(ord('0'), ord('9')));
58
59 $data = array_map(fn($s) => [rawurlencode($s), $s], [
60 'Empty string' => '',
61 'Alpha' => $alpha,
62 'Numbers' => $numbers,
63 'Quotes' => "'" . '"',
64 'Different quotes' => '"Hey, y' . "'" . 'all"',
65 'UTF-8' => '두유',
66 'Encode entities' => '&quot;hello&quot;',
67 'Braces' => '{<>}',
68 'HTML special chars' => '<>\'"&',
69 'Characters beyond ASCII value 255' => 'Ā',
70 'Punctuation and unreserved check' => ',._-:;',
71 'Basic control characters and null' => "\r\n\t\0",
72 ]);
73
74 return [
75 ...$data,
76 'PHP quirks from the past' => ['%20~%2B', ' ~+'],
77 ];
78 }
79}
Inspired by: Laminas escaper: https://github.com/laminas/laminas-escaper.
Definition: URL.php:36
testTransform(string $exptected, string $in)
Definition: URLTest.php:37