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

Revision 22567, 13.2 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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