Ejemplo n.º 1
0
 /**
  * Decompression and/or decryption of archive contents should be possible by
  * using an external client to read the current file, or temporary files for
  * data sources. The test should be skipped if no external client is available.
  *
  * @group  external
  */
 public function testExtractsFilesWithExternalClient()
 {
     if (!($unzip = $this->getUnzipPath())) {
         $this->markTestSkipped();
     }
     $szip = new SzipInfo();
     // Compressed files
     $szfile = $this->fixturesDir . '/solid_lzma_multi.7z';
     $szip->open($szfile);
     $this->assertEmpty($szip->error);
     $files = $szip->getFileList();
     $file = $files[0];
     $this->assertSame('7zFormat.txt', $file['name']);
     $this->assertSame(1, $file['compressed']);
     $data = $szip->extractFile($file['name']);
     $this->assertNotEmpty($szip->error);
     $this->assertContains('external client', $szip->error);
     $szip->setExternalClient($unzip);
     $data = $szip->extractFile($file['name']);
     $this->assertEmpty($szip->error);
     $this->assertSame(strlen($data), $file['size']);
     $this->assertSame($file['crc32'], dechex(crc32($data)));
     $this->assertStringStartsWith('7z Format description', $data);
     $this->assertStringEndsWith("End of document\r\n", $data);
     // Encrypted files
     $szfile = $this->fixturesDir . '/multi_substreams_encrypted.7z';
     $szip->open($szfile);
     $this->assertEmpty($szip->error);
     $files = $szip->getFileList();
     $file = $files[2];
     $this->assertSame('7zFormat.txt', $file['name']);
     $this->assertSame(1, $file['pass']);
     $data = $szip->extractFile($file['name']);
     $this->assertNotEmpty($szip->error);
     $this->assertContains('passworded', $szip->error);
     $data = $szip->extractFile($file['name'], null, 'password');
     $this->assertEmpty($szip->error, $szip->error);
     $this->assertSame(strlen($data), $file['size']);
     $this->assertSame($file['crc32'], dechex(crc32($data)));
     $this->assertStringStartsWith('7z Format description', $data);
     $this->assertStringEndsWith("End of document\r\n", $data);
     // From a data source (via temp file)
     $szip->setData(file_get_contents($szfile));
     $this->assertEmpty($szip->error);
     $summary = $szip->getSummary(true);
     $this->assertSame(filesize($szfile), $summary['data_size']);
     $data = $szip->extractFile($file['name'], null, 'password');
     $this->assertEmpty($szip->error);
     $this->assertSame($file['size'], strlen($data));
     $this->assertSame($file['crc32'], dechex(crc32($data)));
 }