9 use \Magento\Framework\Archive;
41 $this->sourceFilePath =
__DIR__ .
'/_files/source.txt';
42 $this->destinationDir =
__DIR__ .
'/_files/archives/';
47 if (!empty($this->packed) && file_exists($this->packed)) {
51 if (!empty($this->unpacked) && file_exists($this->unpacked)) {
53 $this->unpacked =
null;
64 $this->assertEquals($isArchive, $this->archive->isArchive($file));
73 [
'archive.tar',
true],
75 [
'archive.gzip',
true],
76 [
'archive.tgz',
true],
77 [
'archive.tgzip',
true],
79 [
'archive.bzip',
true],
80 [
'archive.bzip2',
true],
81 [
'archive.bz2',
true],
82 [
'archive.tbz',
true],
83 [
'archive.tbzip',
true],
84 [
'archive.tbz2',
true],
85 [
'archive.tbzip2',
true],
86 [
'archive.txt',
false],
87 [
'archive.php',
false],
88 [
'archive.phtml',
false],
89 [
'archive.js',
false],
90 [
'archive.log',
false],
101 $this->assertEquals($isArchive, $this->archive->isTar($file));
110 [
'archive.tar',
true],
111 [
'archive.gz',
false],
112 [
'archive.gzip',
false],
113 [
'archive.tgz',
false],
114 [
'archive.tgzip',
false],
115 [
'archive.bz',
false],
116 [
'archive.bzip',
false],
117 [
'archive.bzip2',
false],
118 [
'archive.bz2',
false],
119 [
'archive.tbz',
false],
120 [
'archive.tbzip',
false],
121 [
'archive.tbz2',
false],
122 [
'archive.tbzip2',
false],
123 [
'archive.txt',
false],
124 [
'archive.php',
false],
125 [
'archive.phtml',
false],
126 [
'archive.js',
false],
127 [
'archive.log',
false],
138 if ($extensionRequired && !extension_loaded($extensionRequired)) {
139 $this->markTestSkipped(
"The extension '{$extensionRequired}' is not enabled.");
141 $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile);
143 $this->assertFileExists($this->packed);
144 $this->assertEquals($this->destinationDir . $destinationFile, $this->packed);
146 $this->unpacked = $this->archive->unpack($this->packed, $this->destinationDir);
148 $this->assertFileExists($this->unpacked);
149 $this->assertStringStartsWith($this->destinationDir, $this->unpacked);
158 [
'archive.gz',
'zlib'],
159 [
'archive.gzip',
'zlib'],
160 [
'archive.bz',
'bz2'],
161 [
'archive.bzip',
'bz2'],
162 [
'archive.bzip2',
'bz2'],
163 [
'archive.bz2',
'bz2']
174 if ($extensionRequired && !extension_loaded($extensionRequired)) {
175 $this->markTestSkipped(
"The extension '{$extensionRequired}' is not enabled.");
177 $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile);
179 $this->assertFileExists($this->packed);
180 $this->assertEquals($this->destinationDir . $destinationFile, $this->packed);
182 $unpacked = $this->archive->unpack($this->packed, $this->destinationDir);
184 $this->unpacked =
$unpacked . pathinfo($this->sourceFilePath, PATHINFO_BASENAME);
186 $this->assertFileExists($this->unpacked);
187 $this->assertStringStartsWith($this->destinationDir, $this->unpacked);
197 if ($extensionRequired && !extension_loaded($extensionRequired)) {
198 $this->markTestSkipped(
"The extension '{$extensionRequired}' is not enabled.");
200 $this->packed = $this->archive->pack($this->sourceFilePath, $this->destinationDir . $destinationFile);
202 $this->assertFileExists($this->packed);
203 $this->assertEquals($this->destinationDir . $destinationFile, $this->packed);
205 $filename = pathinfo($this->sourceFilePath, PATHINFO_BASENAME);
206 $this->unpacked = $this->archive->extract($filename, $this->packed, $this->destinationDir);
208 $this->assertFileExists($this->unpacked);
209 $this->assertStringStartsWith($this->destinationDir, $this->unpacked);
219 [
'archive.tgz',
'zlib'],
220 [
'archive.tgzip',
'zlib'],
221 [
'archive.tbz',
'bz2'],
222 [
'archive.tbzip',
'bz2'],
223 [
'archive.tbz2',
'bz2'],
224 [
'archive.tbzip2',
'bz2']
defined('TESTS_BP')||define('TESTS_BP' __DIR__
testIsArchive($file, $isArchive)
testIsTar($file, $isArchive)
testExtract($destinationFile, $extensionRequired)
testPackUnpackTar($destinationFile, $extensionRequired)
testPackUnpackGzBz($destinationFile, $extensionRequired)