oo_extract.phpt 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. --TEST--
  2. extractTo
  3. --SKIPIF--
  4. <?php
  5. /* $Id$ */
  6. if(!extension_loaded('zip')) die('skip');
  7. ?>
  8. --FILE--
  9. <?php
  10. $dirname = dirname(__FILE__) . '/';
  11. $file = $dirname . 'test_with_comment.zip';
  12. include $dirname . 'utils.inc';
  13. $zip = new ZipArchive;
  14. if ($zip->open($file) !== TRUE) {
  15. echo "open failed.\n";
  16. exit('failed');
  17. }
  18. $zip->extractTo($dirname . '__oo_extract_tmp');
  19. if (!is_dir($dirname . '__oo_extract_tmp')) {
  20. echo "failed. mkdir\n";
  21. }
  22. if (!is_dir($dirname .'__oo_extract_tmp/foobar')) {
  23. echo "failed. mkdir foobar\n";
  24. }
  25. if (!file_exists($dirname . '__oo_extract_tmp/foobar/baz')) {
  26. echo "failed. extract foobar/baz\n";
  27. } else {
  28. echo file_get_contents($dirname . '__oo_extract_tmp/foobar/baz') . "\n";
  29. }
  30. if (!file_exists($dirname . '__oo_extract_tmp/bar')) {
  31. echo "failed. bar file\n";
  32. } else {
  33. echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n";
  34. }
  35. if (!file_exists($dirname . '__oo_extract_tmp/foo')) {
  36. echo "failed. foo file\n";
  37. } else {
  38. echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n";
  39. }
  40. /* extract one file */
  41. $zip->extractTo($dirname . '__oo_extract_tmp', 'bar');
  42. if (!file_exists($dirname . '__oo_extract_tmp/bar')) {
  43. echo "failed. extract bar file\n";
  44. } else {
  45. echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n";
  46. }
  47. /* extract two files */
  48. $zip->extractTo($dirname . '__oo_extract_tmp', array('bar','foo'));
  49. if (!file_exists($dirname . '__oo_extract_tmp/bar')) {
  50. echo "failed. extract bar file\n";
  51. } else {
  52. echo file_get_contents($dirname . '__oo_extract_tmp/bar') . "\n";
  53. }
  54. if (!file_exists($dirname . '__oo_extract_tmp/foo')) {
  55. echo "failed. extract foo file\n";
  56. } else {
  57. echo file_get_contents($dirname . '__oo_extract_tmp/foo') . "\n";
  58. }
  59. rmdir_rf($dirname . '__oo_extract_tmp');
  60. ?>
  61. --EXPECTF--
  62. blabla laber rababer sülz
  63. bar
  64. foo
  65. bar
  66. bar
  67. foo
  68. --UEXPECTF--
  69. blabla laber rababer sülz
  70. bar
  71. foo
  72. bar
  73. bar
  74. foo