eZ components PHP Cross Reference Developer Tools

Source: /Archive/tests/tar/pax_tar_test.php - 150 lines - 5029 bytes - Summary - Text - Print

   1  <?php
   2  /**
   3   * @copyright Copyright (C) 2005-2010 eZ Systems AS. All rights reserved.
   4   * @license http://ez.no/licenses/new_bsd New BSD License
   5   * @filesource
   6   * @package Archive
   7   * @version 1.4.1
   8   * @subpackage Tests
   9   */
  10  
  11  require_once ( "ustar_tar_test.php" );
  12  
  13  /**
  14   * @package Archive
  15   * @version 1.4.1
  16   * @subpackage Tests
  17   */
  18  class ezcArchivePaxTarTest extends ezcArchiveUstarTarTest // Extend the Ustar tests
  19  {
  20      protected function setUp()
  21      {
  22          date_default_timezone_set( "UTC" );
  23          $this->tarFormat = "posix";
  24          $this->tarMimeFormat = ezcArchive::TAR_PAX;
  25          $this->canWrite = false;
  26  
  27          $this->createTempDir( "ezcArchive_" );
  28  
  29          $this->file = $this->createTempFile( "tar_pax_2_textfiles.tar" );
  30          $blockFile = new ezcArchiveBlockFile( $this->file );
  31          $this->archive = new ezcArchivePaxTar( $blockFile );
  32  
  33          $this->complexFile = $this->createTempFile( "tar_pax_file_dir_symlink_link.tar" );
  34          $blockFile = new ezcArchiveBlockFile( $this->complexFile );
  35          $this->complexArchive = new ezcArchivePaxTar( $blockFile );
  36  
  37          $this->setUsersGid();
  38      }
  39  
  40      protected function tearDown()
  41      {
  42          unset( $this->archive );
  43          unset( $this->file );
  44          unset( $this->complexArchive ) ;
  45          unset( $this->complexFile );
  46          $this->removeTempDir();
  47      }
  48  
  49      // Skip character device. It is most probably the same as in Ustar.
  50      public function testExtractCharacterDevice() { }
  51  
  52      // Skip fifo. It is most probably the same as in Ustar.
  53      public function testExtractFifo() { }
  54  
  55      public function testReallyLongFileName ()
  56      {
  57          $dir = $this->getTempDir();
  58  
  59          if ( $this->isWindows() )
  60          {
  61              $dirname = "aaaaabbbbbaaaaabbbbbaaaaabbbbb"; // 30 char. max paths shorter in Windows
  62              $filename = "cccccdddddcccccdddddcccccddddd"; // 30 char. max paths shorter in Windows
  63              mkdir( "$dir\\$dirname\\$dirname\\$dirname", 0777, true );
  64              touch( "$dir\\$dirname\\$dirname\\$dirname\\$filename" );
  65          }
  66          else
  67          {
  68              $dirname = "aaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb"; // 60 char.
  69              $filename = "ccccccccccddddddddddccccccccccddddddddddccccccccccdddddddddd"; // 60 char.
  70              mkdir( "$dir/$dirname/$dirname/$dirname", 0777, true );
  71              touch( "$dir/$dirname/$dirname/$dirname/$filename" );
  72          }
  73  
  74          exec( "tar -cf $dir/gnutar.tar --format=" . $this->tarFormat . " -C $dir $dirname" );
  75  
  76          unlink("$dir/$dirname/$dirname/$dirname/$filename" );
  77          rmdir( "$dir/$dirname/$dirname/$dirname" );
  78          rmdir( "$dir/$dirname/$dirname" );
  79          rmdir( "$dir/$dirname" );
  80  
  81          // Extract it:
  82          $bf = new ezcArchiveBlockFile( "$dir/gnutar.tar" );
  83          $archive = ezcArchive::getTarInstance( $bf, $this->tarMimeFormat ); 
  84  
  85          foreach ( $archive as $entry )
  86          {
  87              $archive->extractCurrent( $dir );
  88          }
  89  
  90          $this->assertTrue( file_exists( "$dir/$dirname/$dirname/$dirname/$filename" ) );
  91  
  92          unset( $bf );
  93      }
  94  
  95      public function testExtractLongLinkName()
  96      {
  97          $dir = $this->getTempDir();
  98  
  99          if ( $this->isWindows() )
 100          {
 101              $dirname = "aaaaabbbbbaaaaabbbbbaaaaabbbbb"; // 30 char. max paths shorter in Windows
 102              $filename = "cccccdddddcccccdddddcccccddddd"; // 30 char. max paths shorter in Windows
 103              mkdir( "$dir\\$dirname\\$dirname\\$dirname", 0777, true );
 104              touch( "$dir\\$dirname\\$dirname\\$dirname\\$filename" );
 105  
 106              copy( "$dir\\$dirname\\$dirname\\$dirname\\$filename", "$dir/mylink" );
 107          }
 108          else
 109          {
 110              $dirname = "aaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbbaaaaaaaaaabbbbbbbbbb"; // 60 char.
 111              mkdir( "$dir/$dirname/$dirname/$dirname", 0777, true );
 112  
 113              $filename = "ccccccccccddddddddddccccccccccddddddddddccccccccccdddddddddd"; // 60 char.
 114              touch( "$dir/$dirname/$dirname/$dirname/$filename" );
 115  
 116              symlink( "$dirname/$dirname/$dirname/$filename", "$dir/mylink" );
 117          }
 118  
 119          exec( "tar -cf $dir/gnutar.tar --format=" . $this->tarFormat . " -C $dir mylink" );
 120  
 121          unlink( "$dir/$dirname/$dirname/$dirname/$filename" );
 122          rmdir( "$dir/$dirname/$dirname/$dirname" );
 123          rmdir( "$dir/$dirname/$dirname" );
 124          rmdir( "$dir/$dirname" );
 125  
 126          // Extract it:
 127          $bf = new ezcArchiveBlockFile( "$dir/gnutar.tar" );
 128          $archive = ezcArchive::getTarInstance( $bf, $this->tarMimeFormat ); 
 129  
 130          foreach ( $archive as $entry )
 131          {
 132              $archive->extractCurrent( $dir );
 133          }
 134  
 135          $this->assertTrue( is_link( "$dir/mylink" ) );
 136          $this->assertEquals( "$dirname/$dirname/$dirname/$filename", readlink( "$dir/mylink" ) );
 137          unset( $bf );
 138      }
 139  
 140      public function testExtractHugeFile()
 141      {
 142          // TODO.
 143      }
 144  
 145      public static function suite()
 146      {
 147          return new PHPUnit_Framework_TestSuite( __CLASS__ );
 148      }
 149  }
 150  ?>

title

Description

title

Description

title

Description

title

title

Body