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

Revision 22252, 5.4 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::completeOrder()のテストクラス.
29 *
30 *
31 * @author Hiroko Tamagawa
32 * @version $Id$
33 */
34class SC_Helper_Purchase_completeOrderTest extends SC_Helper_Purchase_TestBase {
35
36  private $helper;
37
38  protected function setUp() {
39    parent::setUp();
40    $this->setUpOrderTemp(); // order_temp_id = '1001'
41    $this->setUpShipping();
42    $this->setUpCustomer();
43
44    $_SESSION['cartKey'] = '1';
45    $_SESSION['site'] = array(
46      'pre_page' => 'pre',
47      'now_page' => 'now',
48      'regist_success' => TRUE,
49      'uniqid' => '1001'
50    );
51
52    $this->helper = new SC_Helper_Purchase_completeOrderMock();
53  }
54
55  protected function tearDown() {
56    parent::tearDown();
57  }
58
59  /////////////////////////////////////////
60  // 適切なfunctionが呼ばれていることのみ確認
61  public function testCompleteOrder_顧客IDが指定されている場合_購入日が更新される() {
62    $_SESSION['customer']['customer_id'] = '1002'; // 顧客ID
63    $this->helper->completeOrder(ORDER_DELIV);
64
65    $this->expected = array(
66      'verifyChangeCart' => array(
67        'uniqId' => '1001'
68      ),
69      'getOrderTemp' => array(
70        'uniqId' => '1001'
71      ),
72      'registerOrderComplete' => array(
73        'order_temp_id' => '1001',
74        'status' => ORDER_DELIV,
75        'cartKey' => '1'
76      ),
77      'registerShipmentItem' => array(
78        array(
79          'order_id' => '1001',
80          'shipping_id' => '00001',
81          'shipment_item' => '商品1'
82        )
83      ),
84      'registerShipping' => array(
85        'order_id' => '1001'
86      ),
87      'cleanupSession' => array(
88        'order_id' => '1001',
89        'cartKey' => '1'
90      )
91    );
92    $this->actual = $_SESSION['testResult'];
93    $this->verify('適切なfunctionが呼ばれている');
94    $last_buy_date = $this->objQuery->get('last_buy_date', 'dtb_customer', 'customer_id = ?', '1002');
95    // TODO Jenkins上でテストに失敗するため、デバッグ用コードを挿入
96    var_dump($this->objQuery->select('*', 'dtb_customer', '', array()));
97    $this->assertNotNull($last_buy_date, '最終購入日');
98  }
99
100  public function testCompleteOrder_顧客IDが指定されていない場合_特にエラーなく修了できる() {
101    $this->helper->completeOrder(); // デフォルトのステータス(NEW)
102
103    $this->expected = array(
104      'verifyChangeCart' => array(
105        'uniqId' => '1001'
106      ),
107      'getOrderTemp' => array(
108        'uniqId' => '1001'
109      ),
110      'registerOrderComplete' => array(
111        'order_temp_id' => '1001',
112        'status' => ORDER_NEW,
113        'cartKey' => '1'
114      ),
115      'registerShipmentItem' => array(
116        array(
117          'order_id' => '1001',
118          'shipping_id' => '00001',
119          'shipment_item' => '商品1'
120        )
121      ),
122      'registerShipping' => array(
123        'order_id' => '1001'
124      ),
125      'cleanupSession' => array(
126        'order_id' => '1001',
127        'cartKey' => '1'
128      )
129    );
130    $this->actual = $_SESSION['testResult'];
131    $this->verify('適切なfunctionが呼ばれている');
132  }
133
134  //////////////////////////////////////////
135
136}
137
138class SC_Helper_Purchase_completeOrderMock extends SC_Helper_Purchase{
139
140  function verifyChangeCart($uniqId, $objCartSession){
141    $_SESSION['testResult']['verifyChangeCart'] = array('uniqId'=>$uniqId);
142  }
143
144  function getOrderTemp($uniqId) {
145    $_SESSION['testResult']['getOrderTemp'] = array('uniqId'=>$uniqId);
146    return parent::getOrderTemp($uniqId);
147  }
148
149  function registerOrderComplete($orderTemp, $objCartSession, $cartKey) {
150    $_SESSION['testResult']['registerOrderComplete'] = array(
151      'order_temp_id' => $orderTemp['order_temp_id'],
152      'status' => $orderTemp['status'],
153      'cartKey' => $cartKey
154    );
155    return parent::registerOrderComplete($orderTemp, $objCartSession, $cartKey);
156  }
157
158  function registerShipmentItem($order_id, $shipping_id, $shipment_item) {
159    $_SESSION['testResult']['registerShipmentItem'][] = array(
160      'order_id' => $order_id,
161      'shipping_id' => $shipping_id,
162      'shipment_item' => $shipment_item
163    );
164  }
165
166  function registerShipping($order_id, $shipping_temp) {
167    $_SESSION['testResult']['registerShipping'] = array(
168      'order_id' => $order_id
169    );
170  }
171
172  function cleanupSession($order_id, $objCartSesion, $objCustomer, $cartKey) {
173    $_SESSION['testResult']['cleanupSession'] = array(
174      'order_id' => $order_id,
175      'cartKey' => $cartKey
176    );
177  }
178
179}
180
181?>
182
Note: See TracBrowser for help on using the repository browser.