source: branches/feature-module-update/test/class/page/LC_Page_Test.php @ 15213

Revision 15213, 5.0 KB checked in by nanasess, 17 years ago (diff)

LC_Page::getLocation() の $path が絶対パスの場合に対応

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