1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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("../html/require.php"); |
---|
26 | require_once("../data/class/pages/LC_Page.php"); |
---|
27 | require_once("PHPUnit/Framework.php"); |
---|
28 | |
---|
29 | /** |
---|
30 | * LC_Page のテストケース. |
---|
31 | * |
---|
32 | * @package Page |
---|
33 | * @author LOCKON CO.,LTD. |
---|
34 | * @version $Id:LC_Page_Test.php 15116 2007-07-23 11:32:53Z nanasess $ |
---|
35 | */ |
---|
36 | class LC_Page_Test extends PHPUnit_Framework_TestCase { |
---|
37 | |
---|
38 | // }}} |
---|
39 | // {{{ functions |
---|
40 | |
---|
41 | /* |
---|
42 | * FIXME LC_Page::sendRedirect() は, リダイレクトしてしまうため, |
---|
43 | * PHPUnit3 ではテストできない... |
---|
44 | */ |
---|
45 | |
---|
46 | /** |
---|
47 | * LC_Page::sendRedirect() のテストケース(エラー). |
---|
48 | */ |
---|
49 | /* |
---|
50 | function testSendRedirect() { |
---|
51 | $objPage = new LC_Page(); |
---|
52 | $result = $objPage->sendRedirect(SITE_URL); |
---|
53 | |
---|
54 | $this->assertEquals(true, empty($result)); |
---|
55 | } |
---|
56 | */ |
---|
57 | /** |
---|
58 | * LC_Page::sendRedirect() のテストケース(エラー). |
---|
59 | */ |
---|
60 | /* |
---|
61 | function testSendRedirectIsFailed() { |
---|
62 | $objPage = new LC_Page(); |
---|
63 | $result = $objPage->sendRedirect("http://www.example.org"); |
---|
64 | |
---|
65 | $this->assertEquals(false, $result); |
---|
66 | } |
---|
67 | */ |
---|
68 | |
---|
69 | /** |
---|
70 | * LC_Page::getToken() のテストケース. |
---|
71 | */ |
---|
72 | function testGetToken() { |
---|
73 | $objPage = new LC_Page(); |
---|
74 | |
---|
75 | $token = $objPage->getToken(); |
---|
76 | |
---|
77 | // 40文字の16進数 |
---|
78 | $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", $token)); |
---|
79 | |
---|
80 | // セッションに文字列が格納されているか |
---|
81 | $this->assertEquals($token, $_SESSION[TRANSACTION_ID_NAME]); |
---|
82 | } |
---|
83 | |
---|
84 | /** |
---|
85 | * LC_Page::isValidToken() のテストケース(POST). |
---|
86 | */ |
---|
87 | function testIsValidToken() { |
---|
88 | $objPage = new LC_Page(); |
---|
89 | |
---|
90 | $token = $objPage->getToken(); |
---|
91 | |
---|
92 | // POST でトークンを渡す. |
---|
93 | $_POST[TRANSACTION_ID_NAME] = $token; |
---|
94 | |
---|
95 | $this->assertEquals(true, $objPage->isValidToken()); |
---|
96 | unset($_POST[TRANSACTION_ID_NAME]); |
---|
97 | } |
---|
98 | |
---|
99 | /** |
---|
100 | * LC_Page::isValidToken() のテストケース(GET). |
---|
101 | */ |
---|
102 | function testIsValidTokenWithGET() { |
---|
103 | $objPage = new LC_Page(); |
---|
104 | |
---|
105 | $token = $objPage->getToken(); |
---|
106 | |
---|
107 | // GET でトークンを渡す. |
---|
108 | $_GET[TRANSACTION_ID_NAME] = $token; |
---|
109 | |
---|
110 | $this->assertEquals(true, $objPage->isValidToken()); |
---|
111 | unset($_GET[TRANSACTION_ID_NAME]); |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | /** |
---|
116 | * LC_Page::isValidToken() のテストケース(エラー). |
---|
117 | * |
---|
118 | * 値が渡されてない場合 |
---|
119 | */ |
---|
120 | function testIsValidTokenNotParam() { |
---|
121 | |
---|
122 | $objPage = new LC_Page(); |
---|
123 | |
---|
124 | $token = $objPage->getToken(); |
---|
125 | |
---|
126 | // 値を渡さなければ falsel |
---|
127 | $this->assertEquals(false, $objPage->isValidToken()); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * LC_Page::createToken() のテストケース. |
---|
132 | */ |
---|
133 | function testCreateToken() { |
---|
134 | // 40文字の16進数 |
---|
135 | $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", LC_Page::createToken())); |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * LC_Page::getLocation() のテストケース. |
---|
140 | */ |
---|
141 | function testGetLocation() { |
---|
142 | $objPage = new LC_Page(); |
---|
143 | $_SERVER['DOCUMENT_ROOT'] = realpath("../html"); |
---|
144 | $url = $objPage->getLocation("../html/abouts/index.php"); |
---|
145 | |
---|
146 | $this->assertEquals(SITE_URL . "abouts/index.php", $url); |
---|
147 | unset($_SERVER['DOCUMENT_ROOT']); |
---|
148 | } |
---|
149 | |
---|
150 | /** |
---|
151 | * LC_Page::getLocation() のテストケース. |
---|
152 | * |
---|
153 | * 絶対パス |
---|
154 | */ |
---|
155 | function testGetLocationWithFullPath() { |
---|
156 | $objPage = new LC_Page(); |
---|
157 | $_SERVER['DOCUMENT_ROOT'] = realpath("../html"); |
---|
158 | $url = $objPage->getLocation(URL_DIR . 'abouts/index.php'); |
---|
159 | |
---|
160 | $this->assertEquals(SITE_URL . "abouts/index.php", $url); |
---|
161 | unset($_SERVER['DOCUMENT_ROOT']); |
---|
162 | } |
---|
163 | |
---|
164 | /** |
---|
165 | * LC_Page::getLocation() のテストケース. |
---|
166 | * |
---|
167 | * QueryString 付与 |
---|
168 | */ |
---|
169 | function testGetLocationWithQueryString() { |
---|
170 | $objPage = new LC_Page(); |
---|
171 | $_SERVER['DOCUMENT_ROOT'] = realpath("../html"); |
---|
172 | |
---|
173 | $queryString = array("mode" => "update", "type" => "text"); |
---|
174 | $url = $objPage->getLocation("../html/abouts/index.php", $queryString); |
---|
175 | |
---|
176 | $this->assertEquals(SITE_URL . "abouts/index.php?mode=update&type=text", $url); |
---|
177 | unset($_SERVER['DOCUMENT_ROOT']); |
---|
178 | } |
---|
179 | |
---|
180 | /** |
---|
181 | * LC_Page::getLocation() のテストケース. |
---|
182 | * |
---|
183 | * SSL_URL 使用 |
---|
184 | */ |
---|
185 | function testGetLocationUseSSL() { |
---|
186 | $objPage = new LC_Page(); |
---|
187 | $_SERVER['DOCUMENT_ROOT'] = realpath("../html"); |
---|
188 | |
---|
189 | $queryString = array("mode" => "update", "type" => "text"); |
---|
190 | $url = $objPage->getLocation("../html/abouts/index.php", $queryString, true); |
---|
191 | |
---|
192 | $this->assertEquals(SSL_URL . "abouts/index.php?mode=update&type=text", $url); |
---|
193 | unset($_SERVER['DOCUMENT_ROOT']); |
---|
194 | } |
---|
195 | |
---|
196 | /** |
---|
197 | * LC_Page::getLocation() のテストケース. |
---|
198 | * |
---|
199 | * DocumentRoot 指定 |
---|
200 | */ |
---|
201 | function testGetLocationWithDocumentRoot() { |
---|
202 | $objPage = new LC_Page(); |
---|
203 | $documentRoot = realpath("../html"); |
---|
204 | |
---|
205 | $queryString = array("mode" => "update", "type" => "text"); |
---|
206 | $url = $objPage->getLocation("../html/abouts/index.php", array(), |
---|
207 | false, $documentRoot); |
---|
208 | |
---|
209 | $this->assertEquals(SITE_URL . "abouts/index.php", $url); |
---|
210 | } |
---|
211 | } |
---|
212 | ?> |
---|