source: branches/version-2_4/test/class/page/LC_Page_Test.php @ 18734

Revision 18734, 5.8 KB checked in by nanasess, 11 years ago (diff)

Copyright の更新(#601)

  • Property svn:keywords set to Id Revision Date
  • 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-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
25require_once(CLASS_PATH . "pages/LC_Page.php");
26require_once("PHPUnit/TestCase.php");
27
28/**
29 * LC_Page のテストケース.
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 LC_Page_Test extends PHPUnit_TestCase {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * LC_Page::sendRedirect() のテストケース(エラー).
42     */
43    function testSendRedirect() {
44        $objPage = new LC_Page();
45        $result = $objPage->sendRedirect(SITE_URL);
46
47        $this->assertEquals(true, empty($result));
48    }
49
50    /**
51     * LC_Page::sendRedirect() のテストケース(エラー).
52     */
53    function testSendRedirectIsFailed() {
54        $objPage = new LC_Page();
55        $result = $objPage->sendRedirect("http://www.example.org");
56
57        $this->assertEquals(false, $result);
58    }
59
60    /**
61     * LC_Page::getToken() のテストケース.
62     */
63    function testGetToken() {
64        $objPage = new LC_Page();
65
66        $token = $objPage->getToken();
67
68        // 40文字の16進数
69        $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", $token));
70
71        // セッションに文字列が格納されているか
72        $this->assertEquals($token, $_SESSION[TRANSACTION_ID_NAME]);
73    }
74
75    /**
76     * LC_Page::isValidToken() のテストケース(POST).
77     */
78    function testIsValidToken() {
79        $objPage = new LC_Page();
80
81        $token = $objPage->getToken();
82
83        // POST でトークンを渡す.
84        $_POST[TRANSACTION_ID_NAME] = $token;
85
86        $this->assertEquals(true, $objPage->isValidToken());
87        unset($_POST[TRANSACTION_ID_NAME]);
88    }
89
90    /**
91     * LC_Page::isValidToken() のテストケース(GET).
92     */
93    function testIsValidTokenWithGET() {
94        $objPage = new LC_Page();
95
96        $token = $objPage->getToken();
97
98        // GET でトークンを渡す.
99        $_GET[TRANSACTION_ID_NAME] = $token;
100
101        $this->assertEquals(true, $objPage->isValidToken());
102        unset($_GET[TRANSACTION_ID_NAME]);
103    }
104
105
106    /**
107     * LC_Page::isValidToken() のテストケース(エラー).
108     *
109     * 値が渡されてない場合
110     */
111    function testIsValidTokenNotParam() {
112
113        $objPage = new LC_Page();
114
115        $token = $objPage->getToken();
116
117        // 値を渡さなければ falsel
118        $this->assertEquals(false, $objPage->isValidToken());
119    }
120
121    /**
122     * LC_Page::createToken() のテストケース.
123     */
124    function testCreateToken() {
125        // 40文字の16進数
126        $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", LC_Page::createToken()));
127    }
128
129    /**
130     * LC_Page::getLocation() のテストケース.
131     */
132    function testGetLocation() {
133        $objPage = new LC_Page();
134        $_SERVER['DOCUMENT_ROOT'] = realpath("../../../html");
135        $url = $objPage->getLocation("../../../html/abouts/index.php");
136
137        $this->assertEquals(SITE_URL . "abouts/index.php", $url);
138        unset($_SERVER['DOCUMENT_ROOT']);
139    }
140
141    /**
142     * LC_Page::getLocation() のテストケース.
143     *
144     * 絶対パス
145     */
146    function testGetLocationWithFullPath() {
147        $objPage = new LC_Page();
148        $_SERVER['DOCUMENT_ROOT'] = realpath("../html");
149        $url = $objPage->getLocation("/abouts/index.php");
150
151        $this->assertEquals(SITE_URL . "abouts/index.php", $url);
152        unset($_SERVER['DOCUMENT_ROOT']);
153    }
154
155    /**
156     * LC_Page::getLocation() のテストケース.
157     *
158     * QueryString 付与
159     */
160    function testGetLocationWithQueryString() {
161        $objPage = new LC_Page();
162        $_SERVER['DOCUMENT_ROOT'] = realpath("../../../html");
163
164        $queryString = array("mode" => "update", "type" => "text");
165        $url = $objPage->getLocation("../../../html/abouts/index.php", $queryString);
166
167        $this->assertEquals(SITE_URL . "abouts/index.php?mode=update&type=text", $url);
168        unset($_SERVER['DOCUMENT_ROOT']);
169    }
170
171    /**
172     * LC_Page::getLocation() のテストケース.
173     *
174     * SSL_URL 使用
175     */
176    function testGetLocationUseSSL() {
177        $objPage = new LC_Page();
178        $_SERVER['DOCUMENT_ROOT'] = realpath("../../../html");
179
180        $queryString = array("mode" => "update", "type" => "text");
181        $url = $objPage->getLocation("../../../html/abouts/index.php", $queryString, true);
182
183        $this->assertEquals(SSL_URL . "abouts/index.php?mode=update&type=text", $url);
184        unset($_SERVER['DOCUMENT_ROOT']);
185    }
186
187    /**
188     * LC_Page::getLocation() のテストケース.
189     *
190     * DocumentRoot 指定
191     */
192    function testGetLocationWithDocumentRoot() {
193        $objPage = new LC_Page();
194        $documentRoot = realpath("../../../html");
195
196        $queryString = array("mode" => "update", "type" => "text");
197        $url = $objPage->getLocation("../../../html/abouts/index.php", array(),
198                                     false, $documentRoot);
199
200        $this->assertEquals(SITE_URL . "abouts/index.php", $url);
201    }
202}
203?>
Note: See TracBrowser for help on using the repository browser.