3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
31 class CRM_Utils_ZipTest
extends CiviUnitTestCase
{
33 public function setUp() {
38 public function tearDown() {
45 public function testFindBaseDirName_normal() {
46 $this->_doFindBaseDirName('author-com.example.foo-random/',
47 array('author-com.example.foo-random'),
48 array('author-com.example.foo-random/README.txt' => 'hello')
52 public function testFindBaseDirName_0() {
53 $this->_doFindBaseDirName('0/',
59 public function testFindBaseDirName_plainfile() {
60 $this->_doFindBaseDirName(FALSE,
62 array('README.txt' => 'hello')
66 public function testFindBaseDirName_twodir() {
67 $this->_doFindBaseDirName(FALSE,
68 array('dir-1', 'dir-2'),
69 array('dir-1/README.txt' => 'hello')
73 public function testFindBaseDirName_dirfile() {
74 $this->_doFindBaseDirName(FALSE,
76 array('dir-1/README.txt' => 'hello', 'MANIFEST.MF' => 'extra')
80 public function testFindBaseDirName_dot() {
81 $this->_doFindBaseDirName(FALSE,
83 array('./README.txt' => 'hello')
87 public function testFindBaseDirName_dots() {
88 $this->_doFindBaseDirName(FALSE,
90 array('../README.txt' => 'hello')
94 public function testFindBaseDirName_weird() {
95 $this->_doFindBaseDirName(FALSE,
97 array('foo/../README.txt' => 'hello')
101 public function testGuessBaseDir_normal() {
102 $this->_doGuessBaseDir('author-com.example.foo-random',
103 array('author-com.example.foo-random'),
104 array('author-com.example.foo-random/README.txt' => 'hello'),
109 public function testGuessBaseDir_MACOSX() {
110 $this->_doGuessBaseDir('com.example.foo',
111 array('com.example.foo', '__MACOSX'),
112 array('author-com.example.foo-random/README.txt' => 'hello', '__MACOSX/foo' => 'bar'),
117 public function testGuessBaseDir_0() {
118 $this->_doGuessBaseDir('0',
125 public function testGuessBaseDir_plainfile() {
126 $this->_doGuessBaseDir(FALSE,
128 array('README.txt' => 'hello'),
133 public function testGuessBaseDirTwoDir() {
134 $this->_doGuessBaseDir(FALSE,
135 array('dir-1', 'dir-2'),
136 array('dir-1/README.txt' => 'hello'),
141 public function testGuessBaseDirWeird() {
142 $this->_doGuessBaseDir(FALSE,
144 array('foo/../README.txt' => 'hello'),
150 * @param string $expectedBaseDirName
154 public function _doFindBaseDirName($expectedBaseDirName, $dirs, $files) {
155 $this->file
= tempnam(sys_get_temp_dir(), 'testzip-');
156 $this->assertTrue(CRM_Utils_Zip
::createTestZip($this->file
, $dirs, $files));
158 $zip = new ZipArchive();
159 $this->assertTrue($zip->open($this->file
));
160 $this->assertEquals($expectedBaseDirName, CRM_Utils_Zip
::findBaseDirName($zip));
164 * @param $expectedResult
167 * @param $expectedKey
169 public function _doGuessBaseDir($expectedResult, $dirs, $files, $expectedKey) {
170 $this->file
= tempnam(sys_get_temp_dir(), 'testzip-');
171 $this->assertTrue(CRM_Utils_Zip
::createTestZip($this->file
, $dirs, $files));
173 $zip = new ZipArchive();
174 $this->assertTrue($zip->open($this->file
));
175 $this->assertEquals($expectedResult, CRM_Utils_Zip
::guessBaseDir($zip, $expectedKey));