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

Revision 22193, 5.8 KB checked in by shift_hiroko.tamagawa, 9 years ago (diff)

#1977 SC_Utilsの単体テストを追加

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