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

Revision 22735, 6.7 KB checked in by h_yoshimoto, 11 years ago (diff)

#2193 ユニットテストチームのコミットをマージ(from camp/camp-2_13-tests)

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