Warning: Can't use blame annotator:
svn blame failed on branches/version-2_5-dev/test/class/page/LC_Page_Test.php: バイナリファイル 'file:///home/svn/open/branches/version-2_5-dev/test/class/page/LC_Page_Test.php' に対しては blame で各行の最終変更者を計算できません 195004

source: branches/version-2_5-dev/test/class/page/LC_Page_Test.php @ 18763

Revision 18763, 6.1 KB checked in by nanasess, 14 years ago (diff)
  • MDB2に対応(#564)
    • r18755 のパッチをマージ
    • PEAR::DB を削除
    • 暫定的にインストーラを修正
    • PHPUnit/Framework.php を直接 require するための require.php を追加
    • カレントディレクトリでのテストケース実行をサポート
    • 実装に合わせて README.txt を修正
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
RevLine 
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(realpath(dirname(__FILE__)) . '/../../require.php');
26require_once(realpath(dirname(__FILE__)) . '/../../../data/class/pages/LC_Page.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_Framework_TestCase {
36
37    // }}}
38    // {{{ functions
39
40    /*
41     * FIXME LC_Page::sendRedirect() は, リダイレクトしてしまうため,
42     *       PHPUnit3 ではテストできない...
43     */
44
45    /**
46     * LC_Page::sendRedirect() のテストケース(エラー).
47     */
48    /*
49    function testSendRedirect() {
50        $objPage = new LC_Page();
51        $result = $objPage->sendRedirect(SITE_URL);
52
53        $this->assertEquals(true, empty($result));
54    }
55    */
56    /**
57     * LC_Page::sendRedirect() のテストケース(エラー).
58     */
59    /*
60    function testSendRedirectIsFailed() {
61        $objPage = new LC_Page();
62        $result = $objPage->sendRedirect("http://www.example.org");
63
64        $this->assertEquals(false, $result);
65    }
66    */
67
68    /**
69     * LC_Page::getToken() のテストケース.
70     */
71    function testGetToken() {
72        $objPage = new LC_Page();
73
74        $token = $objPage->getToken();
75
76        // 40文字の16進数
77        $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", $token));
78
79        // セッションに文字列が格納されているか
80        $this->assertEquals($token, $_SESSION[TRANSACTION_ID_NAME]);
81    }
82
83    /**
84     * LC_Page::isValidToken() のテストケース(POST).
85     */
86    function testIsValidToken() {
87        $objPage = new LC_Page();
88
89        $token = $objPage->getToken();
90
91        // POST でトークンを渡す.
92        $_POST[TRANSACTION_ID_NAME] = $token;
93
94        $this->assertEquals(true, $objPage->isValidToken());
95        unset($_POST[TRANSACTION_ID_NAME]);
96    }
97
98    /**
99     * LC_Page::isValidToken() のテストケース(GET).
100     */
101    function testIsValidTokenWithGET() {
102        $objPage = new LC_Page();
103
104        $token = $objPage->getToken();
105
106        // GET でトークンを渡す.
107        $_GET[TRANSACTION_ID_NAME] = $token;
108
109        $this->assertEquals(true, $objPage->isValidToken());
110        unset($_GET[TRANSACTION_ID_NAME]);
111    }
112
113
114    /**
115     * LC_Page::isValidToken() のテストケース(エラー).
116     *
117     * 値が渡されてない場合
118     */
119    function testIsValidTokenNotParam() {
120
121        $objPage = new LC_Page();
122
123        $token = $objPage->getToken();
124
125        // 値を渡さなければ falsel
126        $this->assertEquals(false, $objPage->isValidToken());
127    }
128
129    /**
130     * LC_Page::createToken() のテストケース.
131     */
132    function testCreateToken() {
133        // 40文字の16進数
134        $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", LC_Page::createToken()));
135    }
136
137    /**
138     * LC_Page::getLocation() のテストケース.
139     */
140    function testGetLocation() {
141        $objPage = new LC_Page();
142        $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
143        $url = $objPage->getLocation("/abouts/index.php");
144
145        $this->assertEquals(SITE_URL . "abouts/index.php", $url);
146        unset($_SERVER['DOCUMENT_ROOT']);
147    }
148
149    /**
150     * LC_Page::getLocation() のテストケース.
151     *
152     * 絶対パス
153     */
154    function testGetLocationWithFullPath() {
155        $objPage = new LC_Page();
156        $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
157        $url = $objPage->getLocation(URL_DIR . 'abouts/index.php');
158
159        $this->assertEquals(SITE_URL . "abouts/index.php", $url);
160        unset($_SERVER['DOCUMENT_ROOT']);
161    }
162
163    /**
164     * LC_Page::getLocation() のテストケース.
165     *
166     * QueryString 付与
167     */
168    function testGetLocationWithQueryString() {
169        $objPage = new LC_Page();
170        $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
171
172        $queryString = array("mode" => "update", "type" => "text");
173        $url = $objPage->getLocation("/abouts/index.php", $queryString);
174
175        $this->assertEquals(SITE_URL . "abouts/index.php?mode=update&type=text", $url);
176        unset($_SERVER['DOCUMENT_ROOT']);
177    }
178
179    /**
180     * LC_Page::getLocation() のテストケース.
181     *
182     * SSL_URL 使用
183     */
184    function testGetLocationUseSSL() {
185        $objPage = new LC_Page();
186        $_SERVER['DOCUMENT_ROOT'] = realpath(dirname(__FILE__) . "/../../../html");
187
188        $queryString = array("mode" => "update", "type" => "text");
189        $url = $objPage->getLocation("/abouts/index.php", $queryString, true);
190
191        $this->assertEquals(SSL_URL . "abouts/index.php?mode=update&type=text", $url);
192        unset($_SERVER['DOCUMENT_ROOT']);
193    }
194
195    /**
196     * LC_Page::getLocation() のテストケース.
197     *
198     * DocumentRoot 指定
199     */
200    function testGetLocationWithDocumentRoot() {
201        $objPage = new LC_Page();
202        $documentRoot = realpath(dirname(__FILE__) . "/../../../html");
203
204        $queryString = array("mode" => "update", "type" => "text");
205        $url = $objPage->getLocation("/abouts/index.php", array(),
206                                     false, $documentRoot);
207
208        $this->assertEquals(SITE_URL . "abouts/index.php", $url);
209    }
210}
211?>
Note: See TracBrowser for help on using the repository browser.