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

Revision 22857, 5.9 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::copyDirectory()のテストクラス.
29 * TODO : 最後にスラッシュがないとうまくいかないのは良いのか?
30 *
31 * @author Hiroko Tamagawa
32 * @version $Id$
33 */
34class SC_Utils_copyDirectoryTest 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, 0700, true);
45  }
46
47  protected function tearDown()
48  {
49    // parent::tearDown();
50  }
51
52  /////////////////////////////////////////
53  public function testCopyDirectory_存在するパスの場合_指定したパス以下が再帰的にコピーされる()
54  {
55    /**
56     * tests/tmp/src
57     *             /dir10
58     *             /dir20/dir21
59     *                   /file22.txt
60     */
61    mkdir(self::$TMP_DIR . "/src", 0700, true);
62    mkdir(self::$TMP_DIR . "/src/dir10", 0700, true);
63    mkdir(self::$TMP_DIR . "/src/dir20", 0700, true);
64    mkdir(self::$TMP_DIR . "/src/dir20/dir21", 0700, true);
65    $fp = fopen(self::$TMP_DIR . "/src/dir20/file22.txt", "w");
66    fwrite($fp, "ec-cube test");
67    fclose($fp);
68    mkdir(self::$TMP_DIR . "/dst");
69
70    SC_Utils::copyDirectory(self::$TMP_DIR . "/src/", self::$TMP_DIR . "/dst/");
71
72    $this->expected = array("dir10", "dir20", "dir21", "file22.txt");
73    $this->actual = array();
74    Test_Utils::array_append($this->actual, Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList(self::$TMP_DIR . "/dst"), "file_name"));
75    Test_Utils::array_append($this->actual, Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList(self::$TMP_DIR . "/dst/dir20"), "file_name"));
76   
77    $this->verify('コピーされたファイル一覧');
78  }
79
80  public function testCopyDirectory_存在しないパスの場合_何も起こらない()
81  {
82    /**
83     * tests/tmp/src
84     *             /dir10
85     *             /dir20/dir21
86     *                   /file22.txt
87     */
88    // mkdir(self::$TMP_DIR . "/src", 0700, true);
89    mkdir(self::$TMP_DIR . "/dst");
90
91    SC_Utils::copyDirectory(self::$TMP_DIR . "/src/", self::$TMP_DIR . "/dst/");
92
93    $this->expected = array();
94    $this->actual = array();
95   
96    $this->verify('コピーされたファイル一覧');
97  }
98
99  public function testCopyDirectory_コピー先のディレクトリが元々存在する場合_上書きされる()
100  {
101    /**
102     * tests/tmp/src
103     *             /dir10
104     *             /dir20/dir21
105     *                   /file22.txt
106     */
107    mkdir(self::$TMP_DIR . "/src", 0700, true);
108    mkdir(self::$TMP_DIR . "/src/dir10", 0700, true);
109    mkdir(self::$TMP_DIR . "/src/dir20", 0700, true);
110    mkdir(self::$TMP_DIR . "/src/dir20/dir21", 0700, true);
111    $fp = fopen(self::$TMP_DIR . "/src/dir20/file22.txt", "w");
112    fwrite($fp, "ec-cube test");
113    fclose($fp);
114    mkdir(self::$TMP_DIR . "/dst");
115    mkdir(self::$TMP_DIR . "/dst/dir20/dir23", 0700, true);
116
117    SC_Utils::copyDirectory(self::$TMP_DIR . "/src/", self::$TMP_DIR . "/dst/");
118
119    $this->expected = array("dir10", "dir20", "dir21", "dir23", "file22.txt");
120    $this->actual = array();
121    Test_Utils::array_append($this->actual, Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList(self::$TMP_DIR . "/dst"), "file_name"));
122    Test_Utils::array_append($this->actual, Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList(self::$TMP_DIR . "/dst/dir20"), "file_name"));
123   
124    $this->verify('コピー先のファイル一覧');
125  }
126
127  public function testCopyDirectory_コピー先のファイルが元々存在する場合_上書きされる()
128  {
129    /**
130     * tests/tmp/src
131     *             /dir10
132     *             /dir20/dir21
133     *                   /file22.txt
134     */
135    mkdir(self::$TMP_DIR . "/src", 0700, true);
136    mkdir(self::$TMP_DIR . "/src/dir10", 0700, true);
137    mkdir(self::$TMP_DIR . "/src/dir20", 0700, true);
138    mkdir(self::$TMP_DIR . "/src/dir20/dir21", 0700, true);
139    $fp = fopen(self::$TMP_DIR . "/src/dir20/file22.txt", "w");
140    fwrite($fp, "ec-cube test");
141    fclose($fp);
142    mkdir(self::$TMP_DIR . "/dst");
143    mkdir(self::$TMP_DIR . "/dst/dir20");
144    $fp_dist = fopen(self::$TMP_DIR . "/dst/dir20/file22.txt", "w");
145    fwrite($fp_dist, "hello");
146    fclose($fp_dist);
147
148    SC_Utils::copyDirectory(self::$TMP_DIR . "/src/", self::$TMP_DIR . "/dst/");
149
150    $this->expected = array("dir10", "dir20", "dir21", "file22.txt", "ec-cube test");
151    $this->actual = array();
152    Test_Utils::array_append($this->actual, Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList(self::$TMP_DIR . "/dst"), "file_name"));
153    Test_Utils::array_append($this->actual, Test_Utils::mapCols(SC_Helper_FileManager::sfGetFileList(self::$TMP_DIR . "/dst/dir20"), "file_name"));
154    $fp_final = fopen(self::$TMP_DIR . "/dst/dir20/file22.txt", "r");
155    $read_result = fread($fp_final, 100);
156    fclose($fp_final);
157    $this->actual[] = $read_result;
158
159    $this->verify('コピー先のファイル一覧');
160  }
161
162  //////////////////////////////////////////
163}
164
Note: See TracBrowser for help on using the repository browser.