]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/tests/Sabre/DAV/URLUtilTest.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / tests / Sabre / DAV / URLUtilTest.php
1 <?php
2
3 class Sabre_DAV_URLUtilTest extends PHPUnit_Framework_TestCase{
4
5     function testEncodePath() {
6
7         $str = '';
8         for($i=0;$i<128;$i++) $str.=chr($i);
9
10         $newStr = Sabre_DAV_URLUtil::encodePath($str);
11
12         $this->assertEquals(
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',
21             $newStr);
22
23         $this->assertEquals($str,Sabre_DAV_URLUtil::decodePath($newStr));
24
25     }
26
27     function testEncodePathSegment() {
28
29         $str = '';
30         for($i=0;$i<128;$i++) $str.=chr($i);
31
32         $newStr = Sabre_DAV_URLUtil::encodePathSegment($str);
33
34         // Note: almost exactly the same as the last test, with the
35         // exception of the encoding of / (ascii code 2f)
36         $this->assertEquals(
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',
45             $newStr);
46
47         $this->assertEquals($str,Sabre_DAV_URLUtil::decodePathSegment($newStr));
48
49     }
50
51     function testDecode() {
52
53         $str = 'Hello%20Test+Test2.txt';
54         $newStr = Sabre_DAV_URLUtil::decodePath($str);
55         $this->assertEquals('Hello Test+Test2.txt',$newStr);
56
57     }
58
59     /**
60      * @depends testDecode
61      */
62     function testDecodeUmlaut() {
63
64         $str = 'Hello%C3%BC.txt';
65         $newStr = Sabre_DAV_URLUtil::decodePath($str);
66         $this->assertEquals("Hello\xC3\xBC.txt",$newStr);
67
68     }
69
70     /**
71      * @depends testDecodeUmlaut
72      */
73     function testDecodeUmlautLatin1() {
74
75         $str = 'Hello%FC.txt';
76         $newStr = Sabre_DAV_URLUtil::decodePath($str);
77         $this->assertEquals("Hello\xC3\xBC.txt",$newStr);
78
79     }
80
81     /**
82      * This testcase was sent by a bug reporter
83      *
84      * @depends testDecode
85      */
86     function testDecodeAccentsWindows7() {
87
88         $str = '/webdav/%C3%A0fo%C3%B3';
89         $newStr = Sabre_DAV_URLUtil::decodePath($str);
90         $this->assertEquals(strtolower($str),Sabre_DAV_URLUtil::encodePath($newStr));
91
92     }
93
94     function testSplitPath() {
95
96         $strings = array(
97
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),
110
111             // UTF-8
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"),
115
116         );
117
118         foreach($strings as $input => $expected) {
119
120             $output = Sabre_DAV_URLUtil::splitPath($input);
121             $this->assertEquals($expected, $output, 'The expected output for \'' . $input . '\' was incorrect');
122
123
124         }
125
126
127     }
128
129 }