source: branches/version-2_12-dev/tests/class/helper/SC_Helper_Purchase/SC_Helper_Purchase_cancelOrderTest.php @ 22247

Revision 22247, 4.7 KB checked in by shift_hiroko.tamagawa, 9 years ago (diff)

#1978 SC_Helper_Purchaseクラスのテスト追加

  • Property svn:keywords set to Id Rev Date
Line 
1<?php
2
3$HOME = realpath(dirname(__FILE__)) . "/../../../..";
4require_once($HOME . "/tests/class/helper/SC_Helper_Purchase/SC_Helper_Purchase_TestBase.php");
5/*
6 * This file is part of EC-CUBE
7 *
8 * Copyright(c) 2000-2013 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_Helper_Purchase::cancelOrder()のテストクラス.
29 *
30 * @author Hiroko Tamagawa
31 * @version $Id$
32 */
33class SC_Helper_Purchase_cancelOrderTest extends SC_Helper_Purchase_TestBase {
34
35  private $helper;
36
37  protected function setUp() {
38    parent::setUp();
39
40    $this->helper = new SC_Helper_Purchase_cancelOrderMock();
41  }
42
43  protected function tearDown() {
44    parent::tearDown();
45  }
46
47  /////////////////////////////////////////
48  public function testCancelOrder_デフォルトの引数で呼び出した場合_製品クラスのデータが更新される(){
49    $order_id = '1001';
50    $this->objQuery->begin();
51
52    $this->helper->cancelOrder($order_id);
53
54    $this->actual['testResult'] = $_SESSION['testResult'];
55    $this->actual['productClass'] = $this->objQuery->select(
56      'stock', 'dtb_products_class',
57      'product_class_id = ?', array('1001')
58    );
59    $this->expected = array(
60      'testResult' => array(
61        'registerOrder' => array(
62          'order_id' => '1001',
63          'params' => array(
64            'status' => ORDER_CANCEL
65          )
66        ),
67        'getOrderDetail' => array(
68          'order_id' => '1001'
69        )
70      ),
71      'productClass' => array(
72        array('stock') => '105',
73        array('stock') => '51'
74      )
75    );
76
77    $this->verify();
78  }
79
80  // 実際にトランザクションを開始したかどうかはテストできないが、
81  // 問題なく処理が完了することのみ確認
82  public function testCancelOrder_トランザクションが開始していない場合_内部で開始する(){
83    $order_id = '1001';
84
85    $this->helper->cancelOrder($order_id, ORDER_NEW);
86
87    $this->actual['testResult'] = $_SESSION['testResult'];
88    $this->actual['productClass'] = $this->objQuery->select(
89      'stock', 'dtb_products_class',
90      'product_class_id = ?', array('1001')
91    );
92    $this->expected = array(
93      'testResult' => array(
94        'registerOrder' => array(
95          'order_id' => '1001',
96          'params' => array(
97            'status' => ORDER_NEW
98          )
99        ),
100        'getOrderDetail' => array(
101          'order_id' => '1001'
102        )
103      ),
104      'productClass' => array(
105        array('stock') => '105',
106        array('stock') => '51'
107      )
108    );
109
110    $this->verify();
111  }
112
113  public function testCancelOrder_削除フラグが立っている場合_DB更新時に削除フラグが立てられる(){
114    $order_id = '1001';
115    $this->objQuery->begin();
116
117    $this->helper->cancelOrder($order_id, ORDER_DELIV, true);
118
119    $this->actual['testResult'] = $_SESSION['testResult'];
120    $this->actual['productClass'] = $this->objQuery->select(
121      'stock', 'dtb_products_class',
122      'product_class_id = ?', array('1001')
123    );
124    $this->expected = array(
125      'testResult' => array(
126        'registerOrder' => array(
127          'order_id' => '1001',
128          'params' => array(
129            'status' => ORDER_DELIV,
130            'del_flg' => '1'
131          )
132        ),
133        'getOrderDetail' => array(
134          'order_id' => '1001'
135        )
136      ),
137      'productClass' => array(
138        array('stock') => '105',
139        array('stock') => '51'
140      )
141    );
142
143    $this->verify();
144  }
145
146  //////////////////////////////////////////
147
148}
149
150class SC_Helper_Purchase_cancelOrderMock extends SC_Helper_Purchase {
151
152  function registerOrder($order_id, $params) {
153    $_SESSION['testResult']['registerOrder'] = array(
154      'order_id' => $order_id,
155      'params' => $params
156    );
157  }
158
159  function getOrderDetail($order_id) {
160    $_SESSION['testResult']['getOrderDetail'] = array(
161      'order_id' => $order_id
162    );
163
164    return array(
165      array(
166        'product_class_id' => '1001',
167        'quantity' => '5'
168      ),
169      array(
170        'product_class_id' => '1002',
171        'quantity' => '1'
172      )
173    );
174  }
175}
176
177
Note: See TracBrowser for help on using the repository browser.