ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
URLUtilTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Sabre\HTTP;
4 
6 
7  function testEncodePath() {
8 
9  $str = '';
10  for ($i = 0;$i < 128;$i++) $str .= chr($i);
11 
12  $newStr = URLUtil::encodePath($str);
13 
14  $this->assertEquals(
15  '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f' .
16  '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f' .
17  '%20%21%22%23%24%25%26%27()%2a%2b%2c-./' .
18  '0123456789:%3b%3c%3d%3e%3f' .
19  '@ABCDEFGHIJKLMNO' .
20  'PQRSTUVWXYZ%5b%5c%5d%5e_' .
21  '%60abcdefghijklmno' .
22  'pqrstuvwxyz%7b%7c%7d~%7f',
23  $newStr);
24 
25  $this->assertEquals($str, URLUtil::decodePath($newStr));
26 
27  }
28 
29  function testEncodePathSegment() {
30 
31  $str = '';
32  for ($i = 0;$i < 128;$i++) $str .= chr($i);
33 
34  $newStr = URLUtil::encodePathSegment($str);
35 
36  // Note: almost exactly the same as the last test, with the
37  // exception of the encoding of / (ascii code 2f)
38  $this->assertEquals(
39  '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f' .
40  '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f' .
41  '%20%21%22%23%24%25%26%27()%2a%2b%2c-.%2f' .
42  '0123456789:%3b%3c%3d%3e%3f' .
43  '@ABCDEFGHIJKLMNO' .
44  'PQRSTUVWXYZ%5b%5c%5d%5e_' .
45  '%60abcdefghijklmno' .
46  'pqrstuvwxyz%7b%7c%7d~%7f',
47  $newStr);
48 
49  $this->assertEquals($str, URLUtil::decodePathSegment($newStr));
50 
51  }
52 
53  function testDecode() {
54 
55  $str = 'Hello%20Test+Test2.txt';
56  $newStr = URLUtil::decodePath($str);
57  $this->assertEquals('Hello Test+Test2.txt', $newStr);
58 
59  }
60 
64  function testDecodeUmlaut() {
65 
66  $str = 'Hello%C3%BC.txt';
67  $newStr = URLUtil::decodePath($str);
68  $this->assertEquals("Hello\xC3\xBC.txt", $newStr);
69 
70  }
71 
76 
77  $str = 'Hello%FC.txt';
78  $newStr = URLUtil::decodePath($str);
79  $this->assertEquals("Hello\xC3\xBC.txt", $newStr);
80 
81  }
82 
89 
90  $str = '/webdav/%C3%A0fo%C3%B3';
91  $newStr = URLUtil::decodePath($str);
92  $this->assertEquals(strtolower($str), URLUtil::encodePath($newStr));
93 
94  }
95 
96  function testSplitPath() {
97 
98  $strings = [
99 
100  // input // expected result
101  '/foo/bar' => ['/foo','bar'],
102  '/foo/bar/' => ['/foo','bar'],
103  'foo/bar/' => ['foo','bar'],
104  'foo/bar' => ['foo','bar'],
105  'foo/bar/baz' => ['foo/bar','baz'],
106  'foo/bar/baz/' => ['foo/bar','baz'],
107  'foo' => ['','foo'],
108  'foo/' => ['','foo'],
109  '/foo/' => ['','foo'],
110  '/foo' => ['','foo'],
111  '' => [null,null],
112 
113  // UTF-8
114  "/\xC3\xA0fo\xC3\xB3/bar" => ["/\xC3\xA0fo\xC3\xB3",'bar'],
115  "/\xC3\xA0foo/b\xC3\xBCr/" => ["/\xC3\xA0foo","b\xC3\xBCr"],
116  "foo/\xC3\xA0\xC3\xBCr" => ["foo","\xC3\xA0\xC3\xBCr"],
117 
118  ];
119 
120  foreach ($strings as $input => $expected) {
121 
123  $this->assertEquals($expected, $output, 'The expected output for \'' . $input . '\' was incorrect');
124 
125 
126  }
127 
128  }
129 
133  function testResolve($base, $update, $expected) {
134 
135  $this->assertEquals(
136  $expected,
137  URLUtil::resolve($base, $update)
138  );
139 
140  }
141 
142  function resolveData() {
143 
144  return [
145  [
146  'http://example.org/foo/baz',
147  '/bar',
148  'http://example.org/bar',
149  ],
150  [
151  'https://example.org/foo',
152  '//example.net/',
153  'https://example.net/',
154  ],
155  [
156  'https://example.org/foo',
157  '?a=b',
158  'https://example.org/foo?a=b',
159  ],
160  [
161  '//example.org/foo',
162  '?a=b',
163  '//example.org/foo?a=b',
164  ],
165  // Ports and fragments
166  [
167  'https://example.org:81/foo#hey',
168  '?a=b#c=d',
169  'https://example.org:81/foo?a=b#c=d',
170  ],
171  // Relative.. in-directory paths
172  [
173  'http://example.org/foo/bar',
174  'bar2',
175  'http://example.org/foo/bar2',
176  ],
177  // Now the base path ended with a slash
178  [
179  'http://example.org/foo/bar/',
180  'bar2/bar3',
181  'http://example.org/foo/bar/bar2/bar3',
182  ],
183  ];
184 
185  }
186 
187 }
testDecodeUmlautLatin1()
testDecodeUmlaut
Definition: URLUtilTest.php:75
static encodePathSegment($pathSegment)
Encodes a 1 segment of a path.
Definition: URLUtil.php:44
static http()
Fetches the global http state from ILIAS.
testDecodeAccentsWindows7()
This testcase was sent by a bug reporter.
Definition: URLUtilTest.php:88
static decodePath($path)
Decodes a url-encoded path.
Definition: URLUtil.php:57
$i
Definition: disco.tpl.php:19
static decodePathSegment($path)
Decodes a url-encoded path segment.
Definition: URLUtil.php:70
static encodePath($path)
Encodes the path of a url.
Definition: URLUtil.php:29
static splitPath($path)
Returns the &#39;dirname&#39; and &#39;basename&#39; for a path.
Definition: URLUtil.php:83
testDecodeUmlaut()
testDecode
Definition: URLUtilTest.php:64