source: branches/version-2_12-multilang/test/class/util/SC_Utils_Test.php @ 22081

Revision 22081, 5.1 KB checked in by h_yoshimoto, 10 years ago (diff)

#1955 r22062~r22080間のコミットをmerge

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2012 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
25require_once(realpath(dirname(__FILE__)) . '/../../require.php');
26require_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 */
35class SC_Utils_Test extends PHPUnit_Framework_TestCase {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * SC_Utils::getRealURL() のテストケース.
42     *
43     * 変換無し
44     */
45    function testGetRealURL_変換無し() {
46        $url = "http://www.example.jp/admin/index.php";
47
48        $expected = "http://www.example.jp:/admin/index.php";
49        $actual = SC_Utils::getRealURL($url);
50
51        $this->assertEquals($expected, $actual);
52    }
53
54    function testGetRealURL_変換有() {
55        $url = "http://www.example.jp/admin/../index.php";
56
57        $expected = "http://www.example.jp:/index.php";
58        $actual = SC_Utils::getRealURL($url);
59
60        $this->assertEquals($expected, $actual);
61    }
62
63    function testGetRealURL_空のディレクトリ() {
64        $url = "http://www.example.jp/admin/..///index.php";
65
66        $expected = "http://www.example.jp:/index.php";
67        $actual = SC_Utils::getRealURL($url);
68
69        $this->assertEquals($expected, $actual);
70    }
71
72    function testGetRealURL_Dotのディレクトリ() {
73        $url = "http://www.example.jp/admin/././../index.php";
74
75        $expected = "http://www.example.jp:/index.php";
76        $actual = SC_Utils::getRealURL($url);
77
78        $this->assertEquals($expected, $actual);
79    }
80
81    function testIsBlank() {
82        $val = "";
83        $this->assertTrue(SC_Utils::isBlank($val));
84
85        $valIsNotBlank = "\x00..\x1F  a \n\t";
86        $this->assertTrue(SC_Utils::isBlank($val));
87
88        $wideSpace = " ";
89        $this->assertTrue(SC_Utils::isBlank($wideSpace));
90        // greedy is false
91        $this->assertFalse(SC_Utils::isBlank($wideSpace, false));
92
93        $array = array();
94        $this->assertTrue(SC_Utils::isBlank($array));
95
96        $nestsArray = array(array(array()));
97        $this->assertTrue(SC_Utils::isBlank($nestsArray));
98        // greedy is false
99        $this->assertFalse(SC_Utils::isBlank($nestsArray, false));
100
101        $nestsArrayIsNotBlank = array(array(array('1')));
102        $this->assertFalse(SC_Utils::isBlank($nestsArrayIsNotBlank));
103        // greedy is false
104        $this->assertFalse(SC_Utils::isBlank($nestsArrayIsNotBlank, false));
105
106        $wideSpaceAndBlank = array(array(" \n "));
107        $this->assertTrue(SC_Utils::isBlank($wideSpaceAndBlank));
108        // greedy is false
109        $this->assertFalse(SC_Utils::isBlank($wideSpaceAndBlank, false));
110
111        $wideSpaceIsNotBlank = array(array(" \na "));
112        $this->assertFalse(SC_Utils::isBlank($wideSpaceIsNotBlank));
113        // greedy is false
114        $this->assertFalse(SC_Utils::isBlank($wideSpaceIsNotBlank, false));
115
116        $zero = 0;
117        $this->assertFalse(SC_Utils::isBlank($zero));
118        $this->assertFalse(SC_Utils::isBlank($zero, false));
119
120        $emptyArray[0] = "";
121        $this->assertTrue(SC_Utils::isBlank($emptyArray));
122    }
123
124    function testIsAbsoluteRealPath() {
125        // for *NIX
126        if (strpos(PHP_OS, 'WIN') === false) {
127            $unix_absolute = '/usr/local';
128            $this->assertTrue(SC_Utils::isAbsoluteRealPath($unix_absolute));
129
130            $relative = '../foo/bar';
131            $this->assertFalse(SC_Utils::isAbsoluteRealPath($relative));
132        }
133        // for Win
134        else {
135            $win_absolute = 'C:\Windows\system32';
136            $this->assertTrue(SC_Utils::isAbsoluteRealPath($win_absolute));
137
138            $win_absolute = 'C:/Windows/system32';
139            $this->assertTrue(SC_Utils::isAbsoluteRealPath($win_absolute));
140
141            $relative = '..\\foo\\bar';
142            $this->assertFalse(SC_Utils::isAbsoluteRealPath($relative));
143
144        }
145
146        $empty = '';
147        $this->assertFalse(SC_Utils::isAbsoluteRealPath($empty));
148    }
149
150    function testRecursiveMkdir() {
151        $tmp_dir = sys_get_temp_dir();
152        $dir = '/foo/bar';
153        $results = false;
154        if (is_dir($tmp_dir . $dir)) {
155            rmdir($tmp_dir . '/foo/bar');
156            rmdir($tmp_dir . '/foo');
157        }
158        $results = SC_Utils::recursiveMkdir($tmp_dir . $dir, 0777);
159        $this->assertTrue($results);
160    }
161}
162?>
Note: See TracBrowser for help on using the repository browser.