ZipOutputParserTest.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. namespace Alchemy\Zippy\Tests\Parser;
  3. use Alchemy\Zippy\Parser\ZipOutputParser;
  4. use Alchemy\Zippy\Tests\TestCase;
  5. class ZipOutputParserTest extends TestCase
  6. {
  7. public function testNewParser()
  8. {
  9. return new ZipOutputParser();
  10. }
  11. /**
  12. * @depends testNewParser
  13. */
  14. public function testParseFileListing($parser)
  15. {
  16. $current_timezone = ini_get('date.timezone');
  17. ini_set('date.timezone', 'UTC');
  18. $output =
  19. "Length Date Time Name
  20. -------- ---- ---- ----
  21. 0 2006-06-09 12:06 practice/
  22. 10240 2006-06-09 12:06 practice/records
  23. -------- -------
  24. 785 2 files";
  25. $members = $parser->parseFileListing($output);
  26. $this->assertEquals(2, count($members));
  27. foreach ($members as $member) {
  28. $this->assertTrue(is_array($member));
  29. }
  30. $memberDirectory = array_shift($members);
  31. $this->assertTrue($memberDirectory['is_dir']);
  32. $this->assertEquals('practice/', $memberDirectory['location']);
  33. $this->assertEquals(0, $memberDirectory['size']);
  34. $date = $memberDirectory['mtime'];
  35. $this->assertTrue($date instanceof \DateTime);
  36. $this->assertEquals('1149854760', $date->format("U"));
  37. $memberFile = array_pop($members);
  38. $this->assertFalse($memberFile['is_dir']);
  39. $this->assertEquals('practice/records', $memberFile['location']);
  40. $this->assertEquals(10240, $memberFile['size']);
  41. $date = $memberFile['mtime'];
  42. $this->assertTrue($date instanceof \DateTime);
  43. $this->assertEquals('1149854760', $date->format("U"));
  44. ini_set('date.timezone', $current_timezone);
  45. }
  46. /**
  47. * @depends testNewParser
  48. */
  49. public function testParseDeflatorVersion($parser)
  50. {
  51. $output = "UnZip 5.52 of 28 February 2005, by Info-ZIP. Maintained by C. Spieler. Send
  52. bug reports using http://www.info-zip.org/zip-bug.html; see README for details.
  53. Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  54. Default action is to extract files in list, except those in xlist, to exdir;
  55. file[.zip] may be a wildcard. -Z => ZipInfo mode ('unzip -Z' for usage).
  56. -p extract files to pipe, no messages -l list files (short format)
  57. -f freshen existing files, create none -t test compressed archive data
  58. -u update files, create if necessary -z display archive comment
  59. -x exclude files that follow (in xlist) -d extract files into exdir
  60. modifiers: -q quiet mode (-qq => quieter)
  61. -n never overwrite existing files -a auto-convert any text files
  62. -o overwrite files WITHOUT prompting -aa treat ALL files as text
  63. -j junk paths (do not make directories) -v be verbose/print version info
  64. -C match filenames case-insensitively -L make (some) names lowercase
  65. -X restore UID/GID info -V retain VMS version numbers
  66. -K keep setuid/setgid/tacky permissions -M pipe through 'more' pager
  67. Examples (see unzip.txt for more info):
  68. unzip data1 -x joe => extract all files except joe from zipfile data1.zip
  69. unzip -p foo | more => send contents of foo.zip via pipe into program more
  70. unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer";
  71. $this->assertEquals('5.52', $parser->parseDeflatorVersion($output));
  72. }
  73. /**
  74. * @depends testNewParser
  75. */
  76. public function testParseInflatorVersion($parser)
  77. {
  78. $output = "Copyright (c) 1990-2008 Info-ZIP - Type 'zip '-L'' for software license.
  79. Zip 3.0 (July 5th 2008). Usage:
  80. zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
  81. The default action is to add or replace zipfile entries from list, which
  82. can include the special name - to compress standard input.
  83. If zipfile and list are omitted, zip compresses stdin to stdout.
  84. -f freshen: only changed files -u update: only changed or new files
  85. -d delete entries in zipfile -m move into zipfile (delete OS files)
  86. -r recurse into directories -j junk (don't record) directory names
  87. -0 store only -l convert LF to CR LF (-ll CR LF to LF)
  88. -1 compress faster -9 compress better
  89. -q quiet operation -v verbose operation/print version info
  90. -c add one-line comments -z add zipfile comment
  91. -@ read names from stdin -o make zipfile as old as latest entry
  92. -x exclude the following names -i include only the following names
  93. -F fix zipfile (-FF try harder) -D do not add directory entries
  94. -A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)
  95. -T test zipfile integrity -X eXclude eXtra file attributes
  96. -y store symbolic links as the link instead of the referenced file
  97. -e encrypt -n don't compress these suffixes
  98. -h2 show more help";
  99. $this->assertEquals('3.0', $parser->parseInflatorVersion($output));
  100. }
  101. }