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