source: branches/version-2_12-dev/test/class/helper/SC_Helper_Session_Test.php @ 22567

Revision 22567, 3.7 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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