ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
URLTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 use ValueError;
26 use TypeError;
28 
29 class 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 }
testTransform(string $exptected, string $in)
Definition: URLTest.php:37
Inspired by: Laminas escaper: https://github.com/laminas/laminas-escaper.
Definition: URL.php:35