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 array_walk(glob(self::$destinationFolder .
'/*.zip'),
function($file)
23 public function testCompressTextOnly()
25 $destination = self::$destinationFolder .
'/textOnly.zip';
28 'file1.txt' =>
'content of file1',
29 'file2.txt' =>
'content of file2',
31 $this->assertFileExists($destination);
33 $zip =
new ZipArchive();
34 $zip->open($destination);
35 $this->assertEquals(
'content of file1', $zip->getFromName(
'file1.txt'));
36 $this->assertEquals(
'content of file2', $zip->getFromName(
'file2.txt'));
41 public function testCompressFilesOnly()
43 $destination = self::$destinationFolder .
'/filesOnly.zip';
46 self::$destinationFolder .
'/test_file1.txt',
47 self::$destinationFolder .
'/test_file2.txt'
49 $this->assertFileExists($destination);
51 $zip =
new ZipArchive();
52 $zip->open($destination);
53 $this->assertNotEmpty($zip->getFromName(
'test_file1.txt'));
54 $this->assertNotEmpty($zip->getFromName(
'test_file2.txt'));
57 public function testCompressFilesExclude()
59 $destination = self::$destinationFolder .
'/filesOnlyExclude.zip';
63 'path' => self::$destinationFolder,
64 'exclude' => array(
'test_file1.txt')
67 $this->assertFileExists($destination);
69 $zip =
new ZipArchive();
70 $zip->open($destination);
71 $this->assertEmpty($zip->getFromName(
'test_file1.txt'));
72 $this->assertNotEmpty($zip->getFromName(
'test_file2.txt'));
75 public function testCompressFilesAndText()
77 $destination = self::$destinationFolder .
'/filesAndText.zip';
81 'path' => self::$destinationFolder,
83 'file1.txt' =>
'content of file1',
84 'file2.txt' =>
'content of file2',
86 $this->assertFileExists($destination);
88 $zip =
new ZipArchive();
89 $zip->open($destination);
91 $this->assertNotEmpty($zip->getFromName(
'test_file1.txt'));
92 $this->assertNotEmpty($zip->getFromName(
'test_file2.txt'));
93 $this->assertEquals(
'content of file1', $zip->getFromName(
'file1.txt'));
94 $this->assertEquals(
'content of file2', $zip->getFromName(
'file2.txt'));
97 public function testExtract()
99 $destination = self::$destinationFolder .
'/compressed.zip';
101 'compressed.txt' =>
'content of compressed',
105 $this->assertFileExists(self::$destinationFolder .
'/compressed.txt');
106 unlink(self::$destinationFolder .
'/compressed.txt');