oo_addpattern.phpt 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. --TEST--
  2. ZipArchive::addPattern() method
  3. --CREDITS--
  4. Sammy Kaye Powers <sammyk@sammykmedia.com>
  5. w/Kenzo over the shoulder
  6. #phptek Chicago 2014
  7. --EXTENSIONS--
  8. zip
  9. --FILE--
  10. <?php
  11. include __DIR__ . '/utils.inc';
  12. $dirname = __DIR__ . '/oo_addpattern_dir/';
  13. $file = $dirname . 'tmp.zip';
  14. @mkdir($dirname);
  15. copy(__DIR__ . '/test.zip', $file);
  16. touch($dirname . 'foo.txt');
  17. touch($dirname . 'bar.txt');
  18. $zip = new ZipArchive();
  19. if (!$zip->open($file)) {
  20. exit('failed');
  21. }
  22. $dir = realpath($dirname);
  23. $options = array('add_path' => 'baz/', 'remove_path' => $dir);
  24. if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
  25. echo "failed 1\n";
  26. }
  27. $options['flags'] = 0; // clean FL_OVERWRITE
  28. if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
  29. var_dump($zip->getStatusString());
  30. }
  31. $options['flags'] = ZipArchive::FL_OVERWRITE;
  32. if (!$zip->addPattern('/\.txt$/', $dir, $options)) {
  33. echo "failed 2\n";
  34. }
  35. if ($zip->status == ZIPARCHIVE::ER_OK) {
  36. if (!verify_entries($zip, [
  37. "bar",
  38. "foobar/",
  39. "foobar/baz",
  40. "entry1.txt",
  41. "baz/foo.txt",
  42. "baz/bar.txt"
  43. ])) {
  44. echo "failed\n";
  45. } else {
  46. echo "OK";
  47. }
  48. $zip->close();
  49. } else {
  50. echo "failed3\n";
  51. }
  52. ?>
  53. --CLEAN--
  54. <?php
  55. $dirname = __DIR__ . '/oo_addpattern_dir/';
  56. unlink($dirname . 'tmp.zip');
  57. unlink($dirname . 'foo.txt');
  58. unlink($dirname . 'bar.txt');
  59. rmdir($dirname);
  60. ?>
  61. --EXPECT--
  62. string(19) "File already exists"
  63. OK