3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * Class CRM_Utils_ZipTest
32 class CRM_Utils_ZipTest
extends CiviUnitTestCase
{
34 public function setUp() {
39 public function tearDown() {
46 public function testFindBaseDirName_normal() {
47 $this->_doFindBaseDirName('author-com.example.foo-random/',
48 array('author-com.example.foo-random'),
49 array('author-com.example.foo-random/README.txt' => 'hello')
53 public function testFindBaseDirName_0() {
54 $this->_doFindBaseDirName('0/',
60 public function testFindBaseDirName_plainfile() {
61 $this->_doFindBaseDirName(FALSE,
63 array('README.txt' => 'hello')
67 public function testFindBaseDirName_twodir() {
68 $this->_doFindBaseDirName(FALSE,
69 array('dir-1', 'dir-2'),
70 array('dir-1/README.txt' => 'hello')
74 public function testFindBaseDirName_dirfile() {
75 $this->_doFindBaseDirName(FALSE,
77 array('dir-1/README.txt' => 'hello', 'MANIFEST.MF' => 'extra')
81 public function testFindBaseDirName_dot() {
82 $this->_doFindBaseDirName(FALSE,
84 array('./README.txt' => 'hello')
88 public function testFindBaseDirName_dots() {
89 $this->_doFindBaseDirName(FALSE,
91 array('../README.txt' => 'hello')
95 public function testFindBaseDirName_weird() {
96 $this->_doFindBaseDirName(FALSE,
98 array('foo/../README.txt' => 'hello')
102 public function testGuessBaseDir_normal() {
103 $this->_doGuessBaseDir('author-com.example.foo-random',
104 array('author-com.example.foo-random'),
105 array('author-com.example.foo-random/README.txt' => 'hello'),
110 public function testGuessBaseDir_MACOSX() {
111 $this->_doGuessBaseDir('com.example.foo',
112 array('com.example.foo', '__MACOSX'),
113 array('author-com.example.foo-random/README.txt' => 'hello', '__MACOSX/foo' => 'bar'),
118 public function testGuessBaseDir_0() {
119 $this->_doGuessBaseDir('0',
126 public function testGuessBaseDir_plainfile() {
127 $this->_doGuessBaseDir(FALSE,
129 array('README.txt' => 'hello'),
134 public function testGuessBaseDirTwoDir() {
135 $this->_doGuessBaseDir(FALSE,
136 array('dir-1', 'dir-2'),
137 array('dir-1/README.txt' => 'hello'),
142 public function testGuessBaseDirWeird() {
143 $this->_doGuessBaseDir(FALSE,
145 array('foo/../README.txt' => 'hello'),
151 * @param string $expectedBaseDirName
155 public function _doFindBaseDirName($expectedBaseDirName, $dirs, $files) {
156 $this->file
= tempnam(sys_get_temp_dir(), 'testzip-');
157 $this->assertTrue(CRM_Utils_Zip
::createTestZip($this->file
, $dirs, $files));
159 $zip = new ZipArchive();
160 $this->assertTrue($zip->open($this->file
));
161 $this->assertEquals($expectedBaseDirName, CRM_Utils_Zip
::findBaseDirName($zip));
165 * @param $expectedResult
168 * @param $expectedKey
170 public function _doGuessBaseDir($expectedResult, $dirs, $files, $expectedKey) {
171 $this->file
= tempnam(sys_get_temp_dir(), 'testzip-');
172 $this->assertTrue(CRM_Utils_Zip
::createTestZip($this->file
, $dirs, $files));
174 $zip = new ZipArchive();
175 $this->assertTrue($zip->open($this->file
));
176 $this->assertEquals($expectedResult, CRM_Utils_Zip
::guessBaseDir($zip, $expectedKey));