@@ -45,20 +45,98 @@ public function setUp(){
45
45
OC_Filesystem::clearMounts ();
46
46
}
47
47
48
- public function testMount (){
49
- OC_Filesystem::mount ('OC_Filestorage_Local ' ,self ::getStorageData (),'/ ' );
50
- $ this ->assertEqual ('/ ' ,OC_Filesystem::getMountPoint ('/ ' ));
51
- $ this ->assertEqual ('/ ' ,OC_Filesystem::getMountPoint ('/some/folder ' ));
52
- $ this ->assertEqual ('' ,OC_Filesystem::getInternalPath ('/ ' ));
53
- $ this ->assertEqual ('some/folder ' ,OC_Filesystem::getInternalPath ('/some/folder ' ));
54
-
55
- OC_Filesystem::mount ('OC_Filestorage_Local ' ,self ::getStorageData (),'/some ' );
56
- $ this ->assertEqual ('/ ' ,OC_Filesystem::getMountPoint ('/ ' ));
57
- $ this ->assertEqual ('/some/ ' ,OC_Filesystem::getMountPoint ('/some/folder ' ));
58
- $ this ->assertEqual ('/some/ ' ,OC_Filesystem::getMountPoint ('/some/ ' ));
59
- $ this ->assertEqual ('/ ' ,OC_Filesystem::getMountPoint ('/some ' ));
60
- $ this ->assertEqual ('folder ' ,OC_Filesystem::getInternalPath ('/some/folder ' ));
48
+ public function testMount () {
49
+ OC_Filesystem::mount ('OC_Filestorage_Local ' , self ::getStorageData (), '/ ' );
50
+ $ this ->assertEqual ('/ ' , OC_Filesystem::getMountPoint ('/ ' ));
51
+ $ this ->assertEqual ('/ ' , OC_Filesystem::getMountPoint ('/some/folder ' ));
52
+ $ this ->assertEqual ('' , OC_Filesystem::getInternalPath ('/ ' ));
53
+ $ this ->assertEqual ('some/folder ' , OC_Filesystem::getInternalPath ('/some/folder ' ));
54
+
55
+ OC_Filesystem::mount ('OC_Filestorage_Local ' , self ::getStorageData (), '/some ' );
56
+ $ this ->assertEqual ('/ ' , OC_Filesystem::getMountPoint ('/ ' ));
57
+ $ this ->assertEqual ('/some/ ' , OC_Filesystem::getMountPoint ('/some/folder ' ));
58
+ $ this ->assertEqual ('/some/ ' , OC_Filesystem::getMountPoint ('/some/ ' ));
59
+ $ this ->assertEqual ('/ ' , OC_Filesystem::getMountPoint ('/some ' ));
60
+ $ this ->assertEqual ('folder ' , OC_Filesystem::getInternalPath ('/some/folder ' ));
61
+ }
62
+
63
+ public function testNormalize () {
64
+ $ this ->assertEqual ('/path ' , OC_Filesystem::normalizePath ('/path/ ' ));
65
+ $ this ->assertEqual ('/path/ ' , OC_Filesystem::normalizePath ('/path/ ' , false ));
66
+ $ this ->assertEqual ('/path ' , OC_Filesystem::normalizePath ('path ' ));
67
+ $ this ->assertEqual ('/path ' , OC_Filesystem::normalizePath ('\path ' ));
68
+ $ this ->assertEqual ('/foo/bar ' , OC_Filesystem::normalizePath ('/foo//bar/ ' ));
69
+ $ this ->assertEqual ('/foo/bar ' , OC_Filesystem::normalizePath ('/foo////bar ' ));
70
+ if (class_exists ('Normalizer ' )) {
71
+ $ this ->assertEqual ("/foo/bar \xC3\xBC" , OC_Filesystem::normalizePath ("/foo/baru \xCC\x88" ));
72
+ }
73
+ }
74
+
75
+ public function testBlacklist () {
76
+ OC_Hook::clear ('OC_Filesystem ' );
77
+ OC_Hook::connect ('OC_Filesystem ' , 'write ' , 'OC_Filesystem ' , 'isBlacklisted ' );
78
+ OC_Hook::connect ('OC_Filesystem ' , 'rename ' , 'OC_Filesystem ' , 'isBlacklisted ' );
79
+
80
+ $ run = true ;
81
+ OC_Hook::emit (
82
+ OC_Filesystem::CLASSNAME ,
83
+ OC_Filesystem::signal_write,
84
+ array (
85
+ OC_Filesystem::signal_param_path => '/test/.htaccess ' ,
86
+ OC_Filesystem::signal_param_run => &$ run
87
+ )
88
+ );
89
+ $ this ->assertFalse ($ run );
90
+
91
+ if (OC_Filesystem::getView ()) {
92
+ $ user = OC_User::getUser ();
93
+ } else {
94
+ $ user = uniqid ();
95
+ OC_Filesystem::init ('/ ' . $ user . '/files ' );
96
+ }
97
+
98
+ OC_Filesystem::mount ('OC_Filestorage_Temporary ' , array (), '/ ' );
99
+
100
+ $ rootView = new OC_FilesystemView ('' );
101
+ $ rootView ->mkdir ('/ ' . $ user );
102
+ $ rootView ->mkdir ('/ ' . $ user . '/files ' );
103
+
104
+ $ this ->assertFalse ($ rootView ->file_put_contents ('/.htaccess ' , 'foo ' ));
105
+ $ this ->assertFalse (OC_Filesystem::file_put_contents ('/.htaccess ' , 'foo ' ));
106
+ $ fh = fopen (__FILE__ , 'r ' );
107
+ $ this ->assertFalse (OC_Filesystem::file_put_contents ('/.htaccess ' , $ fh ));
108
+ }
109
+
110
+ public function testHooks () {
111
+ if (OC_Filesystem::getView ()) {
112
+ $ user = OC_User::getUser ();
113
+ } else {
114
+ $ user = uniqid ();
115
+ OC_Filesystem::init ('/ ' . $ user . '/files ' );
116
+ }
117
+ OC_Hook::clear ('OC_Filesystem ' );
118
+ OC_Hook::connect ('OC_Filesystem ' , 'post_write ' , $ this , 'dummyHook ' );
119
+
120
+ OC_Filesystem::mount ('OC_Filestorage_Temporary ' , array (), '/ ' );
121
+
122
+ $ rootView = new OC_FilesystemView ('' );
123
+ $ rootView ->mkdir ('/ ' . $ user );
124
+ $ rootView ->mkdir ('/ ' . $ user . '/files ' );
125
+
126
+ OC_Filesystem::file_put_contents ('/foo ' , 'foo ' );
127
+ OC_Filesystem::mkdir ('/bar ' );
128
+ OC_Filesystem::file_put_contents ('/bar//foo ' , 'foo ' );
129
+
130
+ $ tmpFile = OC_Helper::tmpFile ();
131
+ file_put_contents ($ tmpFile , 'foo ' );
132
+ $ fh = fopen ($ tmpFile , 'r ' );
133
+ OC_Filesystem::file_put_contents ('/bar//foo ' , $ fh );
134
+ }
135
+
136
+ public function dummyHook ($ arguments ) {
137
+ $ path = $ arguments ['path ' ];
138
+ $ this ->assertEqual ($ path , OC_Filesystem::normalizePath ($ path )); //the path passed to the hook should already be normalized
61
139
}
62
140
}
63
141
64
- ?>
142
+ ?>
0 commit comments