7 protected static $destinationFolder;
9 public static function setUpBeforeClass()
11 Yii::app()->getModule(
'updates');
12 self::$destinationFolder = Yii::getPathOfAlias(
'site.tests.runtime.updates.ZipHelper');
15 public function setUp()
17 $matches = glob(self::$destinationFolder .
'/*.zip');
18 array_walk($matches,
function($file)
24 public function testCompressTextOnly()
26 $destination = self::$destinationFolder .
'/textOnly.zip';
29 'file1.txt' =>
'content of file1',
30 'file2.txt' =>
'content of file2',
32 $this->assertFileExists($destination);
34 $zip =
new ZipArchive();
35 $zip->open($destination);
36 $this->assertEquals(
'content of file1', $zip->getFromName(
'file1.txt'));
37 $this->assertEquals(
'content of file2', $zip->getFromName(
'file2.txt'));
42 public function testCompressFilesOnly()
44 $destination = self::$destinationFolder .
'/filesOnly.zip';
47 self::$destinationFolder .
'/test_file1.txt',
48 self::$destinationFolder .
'/test_file2.txt'
50 $this->assertFileExists($destination);
52 $zip =
new ZipArchive();
53 $zip->open($destination);
54 $this->assertNotEmpty($zip->getFromName(
'test_file1.txt'));
55 $this->assertNotEmpty($zip->getFromName(
'test_file2.txt'));
58 public function testCompressFilesExclude()
60 $destination = self::$destinationFolder .
'/filesOnlyExclude.zip';
64 'path' => self::$destinationFolder,
65 'exclude' => array(
'test_file1.txt')
68 $this->assertFileExists($destination);
70 $zip =
new ZipArchive();
71 $zip->open($destination);
72 $this->assertEmpty($zip->getFromName(
'test_file1.txt'));
73 $this->assertNotEmpty($zip->getFromName(
'test_file2.txt'));
76 public function testCompressFilesAndText()
78 $destination = self::$destinationFolder .
'/filesAndText.zip';
82 'path' => self::$destinationFolder,
84 'file1.txt' =>
'content of file1',
85 'file2.txt' =>
'content of file2',
87 $this->assertFileExists($destination);
89 $zip =
new ZipArchive();
90 $zip->open($destination);
92 $this->assertNotEmpty($zip->getFromName(
'test_file1.txt'));
93 $this->assertNotEmpty($zip->getFromName(
'test_file2.txt'));
94 $this->assertEquals(
'content of file1', $zip->getFromName(
'file1.txt'));
95 $this->assertEquals(
'content of file2', $zip->getFromName(
'file2.txt'));
98 public function testExtract()
100 $destination = self::$destinationFolder .
'/compressed.zip';
102 'compressed.txt' =>
'content of compressed',
106 $this->assertFileExists(self::$destinationFolder .
'/compressed.txt');
107 unlink(self::$destinationFolder .
'/compressed.txt');