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

Revision 22204, 5.8 KB checked in by shift_hiroko.tamagawa, 8 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-2012 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::registerOrder()のテストクラス.
29 *
30 *
31 * @author Hiroko Tamagawa
32 * @version $Id$
33 */
34class SC_Helper_Purchase_registerOrderTest extends SC_Helper_Purchase_TestBase {
35
36  private $helper;
37
38  protected function setUp() {
39    parent::setUp();
40    $this->setUpOrder();
41    $this->helper = new SC_Helper_Purchase_registerOrderMock();
42  }
43
44  protected function tearDown() {
45    parent::tearDown();
46  }
47
48  /////////////////////////////////////////
49  public function testRegisterOrder_既に受注IDが存在する場合_情報が更新される() {
50    $order_id = '1001';
51    $arrParams = array(
52      'status' => '1',
53      'add_point' => 10,
54      'use_point' => 20,
55      'order_name01' => '受注情報01_更新'
56    );
57
58    $this->helper->registerOrder($order_id, $arrParams);
59
60    $this->expected = array(
61      'sfUpdateOrderStatus' => array(
62        'order_id' => '1001',
63        'status' => '1',
64        'add_point' => 10,
65        'use_point' => 20
66      ),
67      'sfUpdateOrderNameCol' => '1001',
68      'count' => '2',
69      'content' => array(
70        'order_id' => '1001',
71        'customer_id' => '1001',
72        'status' => '1',
73        'add_point' => '10',
74        'use_point' => '20',
75        'order_name01' => '受注情報01_更新'
76      )
77    );
78    $this->actual = $_SESSION['testResult'];
79    $this->actual['count'] = $this->objQuery->count('dtb_order');
80    $result = $this->objQuery->select(
81      'order_id, customer_id, status, order_name01, add_point, use_point',
82      'dtb_order',
83      'order_id = ?',
84      array($order_id)
85    );
86    $this->actual['content'] = $result[0];
87
88    $this->verify();
89  }
90
91  public function testRegisterOrder_存在しない受注IDを指定した場合_新規に登録される() {
92    $order_id = '1003';
93    $arrParams = array(
94      'customer_id' => '1003',
95      'status' => '2',
96      'add_point' => 100,
97      'use_point' => 200,
98      'order_name01' => '受注情報03'
99    );
100
101    $this->helper->registerOrder($order_id, $arrParams);
102
103    $this->expected = array(
104      'sfUpdateOrderStatus' => array(
105        'order_id' => '1003',
106        'status' => '2',
107        'add_point' => 100,
108        'use_point' => 200
109      ),
110      'sfUpdateOrderNameCol' => '1003',
111      'count' => '3',
112      'content' => array(
113        'order_id' => '1003',
114        'customer_id' => '1003',
115        'status' => null,         // ここではsfUpdateOrderStatusをモックにしているので更新されない
116        'add_point' => '100',
117        'use_point' => '200',
118        'order_name01' => '受注情報03'
119      )
120    );
121    $this->actual = $_SESSION['testResult'];
122    $this->actual['count'] = $this->objQuery->count('dtb_order');
123    $result = $this->objQuery->select(
124      'order_id, customer_id, status, order_name01, add_point, use_point',
125      'dtb_order',
126      'order_id = ?',
127      array($order_id)
128    );
129    $this->actual['content'] = $result[0];
130
131    $this->verify();
132  }
133
134  public function testRegisterOrder_受注IDが未指定の場合_新たにIDが発行される() {
135    $order_id = '';
136    $arrParams = array( // 顧客IDも未指定
137      'status' => '2',
138      'add_point' => 100,
139      'use_point' => 200,
140      'order_name01' => '受注情報03'
141    );
142
143    // SEQの値を取得
144    $new_order_id = $this->helper->getNextOrderID() + 1;
145
146    $this->helper->registerOrder($order_id, $arrParams);
147
148    $this->expected = array(
149      'sfUpdateOrderStatus' => array(
150        'order_id' => $new_order_id,
151        'status' => '2',
152        'add_point' => 100,
153        'use_point' => 200
154      ),
155      'sfUpdateOrderNameCol' => $new_order_id,
156      'count' => '3',
157      'content' => array(
158        'order_id' => $new_order_id,
159        'customer_id' => '0',
160        'status' => null,         // ここではsfUpdateOrderStatusをモックにしているので更新されない
161        'add_point' => '100',
162        'use_point' => '200',
163        'order_name01' => '受注情報03'
164      )
165    );
166    $this->actual = $_SESSION['testResult'];
167    $this->actual['count'] = $this->objQuery->count('dtb_order');
168    $result = $this->objQuery->select(
169      'order_id, customer_id, status, order_name01, add_point, use_point',
170      'dtb_order',
171      'order_id = ?',
172      array($new_order_id)
173    );
174    $this->actual['content'] = $result[0];
175
176    $this->verify();
177
178  }
179
180  //////////////////////////////////////////
181
182}
183
184class SC_Helper_Purchase_registerOrderMock extends SC_Helper_Purchase {
185  function sfUpdateOrderStatus($order_id, $status, $add_point, $use_point, $values) {
186    $_SESSION['testResult']['sfUpdateOrderStatus'] = array(
187      'order_id' => $order_id,
188      'status' => $status,
189      'add_point' => $add_point,
190      'use_point' => $use_point,
191    );
192  }
193
194  function sfUpdateOrderNameCol($order_id) {
195   $_SESSION['testResult']['sfUpdateOrderNameCol'] = $order_id;
196  }
197}
198
Note: See TracBrowser for help on using the repository browser.