| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | $HOME = realpath(dirname(__FILE__)) . "/../../../.."; |
|---|
| 4 | require_once($HOME . "/tests/class/Common_TestCase.php"); |
|---|
| 5 | /* |
|---|
| 6 | * This file is part of EC-CUBE |
|---|
| 7 | * |
|---|
| 8 | * Copyright(c) 2000-2014 LOCKON CO.,LTD. All Rights Reserved. |
|---|
| 9 | * |
|---|
| 10 | * http://www.lockon.co.jp/ |
|---|
| 11 | * |
|---|
| 12 | * This program is free software; you can redistribute it and/or |
|---|
| 13 | * modify it under the terms of the GNU General Public License |
|---|
| 14 | * as published by the Free Software Foundation; either version 2 |
|---|
| 15 | * of the License, or (at your option) any later version. |
|---|
| 16 | * |
|---|
| 17 | * This program is distributed in the hope that it will be useful, |
|---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 20 | * GNU General Public License for more details. |
|---|
| 21 | * |
|---|
| 22 | * You should have received a copy of the GNU General Public License |
|---|
| 23 | * along with this program; if not, write to the Free Software |
|---|
| 24 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 25 | */ |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * SC_Utils::sfIsSuccess()のテストクラス. |
|---|
| 29 | * TODO exitするケースはテスト不可 |
|---|
| 30 | * TODO HTTPSのケースは未テスト(config.phpでhttpsのURLが指定されていないため) |
|---|
| 31 | * @author Hiroko Tamagawa |
|---|
| 32 | * @version $Id$ |
|---|
| 33 | */ |
|---|
| 34 | class SC_Utils_sfIsSuccessTest extends Common_TestCase |
|---|
| 35 | { |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | protected function setUp() |
|---|
| 39 | { |
|---|
| 40 | // parent::setUp(); |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | protected function tearDown() |
|---|
| 44 | { |
|---|
| 45 | // parent::tearDown(); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | ///////////////////////////////////////// |
|---|
| 49 | public function testSfIsSuccess_認証に失敗している場合_falseが返る() |
|---|
| 50 | { |
|---|
| 51 | $objSess = new SC_Session_Mock(); |
|---|
| 52 | $objSess->is_success = SUCCESS + 1; |
|---|
| 53 | |
|---|
| 54 | $this->expected = FALSE; |
|---|
| 55 | $this->actual = SC_Utils::sfIsSuccess($objSess, FALSE); |
|---|
| 56 | |
|---|
| 57 | $this->verify('認証可否'); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | public function testSfIsSuccess_認証成功でリファラがない場合_trueが返る() |
|---|
| 61 | { |
|---|
| 62 | $objSess = new SC_Session_Mock(); |
|---|
| 63 | $objSess->is_success = SUCCESS; |
|---|
| 64 | |
|---|
| 65 | $this->expected = TRUE; |
|---|
| 66 | $this->actual = SC_Utils::sfIsSuccess($objSess); |
|---|
| 67 | |
|---|
| 68 | $this->verify('認証可否'); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | // TODO 正規のドメインであることは確認しているが、管理画面からというのはチェックしていないのでは? |
|---|
| 72 | public function testSfIsSuccess_認証成功でリファラが正しい場合_trueが返る() |
|---|
| 73 | { |
|---|
| 74 | $objSess = new SC_Session_Mock(); |
|---|
| 75 | $objSess->is_success = SUCCESS; |
|---|
| 76 | $_SERVER['HTTP_REFERER'] = HTTP_URL . 'hoge/fuga'; |
|---|
| 77 | |
|---|
| 78 | $this->expected = TRUE; |
|---|
| 79 | $this->actual = SC_Utils::sfIsSuccess($objSess, FALSE); |
|---|
| 80 | |
|---|
| 81 | $this->verify('認証可否'); |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | public function testSfIsSuccess_認証成功でリファラが不正な場合_falseが返る() |
|---|
| 85 | { |
|---|
| 86 | $objSess = new SC_Session_Mock(); |
|---|
| 87 | $objSess->is_success = SUCCESS; |
|---|
| 88 | $_SERVER['HTTP_REFERER'] = 'http://test.jp.local/hoge/fuga'; |
|---|
| 89 | |
|---|
| 90 | $this->expected = FALSE; |
|---|
| 91 | $this->actual = SC_Utils::sfIsSuccess($objSess, FALSE); |
|---|
| 92 | |
|---|
| 93 | $this->verify('認証可否'); |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | ////////////////////////////////////////// |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | class SC_Session_Mock extends SC_Session |
|---|
| 100 | { |
|---|
| 101 | |
|---|
| 102 | public $is_success; |
|---|
| 103 | |
|---|
| 104 | function IsSuccess() |
|---|
| 105 | { |
|---|
| 106 | return $this->is_success; |
|---|
| 107 | } |
|---|
| 108 | } |
|---|
| 109 | |
|---|