|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
5
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
6
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
7
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
8
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
9
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
10
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
11
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
12
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
13
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
14
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
15
|
|
|
* |
|
16
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
17
|
|
|
* and is licensed under the LGPL. For more information please see |
|
18
|
|
|
* <http://phing.info>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace Phing\Test\Task\Ext\Archive; |
|
22
|
|
|
|
|
23
|
|
|
use Phing\Test\Support\BuildFileTest; |
|
24
|
|
|
use ZipArchive; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Tests the Zip and Unzip tasks. |
|
28
|
|
|
* |
|
29
|
|
|
* @author Michiel Rook <[email protected]> |
|
30
|
|
|
* |
|
31
|
|
|
* @requires extension zip |
|
32
|
|
|
* @internal |
|
33
|
|
|
*/ |
|
34
|
|
|
class ZipUnzipTaskTest extends BuildFileTest |
|
35
|
|
|
{ |
|
36
|
|
|
public function setUp(): void |
|
37
|
|
|
{ |
|
38
|
|
|
$this->configureProject( |
|
39
|
|
|
PHING_TEST_BASE |
|
40
|
|
|
. '/etc/tasks/ext/ZipUnzipTaskTest.xml' |
|
41
|
|
|
); |
|
42
|
|
|
$this->executeTarget('setup'); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function tearDown(): void |
|
46
|
|
|
{ |
|
47
|
|
|
$this->executeTarget('clean'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function testSimpleZipContainsOneFile(): void |
|
51
|
|
|
{ |
|
52
|
|
|
$filename = PHING_TEST_BASE . |
|
53
|
|
|
'/etc/tasks/ext/tmp/simple-test.zip'; |
|
54
|
|
|
|
|
55
|
|
|
$this->executeTarget(__FUNCTION__); |
|
56
|
|
|
$this->assertFileExists($filename); |
|
57
|
|
|
|
|
58
|
|
|
$archive = new ZipArchive(); |
|
59
|
|
|
$archive->open($filename); |
|
60
|
|
|
|
|
61
|
|
|
$this->assertEquals('test.txt', $archive->getNameIndex(0)); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testZipFileSet(): void |
|
65
|
|
|
{ |
|
66
|
|
|
$filename = PHING_TEST_BASE . |
|
67
|
|
|
'/etc/tasks/ext/tmp/simple-test.zip'; |
|
68
|
|
|
|
|
69
|
|
|
$this->executeTarget(__FUNCTION__); |
|
70
|
|
|
$this->assertFileExists($filename); |
|
71
|
|
|
|
|
72
|
|
|
$archive = new ZipArchive(); |
|
73
|
|
|
$archive->open($filename); |
|
74
|
|
|
|
|
75
|
|
|
$this->assertEquals('test.txt', $archive->getNameIndex(0)); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testZipBaseDir(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$filename = PHING_TEST_BASE . '/etc/tasks/ext/tmp/simple-test.zip'; |
|
81
|
|
|
|
|
82
|
|
|
$this->executeTarget(__FUNCTION__); |
|
83
|
|
|
$this->assertFileExists($filename); |
|
84
|
|
|
|
|
85
|
|
|
$archive = new ZipArchive(); |
|
86
|
|
|
$archive->open($filename); |
|
87
|
|
|
|
|
88
|
|
|
$this->assertEquals('test.txt', $archive->getNameIndex(0)); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function testUnzipSimpleZip(): void |
|
92
|
|
|
{ |
|
93
|
|
|
$filename = PHING_TEST_BASE . |
|
94
|
|
|
'/etc/tasks/ext/tmp/test.txt'; |
|
95
|
|
|
|
|
96
|
|
|
$this->assertFileDoesNotExist($filename); |
|
97
|
|
|
|
|
98
|
|
|
$this->executeTarget(__FUNCTION__); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertFileExists($filename); |
|
101
|
|
|
$this->assertStringEqualsFile($filename, 'TEST'); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testRetainOriginalPremissionsOfDirectory(): void |
|
105
|
|
|
{ |
|
106
|
|
|
$filename = PHING_TEST_BASE . '/etc/tasks/ext/tmp/simple-test.zip'; |
|
107
|
|
|
|
|
108
|
|
|
$this->executeTarget(__FUNCTION__); |
|
109
|
|
|
$this->assertFileExists($filename); |
|
110
|
|
|
|
|
111
|
|
|
$archive = new ZipArchive(); |
|
112
|
|
|
$archive->open($filename); |
|
113
|
|
|
$opsys = 0; |
|
114
|
|
|
$attr = 0; |
|
115
|
|
|
$archive->getExternalAttributesIndex(0, $opsys, $attr); |
|
116
|
|
|
|
|
117
|
|
|
$this->assertNotEquals( |
|
118
|
|
|
511, |
|
119
|
|
|
($attr >> 16) & 0777, |
|
120
|
|
|
'directory should not be added with world-writable perms' |
|
121
|
|
|
); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|