예제 #1
0
/**
 * Generates test fixtures from 7z sample files.
 *
 * @param   boolean  $pretend  debug output only?
 * @param   boolean  $refresh  regenerate existing files?
 * @return  void
 */
function makeSzipFixtures($pretend = false, $refresh = true)
{
    $szip = new SzipInfo();
    foreach (glob(dirname(__FILE__) . '/szip/*.{7z,001,002}', GLOB_BRACE) as $szipfile) {
        $fname = pathinfo($szipfile, PATHINFO_BASENAME) . '.headers';
        $file = dirname(__FILE__) . "/szip/{$fname}";
        if (!$refresh && file_exists($file)) {
            continue;
        }
        echo "Generating for {$szipfile}:\n";
        $szip->open($szipfile, true);
        if ($szip->error) {
            echo "Error: {$szip->error}\n";
            continue;
        }
        $data = $szip->getHeaders();
        if (!$pretend) {
            $data = "<?php\nreturn " . var_export($data, true) . ";\n";
            file_put_contents($file, $data);
        }
        echo "-- {$fname}\n";
    }
}
예제 #2
0
 /**
  * Headers can be compressed or encrypted, and we should be able to use an
  * external client to extract these before further parsing.
  *
  * @depends testExtractsFilesWithExternalClient
  * @group   external
  */
 public function testExtractsEncodedHeadersWithExternalClient()
 {
     if (!($unzip = $this->getUnzipPath())) {
         $this->markTestSkipped();
     }
     $szip = new SzipInfo();
     // Compressed headers
     $file = $this->fixturesDir . '/store_method_enc_headers.7z';
     $szip->open($file);
     $this->assertEmpty($szip->error);
     $this->assertSame(1, $szip->blockCount);
     $this->assertEmpty($szip->getFileList());
     $szip->setExternalClient($unzip);
     $szip->open($file);
     $this->assertEmpty($szip->error);
     $this->assertSame(2, $szip->blockCount);
     $files = $szip->getFileList();
     $this->assertCount(2, $files);
     $file = $files[0];
     $this->assertSame('7zFormat.txt', $file['name']);
     $this->assertSame('32-7604', $file['range']);
     $file = $files[1];
     $this->assertSame('foo.txt', $file['name']);
     $this->assertSame('7605-7619', $file['range']);
     // Encrypted headers
     $file = $this->fixturesDir . '/encrypted_headers.7z';
     $szip->open($file);
     $this->assertNotEmpty($szip->error);
     $this->assertContains('password needed', $szip->error);
     $this->assertTrue($szip->isEncrypted);
     $this->assertSame(1, $szip->blockCount);
     $this->assertEmpty($szip->getFileList());
     $szip->setPassword('password');
     $szip->open($file);
     $this->assertEmpty($szip->error);
     $this->assertSame(1, $szip->blockCount);
     $files = $szip->getFilelist();
     $this->assertCount(1, $files);
     $file = $files[0];
     $this->assertSame('7zFormat.txt', $file['name']);
     $this->assertSame(7573, $file['size']);
     $this->assertSame('32-7615', $file['range']);
     $this->assertSame(1, $file['pass']);
     $this->assertSame(0, $file['compressed']);
 }