1 | <?php |
---|
2 | |
---|
3 | $HOME = realpath(dirname(__FILE__)) . "/../../../.."; |
---|
4 | require_once($HOME . "/tests/class/Common_TestCase.php"); |
---|
5 | /* |
---|
6 | * This file is part of EC-CUBE |
---|
7 | * |
---|
8 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
---|
9 | * |
---|
10 | * http://www.lockon.co.jp/ |
---|
11 | * |
---|
12 | * This program is free software; you can redistribute it and/or |
---|
13 | * modify it under the terms of the GNU General Public License |
---|
14 | * as published by the Free Software Foundation; either version 2 |
---|
15 | * of the License, or (at your option) any later version. |
---|
16 | * |
---|
17 | * This program is distributed in the hope that it will be useful, |
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
20 | * GNU General Public License for more details. |
---|
21 | * |
---|
22 | * You should have received a copy of the GNU General Public License |
---|
23 | * along with this program; if not, write to the Free Software |
---|
24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
25 | */ |
---|
26 | |
---|
27 | /** |
---|
28 | * SC_Utils::sfCopyDir()のテストクラス. |
---|
29 | * |
---|
30 | * |
---|
31 | * @author Hiroko Tamagawa |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class SC_Utils_sfCopyDirTest extends Common_TestCase { |
---|
35 | |
---|
36 | static $TMP_DIR; |
---|
37 | |
---|
38 | protected function setUp() { |
---|
39 | // parent::setUp(); |
---|
40 | self::$TMP_DIR = realpath(dirname(__FILE__)) . "/../../../tmp"; |
---|
41 | SC_Helper_FileManager::deleteFile(self::$TMP_DIR); |
---|
42 | mkdir(self::$TMP_DIR, 0777, true); |
---|
43 | } |
---|
44 | |
---|
45 | protected function tearDown() { |
---|
46 | // parent::tearDown(); |
---|
47 | } |
---|
48 | |
---|
49 | ///////////////////////////////////////// |
---|
50 | public function testSfCopyDir_ディレクトリでない場合_falseを返し何もしない() { |
---|
51 | mkdir(self::$TMP_DIR . "/src", 0777, true); |
---|
52 | $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w"); |
---|
53 | fwrite($fp, "hello"); |
---|
54 | fclose($fp); |
---|
55 | |
---|
56 | $src = self::$TMP_DIR . "/src/test.txt"; // ディレクトリではなくファイルを指定 |
---|
57 | $dst = self::$TMP_DIR . "/dst/"; |
---|
58 | |
---|
59 | $this->expected = array( |
---|
60 | 'result' => FALSE, |
---|
61 | 'file_exists' => FALSE |
---|
62 | ); |
---|
63 | $this->actual['result'] = SC_Utils::sfCopyDir($src, $dst); |
---|
64 | $this->actual['file_exists'] = file_exists($dst); |
---|
65 | |
---|
66 | $this->verify(); |
---|
67 | } |
---|
68 | |
---|
69 | public function testSfCopyDir_コピー先のディレクトリが存在しない場合_新たに作成する() { |
---|
70 | mkdir(self::$TMP_DIR . "/src", 0777, true); |
---|
71 | $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w"); |
---|
72 | fwrite($fp, "hello"); |
---|
73 | fclose($fp); |
---|
74 | |
---|
75 | $src = self::$TMP_DIR . "/src/"; |
---|
76 | $dst = self::$TMP_DIR . "/dst/"; |
---|
77 | |
---|
78 | $this->expected = array( |
---|
79 | 'dir_exists' => TRUE, |
---|
80 | 'files' => array('test.txt') |
---|
81 | ); |
---|
82 | SC_Utils::sfCopyDir($src, $dst); |
---|
83 | $this->actual['dir_exists'] = is_dir($dst); |
---|
84 | $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name'); |
---|
85 | |
---|
86 | $this->verify(); |
---|
87 | } |
---|
88 | |
---|
89 | // TODO CVS以下のEntriesなどはコピーされないが、CVSという親ディレクトリはコピーされてしまう。 |
---|
90 | // そもそも、CVSだけ特別扱いする意味がないような… |
---|
91 | public function testSfCopyDir_コピー先のディレクトリが存在する場合_そのままコピーする() { |
---|
92 | mkdir(self::$TMP_DIR . "/src", 0777, true); |
---|
93 | mkdir(self::$TMP_DIR . "/dst", 0777, true); // コピー先も作成しておく |
---|
94 | $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w"); |
---|
95 | fwrite($fp, "hello"); |
---|
96 | fclose($fp); |
---|
97 | |
---|
98 | // CVS関連のディレクトリ |
---|
99 | mkdir(self::$TMP_DIR . "/src/CVS/Entries", 0777, true); |
---|
100 | mkdir(self::$TMP_DIR . "/src/CVS/Repository", 0777, true); |
---|
101 | mkdir(self::$TMP_DIR . "/src/CVS/Root", 0777, true); |
---|
102 | |
---|
103 | // 入れ子になったディレクトリ |
---|
104 | mkdir(self::$TMP_DIR . "/src/dir1/dir12/dir123", 0777, true); |
---|
105 | |
---|
106 | // 上書きされないファイル |
---|
107 | $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "w"); |
---|
108 | fwrite($fp, "good morning"); |
---|
109 | fclose($fp); |
---|
110 | |
---|
111 | $src = self::$TMP_DIR . "/src/"; |
---|
112 | $dst = self::$TMP_DIR . "/dst/"; |
---|
113 | |
---|
114 | $this->expected = array( |
---|
115 | 'dir_exists' => TRUE, |
---|
116 | 'files' => array('CVS', 'dir1', 'test.txt'), |
---|
117 | 'files_2' => array('dir12'), |
---|
118 | 'files_3' => array('dir123'), |
---|
119 | 'file_content' => 'good morning' |
---|
120 | ); |
---|
121 | SC_Utils::sfCopyDir($src, $dst); |
---|
122 | $this->actual['dir_exists'] = is_dir($dst); |
---|
123 | $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name'); |
---|
124 | $this->actual['files_2'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst . "dir1/"), 'file_name'); |
---|
125 | $this->actual['files_3'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst . "dir1/dir12/"), 'file_name'); |
---|
126 | $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "r"); |
---|
127 | $this->actual['file_content'] = fread($fp, 100); |
---|
128 | |
---|
129 | $this->verify(); |
---|
130 | } |
---|
131 | |
---|
132 | public function testSfCopyDir_上書きフラグがONの場合_同名ファイルが上書きされる() { |
---|
133 | mkdir(self::$TMP_DIR . "/src", 0777, true); |
---|
134 | mkdir(self::$TMP_DIR . "/dst", 0777, true); // コピー先も作成しておく |
---|
135 | $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w"); |
---|
136 | fwrite($fp, "hello"); |
---|
137 | fclose($fp); |
---|
138 | |
---|
139 | // 上書きされるファイル |
---|
140 | $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "w"); |
---|
141 | fwrite($fp, "good morning"); |
---|
142 | fclose($fp); |
---|
143 | |
---|
144 | $src = self::$TMP_DIR . "/src/"; |
---|
145 | $dst = self::$TMP_DIR . "/dst/"; |
---|
146 | |
---|
147 | $this->expected = array( |
---|
148 | 'dir_exists' => TRUE, |
---|
149 | 'files' => array('test.txt'), |
---|
150 | 'file_content' => 'hello' |
---|
151 | ); |
---|
152 | SC_Utils::sfCopyDir($src, $dst, '', TRUE); |
---|
153 | $this->actual['dir_exists'] = is_dir($dst); |
---|
154 | $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name'); |
---|
155 | $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "r"); |
---|
156 | $this->actual['file_content'] = fread($fp, 100); |
---|
157 | |
---|
158 | $this->verify(); |
---|
159 | } |
---|
160 | |
---|
161 | public function testSfCopyDir_上書きフラグがONかつ書き込み権限がない場合_同名ファイルが上書きされない() { |
---|
162 | mkdir(self::$TMP_DIR . "/src", 0777, true); |
---|
163 | mkdir(self::$TMP_DIR . "/dst", 0777, true); // コピー先も作成しておく |
---|
164 | $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w"); |
---|
165 | fwrite($fp, "hello"); |
---|
166 | fclose($fp); |
---|
167 | |
---|
168 | // 上書きされないファイル |
---|
169 | $test_file = self::$TMP_DIR . "/dst/test.txt"; |
---|
170 | $fp = fopen($test_file, "w"); |
---|
171 | fwrite($fp, "good morning"); |
---|
172 | fclose($fp); |
---|
173 | chmod($test_file, 0444); // いったん読取専用にする |
---|
174 | |
---|
175 | $src = self::$TMP_DIR . "/src/"; |
---|
176 | $dst = self::$TMP_DIR . "/dst/"; |
---|
177 | |
---|
178 | $this->expected = array( |
---|
179 | 'dir_exists' => TRUE, |
---|
180 | 'files' => array('test.txt'), |
---|
181 | 'file_content' => 'good morning' |
---|
182 | ); |
---|
183 | SC_Utils::sfCopyDir($src, $dst, '', TRUE); |
---|
184 | $this->actual['dir_exists'] = is_dir($dst); |
---|
185 | $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name'); |
---|
186 | $fp = fopen($test_file, "r"); |
---|
187 | $this->actual['file_content'] = fread($fp, 100); |
---|
188 | |
---|
189 | chmod($test_file, 0777); // verifyする前にパーミッションを戻す |
---|
190 | $this->verify(); |
---|
191 | } |
---|
192 | |
---|
193 | ////////////////////////////////////////// |
---|
194 | |
---|
195 | } |
---|
196 | |
---|