source: branches/version-2_13-dev/tests/class/util/SC_Utils/SC_Utils_sfCopyDirtest.php @ 22857

Revision 22857, 6.8 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。
  • Property svn:keywords set to Id Rev Date
Line 
1<?php
2
3$HOME = realpath(dirname(__FILE__)) . "/../../../..";
4require_once($HOME . "/tests/class/Common_TestCase.php");
5/*
6 * This file is part of EC-CUBE
7 *
8 * Copyright(c) 2000-2013 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 */
34class SC_Utils_sfCopyDirTest extends Common_TestCase
35{
36
37  static $TMP_DIR;
38
39  protected function setUp()
40  {
41    // parent::setUp();
42    self::$TMP_DIR = realpath(dirname(__FILE__)) . "/../../../tmp";
43    SC_Helper_FileManager::deleteFile(self::$TMP_DIR);
44    mkdir(self::$TMP_DIR, 0777, true);
45  }
46
47  protected function tearDown()
48  {
49    // parent::tearDown();
50  }
51
52  /////////////////////////////////////////
53  public function testSfCopyDir_ディレクトリでない場合_falseを返し何もしない()
54  {
55    mkdir(self::$TMP_DIR . "/src", 0777, true);
56    $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w");
57    fwrite($fp, "hello");
58    fclose($fp);
59
60    $src = self::$TMP_DIR . "/src/test.txt"; // ディレクトリではなくファイルを指定
61    $dst = self::$TMP_DIR . "/dst/";
62
63    $this->expected = array(
64      'result' => FALSE,
65      'file_exists' => FALSE
66    );
67    $this->actual['result'] = SC_Utils::sfCopyDir($src, $dst);
68    $this->actual['file_exists'] = file_exists($dst);
69
70    $this->verify();
71  }
72
73  public function testSfCopyDir_コピー先のディレクトリが存在しない場合_新たに作成する()
74  {
75    mkdir(self::$TMP_DIR . "/src", 0777, true);
76    $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w");
77    fwrite($fp, "hello");
78    fclose($fp);
79
80    $src = self::$TMP_DIR . "/src/";
81    $dst = self::$TMP_DIR . "/dst/";
82
83    $this->expected = array(
84      'dir_exists' => TRUE,
85      'files' => array('test.txt')
86    );
87    SC_Utils::sfCopyDir($src, $dst);
88    $this->actual['dir_exists'] = is_dir($dst);
89    $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name');
90
91    $this->verify();
92  }
93
94  // TODO CVS以下のEntriesなどはコピーされないが、CVSという親ディレクトリはコピーされてしまう。
95  // そもそも、CVSだけ特別扱いする意味がないような…
96  public function testSfCopyDir_コピー先のディレクトリが存在する場合_そのままコピーする()
97  {
98    mkdir(self::$TMP_DIR . "/src", 0777, true);
99    mkdir(self::$TMP_DIR . "/dst", 0777, true); // コピー先も作成しておく
100    $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w");
101    fwrite($fp, "hello");
102    fclose($fp);
103
104    // CVS関連のディレクトリ
105    mkdir(self::$TMP_DIR . "/src/CVS/Entries", 0777, true);
106    mkdir(self::$TMP_DIR . "/src/CVS/Repository", 0777, true);
107    mkdir(self::$TMP_DIR . "/src/CVS/Root", 0777, true);
108
109    // 入れ子になったディレクトリ
110    mkdir(self::$TMP_DIR . "/src/dir1/dir12/dir123", 0777, true);
111
112    // 上書きされないファイル
113    $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "w");
114    fwrite($fp, "good morning");
115    fclose($fp);
116
117    $src = self::$TMP_DIR . "/src/";
118    $dst = self::$TMP_DIR . "/dst/";
119
120    $this->expected = array(
121      'dir_exists' => TRUE,
122      'files' => array('CVS', 'dir1', 'test.txt'),
123      'files_2' => array('dir12'),
124      'files_3' => array('dir123'),
125      'file_content' => 'good morning'
126    );
127    SC_Utils::sfCopyDir($src, $dst);
128    $this->actual['dir_exists'] = is_dir($dst);
129    $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name');
130    $this->actual['files_2'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst . "dir1/"), 'file_name');
131    $this->actual['files_3'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst . "dir1/dir12/"), 'file_name');
132    $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "r");
133    $this->actual['file_content'] = fread($fp, 100);
134
135    $this->verify();
136  }
137
138  public function testSfCopyDir_上書きフラグがONの場合_同名ファイルが上書きされる()
139  {
140    mkdir(self::$TMP_DIR . "/src", 0777, true);
141    mkdir(self::$TMP_DIR . "/dst", 0777, true); // コピー先も作成しておく
142    $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w");
143    fwrite($fp, "hello");
144    fclose($fp);
145
146    // 上書きされるファイル
147    $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "w");
148    fwrite($fp, "good morning");
149    fclose($fp);
150
151    $src = self::$TMP_DIR . "/src/";
152    $dst = self::$TMP_DIR . "/dst/";
153
154    $this->expected = array(
155      'dir_exists' => TRUE,
156      'files' => array('test.txt'),
157      'file_content' => 'hello'
158    );
159    SC_Utils::sfCopyDir($src, $dst, '', TRUE);
160    $this->actual['dir_exists'] = is_dir($dst);
161    $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name');
162    $fp = fopen(self::$TMP_DIR . "/dst/test.txt", "r");
163    $this->actual['file_content'] = fread($fp, 100);
164
165    $this->verify();
166  }
167
168  public function testSfCopyDir_上書きフラグがONかつ書き込み権限がない場合_同名ファイルが上書きされない()
169  {
170    mkdir(self::$TMP_DIR . "/src", 0777, true);
171    mkdir(self::$TMP_DIR . "/dst", 0777, true); // コピー先も作成しておく
172    $fp = fopen(self::$TMP_DIR . "/src/test.txt", "w");
173    fwrite($fp, "hello");
174    fclose($fp);
175
176    // 上書きされないファイル
177    $test_file = self::$TMP_DIR . "/dst/test.txt";
178    $fp = fopen($test_file, "w");
179    fwrite($fp, "good morning");
180    fclose($fp);
181    chmod($test_file, 0444); // いったん読取専用にする
182
183    $src = self::$TMP_DIR . "/src/";
184    $dst = self::$TMP_DIR . "/dst/";
185
186    $this->expected = array(
187      'dir_exists' => TRUE,
188      'files' => array('test.txt'),
189      'file_content' => 'good morning'
190    );
191    SC_Utils::sfCopyDir($src, $dst, '', TRUE);
192    $this->actual['dir_exists'] = is_dir($dst);
193    $this->actual['files'] = Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList($dst), 'file_name');
194    $fp = fopen($test_file, "r");
195    $this->actual['file_content'] = fread($fp, 100);
196
197    chmod($test_file, 0777); // verifyする前にパーミッションを戻す
198    $this->verify();
199  }
200
201  //////////////////////////////////////////
202}
203
Note: See TracBrowser for help on using the repository browser.