3 class Sabre_DAV_URLUtilTest extends PHPUnit_Framework_TestCase{
5 function testEncodePath() {
8 for($i=0;$i<128;$i++) $str.=chr($i);
10 $newStr = Sabre_DAV_URLUtil::encodePath($str);
13 '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'.
14 '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'.
15 '%20%21%22%23%24%25%26%27()%2a%2b%2c-./'.
16 '0123456789%3a%3b%3c%3d%3e%3f'.
17 '%40ABCDEFGHIJKLMNO' .
18 'PQRSTUVWXYZ%5b%5c%5d%5e_' .
19 '%60abcdefghijklmno' .
20 'pqrstuvwxyz%7b%7c%7d~%7f',
23 $this->assertEquals($str,Sabre_DAV_URLUtil::decodePath($newStr));
27 function testEncodePathSegment() {
30 for($i=0;$i<128;$i++) $str.=chr($i);
32 $newStr = Sabre_DAV_URLUtil::encodePathSegment($str);
34 // Note: almost exactly the same as the last test, with the
35 // exception of the encoding of / (ascii code 2f)
37 '%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f'.
38 '%10%11%12%13%14%15%16%17%18%19%1a%1b%1c%1d%1e%1f'.
39 '%20%21%22%23%24%25%26%27()%2a%2b%2c-.%2f'.
40 '0123456789%3a%3b%3c%3d%3e%3f'.
41 '%40ABCDEFGHIJKLMNO' .
42 'PQRSTUVWXYZ%5b%5c%5d%5e_' .
43 '%60abcdefghijklmno' .
44 'pqrstuvwxyz%7b%7c%7d~%7f',
47 $this->assertEquals($str,Sabre_DAV_URLUtil::decodePathSegment($newStr));
51 function testDecode() {
53 $str = 'Hello%20Test+Test2.txt';
54 $newStr = Sabre_DAV_URLUtil::decodePath($str);
55 $this->assertEquals('Hello Test+Test2.txt',$newStr);
62 function testDecodeUmlaut() {
64 $str = 'Hello%C3%BC.txt';
65 $newStr = Sabre_DAV_URLUtil::decodePath($str);
66 $this->assertEquals("Hello\xC3\xBC.txt",$newStr);
71 * @depends testDecodeUmlaut
73 function testDecodeUmlautLatin1() {
75 $str = 'Hello%FC.txt';
76 $newStr = Sabre_DAV_URLUtil::decodePath($str);
77 $this->assertEquals("Hello\xC3\xBC.txt",$newStr);
82 * This testcase was sent by a bug reporter
86 function testDecodeAccentsWindows7() {
88 $str = '/webdav/%C3%A0fo%C3%B3';
89 $newStr = Sabre_DAV_URLUtil::decodePath($str);
90 $this->assertEquals(strtolower($str),Sabre_DAV_URLUtil::encodePath($newStr));
94 function testSplitPath() {
98 // input // expected result
99 '/foo/bar' => array('/foo','bar'),
100 '/foo/bar/' => array('/foo','bar'),
101 'foo/bar/' => array('foo','bar'),
102 'foo/bar' => array('foo','bar'),
103 'foo/bar/baz' => array('foo/bar','baz'),
104 'foo/bar/baz/' => array('foo/bar','baz'),
105 'foo' => array('','foo'),
106 'foo/' => array('','foo'),
107 '/foo/' => array('','foo'),
108 '/foo' => array('','foo'),
109 '' => array(null,null),
112 "/\xC3\xA0fo\xC3\xB3/bar" => array("/\xC3\xA0fo\xC3\xB3",'bar'),
113 "/\xC3\xA0foo/b\xC3\xBCr/" => array("/\xC3\xA0foo","b\xC3\xBCr"),
114 "foo/\xC3\xA0\xC3\xBCr" => array("foo","\xC3\xA0\xC3\xBCr"),
118 foreach($strings as $input => $expected) {
120 $output = Sabre_DAV_URLUtil::splitPath($input);
121 $this->assertEquals($expected, $output, 'The expected output for \'' . $input . '\' was incorrect');