source: branches/version-2_11-dev/test/class/helper/SC_Helper_Session_Test.php @ 21016

Revision 21016, 3.7 KB checked in by habu, 13 years ago (diff)

#1394(会員住所以外のお届け先を指定しても情報が反映されない)

  • Property svn:keywords set to Id
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 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_extends/helper_extends/SC_Helper_Session_Ex.php");
27
28/**
29 * SC_Helper_Session のテストケース.
30 *
31 * @package Helper
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class SC_Helper_Session_Test extends PHPUnit_Framework_TestCase {
36
37    /**
38     * getToken() のテストケース.
39     */
40    function testGetToken() {
41        $objSession = new SC_Helper_Session_Ex();
42        $token = $objSession->getToken();
43       
44        // 40文字の16進数
45        $this->assertEquals(1, preg_match("/[a-f0-9]{40,}/", $token));
46       
47        // セッションに文字列が格納されているか
48        $this->assertEquals($token, $_SESSION[TRANSACTION_ID_NAME]);
49    }
50    /**
51     * isValidToken() のテストケース.
52     */
53    function testIsValidToken() {
54        $objSession = new SC_Helper_Session_Ex();
55        $token = $objSession->getToken();
56       
57        // POST でトークンを渡す.
58        $_REQUEST[TRANSACTION_ID_NAME] = $token;
59       
60        $this->assertEquals(true, $objSession->isValidToken());
61        unset($_REQUEST[TRANSACTION_ID_NAME]);
62    }
63
64    /**
65     * isValidToken() のテストケース(POST).
66     */
67    function testIsValidTokenWithPost() {
68        $objSession = new SC_Helper_Session_Ex();
69        $token = $objSession->getToken();
70       
71        // POST でトークンを渡す.
72        $_POST[TRANSACTION_ID_NAME] = $token;
73       
74        // FIXME: PHPUnitでの実行時は、$_POSTの内容が$_REQUESTに統合されないためコメントアウトしています。テストを記述する良い方法があれば変更してください
75        // $this->assertEquals(true, $objSession->isValidToken());
76        unset($_POST[TRANSACTION_ID_NAME]);
77    }
78
79    /**
80     * isValidToken() のテストケース(GET).
81     */
82    function testIsValidTokenWithGET() {
83        $objSession = new SC_Helper_Session_Ex();
84        $token = $objSession->getToken();
85       
86        // GET でトークンを渡す.
87        $_GET[TRANSACTION_ID_NAME] = $token;
88       
89        // FIXME: PHPUnitでの実行時は、$_GETの内容が$_REQUESTに統合されないためコメントアウトしています。テストを記述する良い方法があれば変更してください
90        // $this->assertEquals(true, $objSession->isValidToken());
91        unset($_GET[TRANSACTION_ID_NAME]);
92    }
93
94    /**
95     * isValidToken() のテストケース(エラー).
96     *
97     * 値が渡されてない場合
98     */
99    function testIsValidTokenNotParam() {
100        $objSession = new SC_Helper_Session_Ex();
101        $token = $objSession->getToken();
102       
103        // 値を渡さなければ false
104        $this->assertEquals(false, $objSession->isValidToken());
105    }
106}
107?>
Note: See TracBrowser for help on using the repository browser.