[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 function ok($string){ 3 /* html_table_row_begin(); 4 html_table_col_begin();*/ 5 echo "<h3>$string "; 6 /* html_table_col_end(); 7 html_table_col_begin();*/ 8 echo " OK</h3>"; 9 /* html_table_col_end(); 10 html_table_row_end();*/ 11 } 12 function fail($string){ 13 /* html_table_row_begin(); 14 html_table_col_begin();*/ 15 echo "<h3>$string "; 16 /* html_table_col_end(); 17 html_table_col_begin();*/ 18 echo " <b>FAILED!</b></h3>"; 19 /* html_table_col_end(); 20 html_table_row_end(); */ 21 } 22 23 $phpgw_info["flags"] = array("currentapp" => "filemanager", 24 "noheader" => False, 25 "noappheader" => False, 26 "enable_vfs_class" => True); 27 28 include("../../header.inc.php"); 29 30 html_text('VFS_DAV tests:'); 31 html_break (1); 32 html_text_italic (PHP_OS . " - " . $phpgw_info["server"]["db_type"] . " - " . PHP_VERSION . " - " . $phpgw->vfs->basedir); 33 html_break (1); 34 //html_table_begin(); 35 36 37 $sep = SEP; 38 $user = $phpgw->vfs->working_lid; 39 $homedir = $phpgw->vfs->fakebase . "/" . $user; 40 $realhomedir = preg_replace ("|/|", $sep, $homedir); 41 $filesdir = $phpgw->vfs->basedir; 42 $currentapp = $phpgw_info["flags"]["currentapp"]; 43 $time1 = time(); 44 45 echo ' override locks : ';print_r($phpgw->vfs->override_locks); 46 ### 47 # write test 48 49 $phpgw->vfs->cd (); 50 $testfile = 'sdhdsjjkldggfsbhgbnirooaqojsdkljajklvagbytoi-test'; 51 $teststring = 'delete me' ; 52 if (!$result = $phpgw->vfs->write (array ('string' => $testfile, 53 'content' => $teststring 54 ))) 55 { 56 fail( __LINE__." failed writing file!"); 57 } 58 else 59 { 60 ok("write"); 61 } 62 63 #read 64 $phpgw->vfs->cd (); 65 $result = $phpgw->vfs->read (array ('string' => $testfile, 'noview' => true )); 66 if (!$result==$teststring) 67 { 68 fail( __LINE__." failed reading file!"); 69 } 70 else 71 { 72 ok(" read"); 73 } 74 75 ### 76 # ls test 77 78 $result1 = $phpgw->vfs->ls (array ('string' => $testfile )); 79 80 if (!count($result1)) 81 { 82 fail(__LINE__." failed listing file!"); 83 } 84 else 85 { 86 ok(" ls : known file"); 87 } 88 //list the parent dir 89 90 $result = $phpgw->vfs->ls (array ('string' => '')); 91 foreach ($result as $file) 92 { 93 if ($testfile == $file['name']) 94 { 95 $found = true; 96 break; 97 } 98 } 99 if (!$found) 100 { 101 fail(__LINE__." failed listing file!"); 102 } 103 else 104 { 105 ok(" ls : parent"); 106 } 107 $found = false; 108 foreach ($result as $file) 109 { 110 if ($result1[0]['directory'] == $file['full_name']) 111 { 112 $found = true; 113 break; 114 } 115 } 116 if ($found) 117 { 118 fail(__LINE__." parent is present in its own listing!"); 119 } 120 else 121 { 122 ok(" ls : parent self reference"); 123 } 124 # getsize 125 $phpgw->vfs->cd (); 126 $result = $phpgw->vfs->get_size (array ('string' => $testfile )); 127 $len = strlen($teststring); 128 if (!($result== $len)) 129 { 130 fail(__LINE__." failed getting size of file result $result strlen $len"); 131 } 132 else 133 { 134 ok("get_size"); 135 } 136 137 #filetype 138 $phpgw->vfs->cd (); 139 $result = $phpgw->vfs->file_type(array ('string' => $testfile )); 140 $len = strlen($teststring); 141 if (!($result== 'application/octet-stream')) 142 { 143 fail(__LINE__." failed getting file type $result"); 144 } 145 else 146 { 147 ok("file_type"); 148 } 149 150 151 #file_exists 152 $phpgw->vfs->cd (); 153 $result = $phpgw->vfs->file_exists(array ('string' => $testfile )); 154 if (!$result) 155 { 156 fail(__LINE__." file_exist failed: $result"); 157 } 158 else 159 { 160 ok("file_exists"); 161 } 162 163 #lock 164 $phpgw->vfs->cd (); 165 $result = $phpgw->vfs->lock (array ('string' => $testfile )); 166 if (!$result) 167 { 168 fail(__LINE__."failed locking file!"); 169 } 170 else 171 { 172 ok(" lock"); 173 } 174 175 176 $ls_array = $GLOBALS['phpgw']->vfs->ls (array ( 177 'string' => $testfile, 178 'relatives' => array (RELATIVE_ALL), 179 'checksubdirs' => False 180 ) 181 ); 182 if (!count($ls_array[0]['locks'])) 183 { 184 fail(__LINE__."after locking file no locks exist!"); 185 } 186 else 187 { 188 ok(" lock: after locking lock exists."); 189 } 190 $lock = end($ls_array[0]['locks']); 191 $tokens = end($lock['lock_tokens']); 192 $token = $tokens['name']; 193 //write should now fail 194 $result = $phpgw->vfs->write (array ('string' => $testfile, 195 'content' => 'delete me' 196 )); 197 if ($result) 198 { 199 fail(__LINE__."I can write a supposidly locked file!"); 200 } 201 else 202 { 203 ok("lock: after locking write fails"); 204 } 205 206 $phpgw->vfs->add_lock_override(array ('string' => $testfile)); 207 $result = $phpgw->vfs->write (array ('string' => $testfile, 208 'content' => 'delete me' 209 )); 210 if (!$result) 211 { 212 fail(__LINE__."I cant write a locked file after overriding the lock!"); 213 } 214 else 215 { 216 ok("lock: after lock override write succeeds"); 217 } 218 ### 219 # unlock test 220 221 $phpgw->vfs->cd (); 222 $result = $phpgw->vfs->unlock (array ('string' => $testfile ), $token); 223 if (!$result) 224 { 225 fail( __LINE__."failed unlocking file!"); 226 } 227 else 228 { 229 OK("unlock"); 230 } 231 232 #server side copy 233 234 $phpgw->vfs->cd (); 235 $result = $phpgw->vfs->cp(array ('from' => $testfile, 236 'to' => $testfile.'2', 237 'relatives' => array (RELATIVE_ALL, RELATIVE_ALL) 238 )); 239 if (!$result) 240 { 241 fail(__LINE__." failed copying! returned: $result"); 242 } 243 else 244 { 245 ok("server-side copy"); 246 } 247 $result = $phpgw->vfs->file_exists(array ('string' => $testfile.'2' 248 )); 249 if (!$result) 250 { 251 fail(__LINE__." after copy, target doesnt exist!"); 252 } 253 else 254 { 255 ok("server-side copy : test for target"); 256 } 257 $result = $phpgw->vfs->read (array ('string' => "$testfile".'2', 258 'noview' => true, 259 'relatives' => array (RELATIVE_ALL) 260 )); 261 if (!$result==$teststring) 262 { 263 fail( __LINE__."after copy, read returned '$result' not '$teststring' "); 264 } 265 else 266 { 267 ok(" server-side copy: read target"); 268 } 269 $result = $phpgw->vfs->delete(array ('string' => $testfile.'2' 270 )); 271 272 if (!$result) 273 { 274 fail(__LINE__." failed copying! delete copied file returned: $result"); 275 } 276 else 277 { 278 ok("server-side copy : delete target"); 279 } 280 281 #remote -> local copy 282 $phpgw->vfs->cd (); 283 echo "<pre>"; 284 $result = $phpgw->vfs->cp(array ('from' => $testfile, 285 'to' => "/tmp/$testfile".'2', 286 'relatives' => array (RELATIVE_ALL, RELATIVE_NONE | VFS_REAL) 287 )); 288 echo "</pre>"; 289 if (!$result) 290 { 291 fail(__LINE__." failed remote->local copying! returned: $result"); 292 } 293 else 294 { 295 ok("remote->local copy"); 296 } 297 echo "<pre>"; 298 $result = $phpgw->vfs->file_exists(array ('string' => "/tmp/$testfile".'2', 299 'relatives' => array (RELATIVE_NONE | VFS_REAL) 300 )); 301 echo "</pre>"; 302 if (!$result) 303 { 304 fail(__LINE__." after remote->local copy, target doesnt exist!"); 305 } 306 else 307 { 308 ok("remote->local copy : test for target"); 309 } 310 $phpgw->vfs->cd (); 311 echo "<pre>"; 312 $result = $phpgw->vfs->read (array ('string' => "/tmp/$testfile".'2', 313 'noview' => true, 314 'relatives' => array (RELATIVE_NONE | VFS_REAL) 315 )); 316 echo "</pre>"; 317 if (!$result==$teststring) 318 { 319 fail( __LINE__."after remote->local copy, returned $result"); 320 } 321 else 322 { 323 ok(" remote->local copy: read target"); 324 } 325 echo "<pre>"; 326 $result = $phpgw->vfs->delete(array ('string' => "/tmp/$testfile".'2', 327 'relatives' => array (RELATIVE_NONE | VFS_REAL) 328 )); 329 echo "</pre>"; 330 if (!$result) 331 { 332 fail(__LINE__." failed copying! delete copied file returned: $result"); 333 } 334 else 335 { 336 ok("remote->local copy : delete target"); 337 } 338 339 #move 340 $phpgw->vfs->cd (); 341 echo "<pre>"; 342 $result = $phpgw->vfs->mv(array ('from' => $testfile, 343 'to' => $testfile.'2', 344 'relatives' => array (RELATIVE_ALL, RELATIVE_ALL) 345 )); 346 echo "</pre>"; 347 if (!$result) 348 { 349 fail(__LINE__." failed moving! returned: $result"); 350 } 351 else 352 { 353 ok("server-side move"); 354 } 355 $result = $phpgw->vfs->file_exists(array ('string' => $testfile, 356 )); 357 if ($result) 358 { 359 fail(__LINE__." failed moving! returned: $result"); 360 } 361 else 362 { 363 ok("server-side move : test for source"); 364 } 365 $result = $phpgw->vfs->file_exists(array ('string' => $testfile.'2', 366 )); 367 if (!$result) 368 { 369 fail(__LINE__." failed moving! returned: $result"); 370 } 371 else 372 { 373 ok("server-side move : test for target"); 374 } 375 echo "<pre>"; 376 $result = $phpgw->vfs->read (array ('string' => $testfile.'2', 377 'noview' => true, 378 'relatives' => array (RELATIVE_ALL) 379 )); 380 echo "</pre>"; 381 if (!$result==$teststring) 382 { 383 fail( __LINE__."after move, read returned '$result' not '$teststring' "); 384 } 385 else 386 { 387 ok(" server-side move: read target"); 388 } 389 390 echo "<pre>"; 391 $result = $phpgw->vfs->mv(array ('from' => $testfile.'2', 392 'to' => $testfile, 393 'relatives' => array (RELATIVE_ALL, RELATIVE_ALL) 394 )); 395 echo "</pre>"; 396 if (!$result) 397 { 398 fail(__LINE__." failed moving! returned: $result"); 399 } 400 else 401 { 402 ok("server-side move : move back"); 403 } 404 405 #remote->local move 406 echo "<pre>"; 407 $phpgw->vfs->cd (); 408 $result = $phpgw->vfs->mv(array ('from' => $testfile, 409 'to' => '/tmp/'.$testfile.'2', 410 'relatives' => array (RELATIVE_ALL, RELATIVE_NONE | VFS_REAL) 411 )); 412 echo "</pre>"; 413 if (!$result) 414 { 415 fail(__LINE__." failed moving! returned: $result"); 416 } 417 else 418 { 419 ok("remote->local move"); 420 } 421 $result = $phpgw->vfs->file_exists(array ('string' => $testfile, 422 )); 423 if ($result) 424 { 425 fail(__LINE__." failed moving! returned: $result"); 426 } 427 else 428 { 429 ok("remote->local move : test for source"); 430 } 431 $result = $phpgw->vfs->file_exists(array ('string' => '/tmp/'.$testfile.'2', 432 'relatives' => array(RELATIVE_NONE | VFS_REAL) 433 )); 434 if (!$result) 435 { 436 fail(__LINE__." failed moving! returned: $result"); 437 } 438 else 439 { 440 ok("remote->local move : test for target"); 441 } 442 443 $result = $phpgw->vfs->read (array ('string' => '/tmp/'.$testfile.'2', 444 'noview' => true, 445 'relatives' => array(RELATIVE_NONE | VFS_REAL) 446 )); 447 if (!$result==$teststring) 448 { 449 fail( __LINE__."after move, read returned '$result' not '$teststring' "); 450 } 451 else 452 { 453 ok("remote->local move: read target"); 454 } 455 456 echo "<pre>"; 457 $result = $phpgw->vfs->mv(array ('from' => '/tmp/'.$testfile.'2', 458 'to' => $testfile, 459 'relatives' => array (RELATIVE_NONE | VFS_REAL, RELATIVE_ALL) 460 )); 461 echo "</pre>"; 462 if (!$result) 463 { 464 fail(__LINE__." failed moving! returned: $result"); 465 } 466 else 467 { 468 ok("server-side move : move back"); 469 } 470 471 472 ### 473 # delete test 474 475 $phpgw->vfs->cd (); 476 $result = $phpgw->vfs->delete(array ('string' => $testfile )); 477 if (!$result) 478 { 479 fail(__LINE__."failed deleting file! returned: $result"); 480 } 481 else 482 { 483 ok("delete"); 484 } 485 486 ### 487 # mkdir test 488 489 $phpgw->vfs->cd (); 490 $result = $phpgw->vfs->mkdir(array ('string' => $testfile )); 491 if (!$result) 492 { 493 fail(__LINE__."failed creating collection! returned: $result"); 494 } 495 else 496 { 497 ok("mkdir"); 498 } 499 500 $result = $phpgw->vfs->write (array ('string' => $testfile.'/'.$testfile.'2', 501 'content' => $teststring 502 )); 503 504 if (!$result) 505 { 506 fail( __LINE__." failed writing file into new dir!"); 507 } 508 else 509 { 510 ok("mkdir : write into dir"); 511 } 512 ### 513 # rm dir test 514 515 $phpgw->vfs->cd (); 516 $result = $phpgw->vfs->rm(array ('string' => $testfile )); 517 if (!$result) 518 { 519 fail(__LINE__." failed deleting collection! returned: $result"); 520 } 521 else 522 { 523 ok("delete dir"); 524 } 525 526 //html_table_end(); 527 $time = time() - $time1; 528 html_text("Done in $time s"); 529 html_page_close (); 530 531 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |