oo_setcomment.phpt 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. setComment
  3. --EXTENSIONS--
  4. zip
  5. --FILE--
  6. <?php
  7. $dirname = __DIR__ . '/';
  8. include $dirname . 'utils.inc';
  9. $file = $dirname . 'oo_setcomment.zip';
  10. @unlink($file);
  11. $zip = new ZipArchive;
  12. if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
  13. exit('failed');
  14. }
  15. $zip->addFromString('entry1.txt', 'entry #1');
  16. $zip->addFromString('entry2.txt', 'entry #2');
  17. $zip->addFromString('dir/entry2d.txt', 'entry #2');
  18. $zip->addFromString('entry4.txt', 'entry #1');
  19. var_dump($zip->setCommentIndex($zip->lastId, 'entry4.txt'));
  20. $zip->addFromString('entry5.txt', 'entry #2');
  21. var_dump($zip->setCommentIndex($zip->lastId, 'entry5.txt'));
  22. var_dump($zip->setCommentName('entry1.txt', 'entry1.txt'));
  23. var_dump($zip->setCommentName('entry2.txt', 'entry2.txt'));
  24. var_dump($zip->setCommentName('dir/entry2d.txt', 'dir/entry2d.txt'));
  25. var_dump($zip->setArchiveComment('archive'));
  26. var_dump($zip->setArchiveComment('archive'));
  27. if (!$zip->status == ZIPARCHIVE::ER_OK) {
  28. echo "failed to write zip\n";
  29. }
  30. $zip->close();
  31. if (!$zip->open($file)) {
  32. @unlink($file);
  33. exit('failed');
  34. }
  35. var_dump($zip->getCommentIndex(0));
  36. var_dump($zip->getCommentIndex(1));
  37. var_dump($zip->getCommentIndex(2));
  38. var_dump($zip->getCommentIndex(3));
  39. var_dump($zip->getCommentIndex(4));
  40. var_dump($zip->getArchiveComment());
  41. $zip->close();
  42. @unlink($file);
  43. ?>
  44. --EXPECT--
  45. bool(true)
  46. bool(true)
  47. bool(true)
  48. bool(true)
  49. bool(true)
  50. bool(true)
  51. bool(true)
  52. string(10) "entry1.txt"
  53. string(10) "entry2.txt"
  54. string(15) "dir/entry2d.txt"
  55. string(10) "entry4.txt"
  56. string(10) "entry5.txt"
  57. string(7) "archive"