1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | // {{{ requires |
---|
25 | require_once(realpath(dirname(__FILE__)) . '/../../require.php'); |
---|
26 | require_once(realpath(dirname(__FILE__)) . '/../../../data/class/pages/LC_Page.php'); |
---|
27 | |
---|
28 | /** |
---|
29 | * SC_Utils のテストケース. |
---|
30 | * |
---|
31 | * @package Page |
---|
32 | * @author LOCKON CO.,LTD. |
---|
33 | * @version $Id:LC_Page_Test.php 15116 2007-07-23 11:32:53Z nanasess $ |
---|
34 | */ |
---|
35 | class SC_Utils_Test extends PHPUnit_Framework_TestCase |
---|
36 | { |
---|
37 | |
---|
38 | // }}} |
---|
39 | // {{{ functions |
---|
40 | |
---|
41 | /** |
---|
42 | * SC_Utils::getRealURL() のテストケース. |
---|
43 | * |
---|
44 | * 変換無し |
---|
45 | */ |
---|
46 | function testGetRealURL_変換無し() |
---|
47 | { |
---|
48 | $url = "http://www.example.jp/admin/index.php"; |
---|
49 | |
---|
50 | $expected = "http://www.example.jp:/admin/index.php"; |
---|
51 | $actual = SC_Utils::getRealURL($url); |
---|
52 | |
---|
53 | $this->assertEquals($expected, $actual); |
---|
54 | } |
---|
55 | |
---|
56 | function testGetRealURL_変換有() |
---|
57 | { |
---|
58 | $url = "http://www.example.jp/admin/../index.php"; |
---|
59 | |
---|
60 | $expected = "http://www.example.jp:/index.php"; |
---|
61 | $actual = SC_Utils::getRealURL($url); |
---|
62 | |
---|
63 | $this->assertEquals($expected, $actual); |
---|
64 | } |
---|
65 | |
---|
66 | function testGetRealURL_空のディレクトリ() |
---|
67 | { |
---|
68 | $url = "http://www.example.jp/admin/..///index.php"; |
---|
69 | |
---|
70 | $expected = "http://www.example.jp:/index.php"; |
---|
71 | $actual = SC_Utils::getRealURL($url); |
---|
72 | |
---|
73 | $this->assertEquals($expected, $actual); |
---|
74 | } |
---|
75 | |
---|
76 | function testGetRealURL_Dotのディレクトリ() |
---|
77 | { |
---|
78 | $url = "http://www.example.jp/admin/././../index.php"; |
---|
79 | |
---|
80 | $expected = "http://www.example.jp:/index.php"; |
---|
81 | $actual = SC_Utils::getRealURL($url); |
---|
82 | |
---|
83 | $this->assertEquals($expected, $actual); |
---|
84 | } |
---|
85 | |
---|
86 | function testIsBlank() |
---|
87 | { |
---|
88 | $val = ""; |
---|
89 | $this->assertTrue(SC_Utils::isBlank($val)); |
---|
90 | |
---|
91 | $valIsNotBlank = "\x00..\x1F a \n\t"; |
---|
92 | $this->assertTrue(SC_Utils::isBlank($val)); |
---|
93 | |
---|
94 | $wideSpace = " "; |
---|
95 | $this->assertTrue(SC_Utils::isBlank($wideSpace)); |
---|
96 | // greedy is false |
---|
97 | $this->assertFalse(SC_Utils::isBlank($wideSpace, false)); |
---|
98 | |
---|
99 | $array = array(); |
---|
100 | $this->assertTrue(SC_Utils::isBlank($array)); |
---|
101 | |
---|
102 | $nestsArray = array(array(array())); |
---|
103 | $this->assertTrue(SC_Utils::isBlank($nestsArray)); |
---|
104 | // greedy is false |
---|
105 | $this->assertFalse(SC_Utils::isBlank($nestsArray, false)); |
---|
106 | |
---|
107 | $nestsArrayIsNotBlank = array(array(array('1'))); |
---|
108 | $this->assertFalse(SC_Utils::isBlank($nestsArrayIsNotBlank)); |
---|
109 | // greedy is false |
---|
110 | $this->assertFalse(SC_Utils::isBlank($nestsArrayIsNotBlank, false)); |
---|
111 | |
---|
112 | $wideSpaceAndBlank = array(array(" \n ")); |
---|
113 | $this->assertTrue(SC_Utils::isBlank($wideSpaceAndBlank)); |
---|
114 | // greedy is false |
---|
115 | $this->assertFalse(SC_Utils::isBlank($wideSpaceAndBlank, false)); |
---|
116 | |
---|
117 | $wideSpaceIsNotBlank = array(array(" \na ")); |
---|
118 | $this->assertFalse(SC_Utils::isBlank($wideSpaceIsNotBlank)); |
---|
119 | // greedy is false |
---|
120 | $this->assertFalse(SC_Utils::isBlank($wideSpaceIsNotBlank, false)); |
---|
121 | |
---|
122 | $zero = 0; |
---|
123 | $this->assertFalse(SC_Utils::isBlank($zero)); |
---|
124 | $this->assertFalse(SC_Utils::isBlank($zero, false)); |
---|
125 | |
---|
126 | $emptyArray[0] = ""; |
---|
127 | $this->assertTrue(SC_Utils::isBlank($emptyArray)); |
---|
128 | } |
---|
129 | |
---|
130 | function testIsAbsoluteRealPath() |
---|
131 | { |
---|
132 | // for *NIX |
---|
133 | if (strpos(PHP_OS, 'WIN') === false) { |
---|
134 | $unix_absolute = '/usr/local'; |
---|
135 | $this->assertTrue(SC_Utils::isAbsoluteRealPath($unix_absolute)); |
---|
136 | |
---|
137 | $relative = '../foo/bar'; |
---|
138 | $this->assertFalse(SC_Utils::isAbsoluteRealPath($relative)); |
---|
139 | } |
---|
140 | // for Win |
---|
141 | else { |
---|
142 | $win_absolute = 'C:\Windows\system32'; |
---|
143 | $this->assertTrue(SC_Utils::isAbsoluteRealPath($win_absolute)); |
---|
144 | |
---|
145 | $win_absolute = 'C:/Windows/system32'; |
---|
146 | $this->assertTrue(SC_Utils::isAbsoluteRealPath($win_absolute)); |
---|
147 | |
---|
148 | $relative = '..\\foo\\bar'; |
---|
149 | $this->assertFalse(SC_Utils::isAbsoluteRealPath($relative)); |
---|
150 | } |
---|
151 | |
---|
152 | $empty = ''; |
---|
153 | $this->assertFalse(SC_Utils::isAbsoluteRealPath($empty)); |
---|
154 | } |
---|
155 | |
---|
156 | function testRecursiveMkdir() |
---|
157 | { |
---|
158 | $tmp_dir = sys_get_temp_dir(); |
---|
159 | $dir = '/foo/bar'; |
---|
160 | $results = false; |
---|
161 | if (is_dir($tmp_dir . $dir)) { |
---|
162 | rmdir($tmp_dir . '/foo/bar'); |
---|
163 | rmdir($tmp_dir . '/foo'); |
---|
164 | } |
---|
165 | $results = SC_Utils::recursiveMkdir($tmp_dir . $dir, 0777); |
---|
166 | $this->assertTrue($results); |
---|
167 | } |
---|
168 | } |
---|
169 | ?> |
---|