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

Revision 22796, 13.2 KB checked in by h_yoshimoto, 11 years ago (diff)

#2236 2.12.3リリース以降の2.12-devへのコミット差し戻し

  • 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::sfUpdateOrderStatus()のテストクラス.
29 *
30 *
31 * @author Hiroko Tamagawa
32 * @version $Id$
33 */
34class SC_Helper_Purchase_sfUpdateOrderStatusTest extends SC_Helper_Purchase_TestBase {
35
36  private $helper;
37
38  protected function setUp() {
39    parent::setUp();
40    $this->setUpOrder();
41    $this->setUpCustomer();
42    $this->helper = new SC_Helper_Purchase_sfUpdateOrderStatusMock();
43  }
44
45  protected function tearDown() {
46    parent::tearDown();
47  }
48
49  /////////////////////////////////////////
50  // オプションの引数:対応状況、使用ポイント、加算ポイント
51  public function testSfUpdateOrderStatus_オプションの引数が未指定の場合_DBの値が引き継がれる() {
52    $order_id = '1001';
53    $old_update_date = $this->objQuery->get('update_date', 'dtb_order', 'order_id = ?', array($order_id));
54
55    $this->helper->usePoint = false;
56    $this->helper->addPoint = false;
57    $this->helper->sfUpdateOrderStatus($order_id); // 引数は最低限だけ指定
58
59    $this->expected = array(
60      'order' => array(
61        'status' => '3',
62        'add_point' => '20',
63        'use_point' => '10'
64      ),
65      'customer' => array(
66        'point' => '100'
67      )
68    );
69    $this->actual['order'] = array_shift($this->objQuery->select(
70      'status, use_point, add_point',
71      'dtb_order', 'order_id = ?', array($order_id)));
72    $this->actual['customer'] = array_shift($this->objQuery->select(
73      'point', 'dtb_customer', 'customer_id = ?', '1001'));
74
75    $this->verify();
76
77    $update_date = $this->objQuery->get('update_date', 'dtb_order', 'order_id = ?', array($order_id));
78    $this->assertTrue($update_date > $old_udpate_date, '受注情報が更新されている');
79  }
80
81  // TODO 定数を変更できないためテスト不可
82  /**
83  public function testSfUpdateOrderStatus_ポイント使用しない設定の場合_ポイントに関する処理が行われない() {
84
85
86    $this->verify();
87  }
88  */
89
90  public function testSfUpdateOrderStatus_対応状況が発送済みに変更された場合_発送日が更新される() {
91    $order_id = '1001';
92    $old_dates = $this->objQuery->select(
93      'update_date, commit_date, payment_date',
94      'dtb_order', 'order_id = ?', array($order_id));
95
96    $this->helper->usePoint = false;
97    $this->helper->addPoint = false;
98    $this->helper->sfUpdateOrderStatus($order_id, ORDER_DELIV, 50, 45);
99
100    $this->expected = array(
101      'order' => array(
102        'status' => ORDER_DELIV,
103        'add_point' => '50',  // 引数の設定どおりになる
104        'use_point' => '45' // 引数の設定どおりになる
105      ),
106      'customer' => array(
107        'point' => '100' // ポイントを使わない
108      )
109    );
110    $this->actual['order'] = array_shift($this->objQuery->select(
111      'status, use_point, add_point',
112      'dtb_order', 'order_id = ?', array($order_id)));
113    $this->actual['customer'] = array_shift($this->objQuery->select(
114      'point', 'dtb_customer', 'customer_id = ?', '1001'));
115
116    $this->verify();
117
118    $new_dates = $this->objQuery->select(
119      'update_date, commit_date, payment_date',
120      'dtb_order', 'order_id = ?', array($order_id));
121    $this->assertUpdate($new_dates, $old_dates, 'update_date', '受注情報'); 
122    $this->assertUpdate($new_dates, $old_dates, 'commit_date', '発送日'); 
123    $this->assertUpdate($new_dates, $old_dates, 'payment_date', '入金日', false); 
124  }
125
126  public function testSfUpdateOrderStatus_対応状況が入金済みに変更された場合_入金日が更新される() {
127    $order_id = '1002';
128    $old_dates = $this->objQuery->select(
129      'update_date, commit_date, payment_date',
130      'dtb_order', 'order_id = ?', array($order_id));
131
132    $this->helper->usePoint = false;
133    $this->helper->addPoint = false;
134    $this->helper->sfUpdateOrderStatus($order_id, ORDER_PRE_END, 50, 45);
135
136    $this->expected = array(
137      'order' => array(
138        'status' => ORDER_PRE_END,
139        'add_point' => '50',  // 引数の設定どおりになる
140        'use_point' => '45' // 引数の設定どおりになる
141      )
142    );
143    $this->actual['order'] = array_shift($this->objQuery->select(
144      'status, use_point, add_point',
145      'dtb_order', 'order_id = ?', array($order_id)));
146
147    $this->verify();
148
149    $new_dates = $this->objQuery->select(
150      'update_date, commit_date, payment_date',
151      'dtb_order', 'order_id = ?', array($order_id));
152    $this->assertUpdate($new_dates, $old_dates, 'update_date', '受注情報'); 
153    $this->assertUpdate($new_dates, $old_dates, 'commit_date', '発送日', false); 
154    $this->assertUpdate($new_dates, $old_dates, 'payment_date', '入金日'); 
155  }
156
157  public function testSfUpdateOrderStatus_変更前の対応状況が利用対象の場合_変更前の使用ポイントを戻す() {
158    $order_id = '1002';
159    $old_dates = $this->objQuery->select(
160      'update_date, commit_date, payment_date',
161      'dtb_order', 'order_id = ?', array($order_id));
162
163    $this->helper->addPoint = false; // 加算は強制的にfalseにしておく
164    $this->helper->sfUpdateOrderStatus($order_id, ORDER_CANCEL, 0, 45);
165
166    $this->expected = array(
167      'order' => array(
168        'status' => ORDER_CANCEL,
169        'add_point' => '0',  // 引数の設定どおりになる
170        'use_point' => '45' // 引数の設定どおりになる
171      ),
172      'customer' => array(
173        'point' => '210' // 元々200pt+10pt戻す
174      )
175    );
176    $this->actual['order'] = array_shift($this->objQuery->select(
177      'status, use_point, add_point',
178      'dtb_order', 'order_id = ?', array($order_id)));
179    $this->actual['customer'] = array_shift($this->objQuery->select(
180      'point', 'dtb_customer', 'customer_id = ?', array('1002')));
181
182    $this->verify();
183  }
184
185  public function testSfUpdateOrderStatus_変更後の対応状況が利用対象の場合_変更後の使用ポイントを引く() {
186    $order_id = '1001';
187    $old_dates = $this->objQuery->select(
188      'update_date, commit_date, payment_date',
189      'dtb_order', 'order_id = ?', array($order_id));
190
191    $this->helper->sfUpdateOrderStatus($order_id, ORDER_NEW, 50, 45);
192
193    $this->expected = array(
194      'order' => array(
195        'status' => ORDER_NEW,
196        'add_point' => '50',  // 引数の設定どおりになる
197        'use_point' => '45' // 引数の設定どおりになる
198      ),
199      'customer' => array(
200        'point' => '55' // 元々100pt→45pt引く
201      )
202    );
203    $this->actual['order'] = array_shift($this->objQuery->select(
204      'status, use_point, add_point',
205      'dtb_order', 'order_id = ?', array($order_id)));
206    $this->actual['customer'] = array_shift($this->objQuery->select(
207      'point', 'dtb_customer', 'customer_id = ?', array('1001')));
208
209    $this->verify();
210  }
211
212  public function testSfUpdateOrderStatus_変更前の対応状況が加算対象の場合_変更前の加算ポイントを戻す() {
213    $order_id = '1002';
214    $old_dates = $this->objQuery->select(
215      'update_date, commit_date, payment_date',
216      'dtb_order', 'order_id = ?', array($order_id));
217
218    $this->helper->usePoint = false; // 使用対象は強制的にfalseにしておく
219    $this->helper->sfUpdateOrderStatus($order_id, ORDER_CANCEL, 50, 45);
220
221    $this->expected = array(
222      'order' => array(
223        'status' => ORDER_CANCEL,
224        'add_point' => '50',  // 引数の設定どおりになる
225        'use_point' => '45' // 引数の設定どおりになる
226      ),
227      'customer' => array(
228        'point' => '180' // 元々200pt→20pt引く
229      )
230    );
231    $this->actual['order'] = array_shift($this->objQuery->select(
232      'status, use_point, add_point',
233      'dtb_order', 'order_id = ?', array($order_id)));
234    $this->actual['customer'] = array_shift($this->objQuery->select(
235      'point', 'dtb_customer', 'customer_id = ?', array('1002')));
236
237    $this->verify();
238  }
239
240  public function testSfUpdateOrderStatus_変更後の対応状況が加算対象の場合_変更後の加算ポイントを足す() {
241    $order_id = '1001';
242    $old_dates = $this->objQuery->select(
243      'update_date, commit_date, payment_date',
244      'dtb_order', 'order_id = ?', array($order_id));
245
246    $this->helper->sfUpdateOrderStatus($order_id, ORDER_DELIV, 50, 0);
247
248    $this->expected = array(
249      'order' => array(
250        'status' => ORDER_DELIV,
251        'add_point' => '50',  // 引数の設定どおりになる
252        'use_point' => '0' // 引数の設定どおりになる
253      ),
254      'customer' => array(
255        'point' => '150' // 元々100pt→50pt足す
256      )
257    );
258    $this->actual['order'] = array_shift($this->objQuery->select(
259      'status, use_point, add_point',
260      'dtb_order', 'order_id = ?', array($order_id)));
261    $this->actual['customer'] = array_shift($this->objQuery->select(
262      'point', 'dtb_customer', 'customer_id = ?', array('1001')));
263
264    $this->verify();
265  }
266
267  public function testSfUpdateOrderStatus_加算ポイントがプラスの場合_会員テーブルが更新される() {
268    $order_id = '1001';
269    $old_dates = $this->objQuery->select(
270      'update_date, commit_date, payment_date',
271      'dtb_order', 'order_id = ?', array($order_id));
272
273    $this->helper->usePoint = true;
274    $this->helper->addPoint = true;
275    $this->helper->sfUpdateOrderStatus($order_id, ORDER_PRE_END, 40, 25);
276
277    $this->expected = array(
278      'order' => array(
279        'status' => ORDER_PRE_END,
280        'add_point' => '40',  // 引数の設定どおりになる
281        'use_point' => '25' // 引数の設定どおりになる
282      ),
283      'customer' => array(
284        'point' => '105' // 変更前の状態で-10pt,変更後の状態で+15pt
285      )
286    );
287    $this->actual['order'] = array_shift($this->objQuery->select(
288      'status, use_point, add_point',
289      'dtb_order', 'order_id = ?', array($order_id)));
290    $this->actual['customer'] = array_shift($this->objQuery->select(
291      'point', 'dtb_customer', 'customer_id = ?', '1001'));
292
293    $this->verify();
294  }
295
296  public function testSfUpdateOrderStatus_加算ポイントが負でポイントが足りている場合_会員テーブルが更新される() {
297    $order_id = '1001';
298    $old_dates = $this->objQuery->select(
299      'update_date, commit_date, payment_date',
300      'dtb_order', 'order_id = ?', array($order_id));
301
302    $this->helper->usePoint = true;
303    $this->helper->addPoint = true;
304    $this->helper->sfUpdateOrderStatus($order_id, ORDER_PRE_END, 0, 50);
305
306    $this->expected = array(
307      'order' => array(
308        'status' => ORDER_PRE_END,
309        'add_point' => '0',  // 引数の設定どおりになる
310        'use_point' => '50' // 引数の設定どおりになる
311      ),
312      'customer' => array(
313        'point' => '40' // 変更前の状態で-10pt,変更後の状態で-50pt
314      )
315    );
316    $this->actual['order'] = array_shift($this->objQuery->select(
317      'status, use_point, add_point',
318      'dtb_order', 'order_id = ?', array($order_id)));
319    $this->actual['customer'] = array_shift($this->objQuery->select(
320      'point', 'dtb_customer', 'customer_id = ?', '1001'));
321
322    $this->verify();
323  }
324
325  // TODO ロールバックされる場合はexitするためテスト不可.
326  /**
327  public function testSfUpdateOrderStatus_加算ポイントが負でポイントが足りていない場合_会員テーブルがロールバックされエラーとなる() {
328  }
329  */
330
331  //////////////////////////////////////////
332
333  function assertUpdate($new_dates, $old_dates, $key, $message, $is_update = true) {
334    $new_date = $new_dates[0][$key];
335    $old_date = $old_dates[0][$key];
336    if (empty($new_date)) $new_date = '2000-01-01 00:00:00';
337    if (empty($old_date)) $old_date = '2000-01-01 00:00:00';
338
339    if ($is_update) {
340      $this->assertTrue($new_date > $old_date, $message . 'が更新されている');
341    } else {
342      $this->assertEquals($new_date, $old_date, $message . 'が更新されていない');
343    }
344  }
345}
346
347class SC_Helper_Purchase_sfUpdateOrderStatusMock extends SC_Helper_Purchase {
348
349  var $usePoint;
350  var $addPoint;
351
352  function isUsePoint($status) {
353    if (is_null($this->usePoint)) {
354      return parent::isUsePoint($status);
355    }
356    return $this->usePoint;
357  }
358
359  function isAddPoint($status) {
360    if (is_null($this->addPoint)) {
361      return parent::isAddPoint($status);
362    }
363    return $this->addPoint;
364  }
365}
366
Note: See TracBrowser for help on using the repository browser.