source: branches/version-2_12-dev/test/class/page/LC_Page_Admin_Products_ProductClass_Test.php @ 21867

Revision 21867, 17.6 KB checked in by nakanishi, 12 years ago (diff)

#1831 Copyright Update

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(realpath(dirname(__FILE__)) . '/../../require.php');
26require_once(realpath(dirname(__FILE__)) . '/../../../data/class/pages/admin/products/LC_Page_Admin_Products_ProductClass.php');
27
28/**
29 * LC_Page_Admin_Products_ProductClass のテストケース.
30 *
31 * @package Page
32 * @author Kentaro Ohkouchi
33 * @version $Id$
34 */
35class LC_Page_Admin_Products_ProductClass_Test extends PHPUnit_Framework_TestCase {
36
37    function setUp() {
38        $this->objQuery =& SC_Query::getSingletonInstance();
39        $this->objQuery->begin();
40
41        $this->objPage = new LC_Page_Admin_Products_ProductClass_Mock();
42        $this->objPage->init();
43        $this->now = "2010-01-01 00:00:00";
44    }
45
46    function tearDown() {
47        $this->objQuery->rollback();
48        $this->objQuery = null;
49        $this->objPage = null;
50    }
51
52    function testInit() {
53
54        $this->assertEquals('products/product_class.tpl',
55                            $this->objPage->tpl_mainpage);
56        $this->assertEquals('products',
57                            $this->objPage->tpl_mainno);
58        $this->assertEquals('product',
59                            $this->objPage->tpl_subno);
60        $this->assertEquals('商品登録(商品規格)',
61                            $this->objPage->tpl_subtitle);
62    }
63
64    function testProcess() {
65        $this->objPage->process();
66    }
67
68    function testCreateSearchParams() {
69        $keys = array('search_product_id',
70                      'search_product_code',
71                      'search_category_id',
72                      'search_product_class_name',
73                      'search_name',
74                      'search_startyear',
75                      'search_startmonth',
76                      'search_startday',
77                      'search_endyear',
78                      'search_endmonth',
79                      'search_endday',
80                      'search_page_max',
81                      'search_pageno',
82                      'mode');
83        foreach ($keys as $key) {
84            $_POST[$key] = $key . " in value.";
85        }
86
87        $this->expected = array('search_product_id' => 'search_product_id in value.',
88                                'search_product_code' => 'search_product_code in value.',
89                                'search_category_id' => 'search_category_id in value.',
90                                'search_product_class_name' => 'search_product_class_name in value.',
91                                'search_name' => 'search_name in value.',
92                                'search_startyear' => 'search_startyear in value.',
93                                'search_startmonth' => 'search_startmonth in value.',
94                                'search_startday' => 'search_startday in value.',
95                                'search_endyear' => 'search_endyear in value.',
96                                'search_endmonth' => 'search_endmonth in value.',
97                                'search_endday' => 'search_endday in value.',
98                                'search_page_max' => 'search_page_max in value.',
99                                'search_pageno' => 'search_pageno in value.');
100
101        $this->actual = $this->objPage->createSearchParams($_POST);
102
103        $this->verify();
104    }
105
106    function testGetProductName() {
107        $product_id = 10000000;
108        $this->expected = "テスト商品";
109        $this->setProduct($product_id, $this->expected);
110
111        $this->actual = $this->objPage->getProductName($product_id);
112
113        $this->verify();
114    }
115
116    function testGetProductsClass() {
117        $product_id = 10000000;
118        $product_class_id = 10000;
119        $this->setProductsClass($product_id, $product_class_id);
120        $this->expected = array('product_class_id' => $product_class_id,
121                                'product_id' => $product_id,
122                                'class_combination_id' => null,
123                                'product_code' => 'product_code' . $product_class_id,
124                                'stock' => null,
125                                'stock_unlimited' => 0,
126                                'sale_limit' => null,
127                                'price01' => 10000,
128                                'price02' => null,
129                                'deliv_fee' => null,
130                                'point_rate' => null,
131                                'status' => null,
132                                'creator_id' => 1,
133                                'create_date' => $this->now,
134                                'update_date' => null,
135                                'del_flg' => 0
136                                );
137
138        $this->actual = $this->objPage->getProductsClass($product_id);
139
140        $this->verify();
141    }
142
143    function testGetAllClass() {
144        $this->clearClass();
145        $this->setClass(1000, "大きさ", 1, array('S', 'M', 'L', 'LL'));
146        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
147        $this->setClass(3, "味", 3, array());
148
149        $this->expected = array('1000' => "大きさ",
150                                '2' => "色");
151        $this->actual = $this->objPage->getAllClass();
152
153        $this->verify();
154    }
155
156    function testGetAllClassCategory規格1のみ() {
157        $this->clearClass();
158        $this->setClass(1000, "大きさ", 1, array('S', 'M', 'L', 'LL'));
159        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
160        $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口"));
161
162        $this->expected = array(
163                                array('class_id1' => 1000,
164                                      'classcategory_id1' => 1000000004,
165                                      'name1' => 'LL',
166                                      'rank1' => 4),
167                                array('class_id1' => 1000,
168                                      'classcategory_id1' => 1000000003,
169                                      'name1' => 'L',
170                                      'rank1' => 3),
171                                array('class_id1' => 1000,
172                                      'classcategory_id1' => 1000000002,
173                                      'name1' => 'M',
174                                      'rank1' => 2),
175                                array('class_id1' => 1000,
176                                      'classcategory_id1' => 1000000001,
177                                      'name1' => 'S',
178                                      'rank1' => 1));
179
180        $this->actual = $this->objPage->getAllClassCategory(1000);
181        $this->verify();
182    }
183
184    function testGetAllClassCategory規格1と3() {
185        $this->clearClass();
186        $this->setClass(1000, "大きさ", 1, array('S', 'M', 'L', 'LL'));
187        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
188        $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口"));
189
190        $this->expected = array(
191                                array('class_id1' => 1000,
192                                      'classcategory_id1' => 1000000004,
193                                      'name1' => 'LL',
194                                      'rank1' => 4,
195                                      'class_id2' => 3,
196                                      'classcategory_id2' => 3000003,
197                                      'name2' => "辛口",
198                                      'rank2' => 3),
199                                array('class_id1' => 1000,
200                                      'classcategory_id1' => 1000000004,
201                                      'name1' => 'LL',
202                                      'rank1' => 4,
203                                      'class_id2' => 3,
204                                      'classcategory_id2' => 3000002,
205                                      'name2' => "中辛",
206                                      'rank2' => 2),
207                                array('class_id1' => 1000,
208                                      'classcategory_id1' => 1000000004,
209                                      'name1' => 'LL',
210                                      'rank1' => 4,
211                                      'class_id2' => 3,
212                                      'classcategory_id2' => 3000001,
213                                      'name2' => "甘口",
214                                      'rank2' => 1),
215
216                                array('class_id1' => 1000,
217                                      'classcategory_id1' => 1000000003,
218                                      'name1' => 'L',
219                                      'rank1' => 3,
220                                      'class_id2' => 3,
221                                      'classcategory_id2' => 3000003,
222                                      'name2' => "辛口",
223                                      'rank2' => 3),
224                                array('class_id1' => 1000,
225                                      'classcategory_id1' => 1000000003,
226                                      'name1' => 'L',
227                                      'rank1' => 3,
228                                      'class_id2' => 3,
229                                      'classcategory_id2' => 3000002,
230                                      'name2' => "中辛",
231                                      'rank2' => 2),
232                                array('class_id1' => 1000,
233                                      'classcategory_id1' => 1000000003,
234                                      'name1' => 'L',
235                                      'rank1' => 3,
236                                      'class_id2' => 3,
237                                      'classcategory_id2' => 3000001,
238                                      'name2' => "甘口",
239                                      'rank2' => 1),
240
241                                array('class_id1' => 1000,
242                                      'classcategory_id1' => 1000000002,
243                                      'name1' => 'M',
244                                      'rank1' => 2,
245                                      'class_id2' => 3,
246                                      'classcategory_id2' => 3000003,
247                                      'name2' => "辛口",
248                                      'rank2' => 3),
249                                array('class_id1' => 1000,
250                                      'classcategory_id1' => 1000000002,
251                                      'name1' => 'M',
252                                      'rank1' => 2,
253                                      'class_id2' => 3,
254                                      'classcategory_id2' => 3000002,
255                                      'name2' => "中辛",
256                                      'rank2' => 2),
257                                array('class_id1' => 1000,
258                                      'classcategory_id1' => 1000000002,
259                                      'name1' => 'M',
260                                      'rank1' => 2,
261                                      'class_id2' => 3,
262                                      'classcategory_id2' => 3000001,
263                                      'name2' => "甘口",
264                                      'rank2' => 1),
265
266                                array('class_id1' => 1000,
267                                      'classcategory_id1' => 1000000001,
268                                      'name1' => 'S',
269                                      'rank1' => 1,
270                                      'class_id2' => 3,
271                                      'classcategory_id2' => 3000003,
272                                      'name2' => "辛口",
273                                      'rank2' => 3),
274                                array('class_id1' => 1000,
275                                      'classcategory_id1' => 1000000001,
276                                      'name1' => 'S',
277                                      'rank1' => 1,
278                                      'class_id2' => 3,
279                                      'classcategory_id2' => 3000002,
280                                      'name2' => "中辛",
281                                      'rank2' => 2),
282                                array('class_id1' => 1000,
283                                      'classcategory_id1' => 1000000001,
284                                      'name1' => 'S',
285                                      'rank1' => 1,
286                                      'class_id2' => 3,
287                                      'classcategory_id2' => 3000001,
288                                      'name2' => "甘口",
289                                      'rank2' => 1),
290                                );
291
292        $this->actual = $this->objPage->getAllClassCategory(1000, 3);
293        $this->verify();
294    }
295
296    function testGetProductsClassAndClasscategory() {
297        $product_id = 10000;
298        $product_class_id = 1000;
299        $class_combination_id = 200;
300        $this->clearClass();
301        $this->setClass(1000, "大きさ", 1, array('S', 'M', 'L', 'LL'));
302        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
303        $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口"));
304        $this->setProductsClass($product_id, $product_class_id,
305                                $class_combination_id);
306        $this->setClassCombination($class_combination_id, 100, 3000001, 2);
307        $this->setClassCombination(100, null, 2000001, 1);
308
309
310        $this->expected = array(
311                                array('class_id1' => 2,
312                                      'class_id2' => 3,
313                                      'name1' => "赤",
314                                      'name2' => "甘口",
315                                      'rank1' => 1,
316                                      'rank2' => 1,
317                                      'product_class_id' => 1000,
318                                      'product_id' => 10000,
319                                      'classcategory_id1' => 2000001,
320                                      'classcategory_id2' => 3000001,
321                                      'product_code' => 'product_code1000',
322                                      'stock' => null,
323                                      'stock_unlimited' => 0,
324                                      'sale_limit' => null,
325                                      'price01' => 10000,
326                                      'price02' => null));
327
328        $this->actual = $this->objPage->getProductsClassAndClasscategory($product_id);
329
330        $this->verify();
331    }
332
333    function verify() {
334        $this->assertEquals($this->expected, $this->actual);
335    }
336
337    function setProduct($product_id, $name) {
338        $val['product_id'] = $product_id;
339        $val['name'] = $name;
340        $val['creator_id'] = 1;
341        $val['deliv_date_id'] = 1;
342        $this->objQuery->insert('dtb_products', $val);
343    }
344
345    function setProductsClass($product_id, $product_class_id, $class_combination_id = null) {
346        $val['product_class_id'] = $product_class_id;
347        $val['product_id'] = $product_id;
348        $val['class_combination_id'] = $class_combination_id;
349        $val['product_code'] = 'product_code' . $product_class_id;
350        $val['price01'] = 10000;
351        $val['creator_id'] = 1;
352        $val['create_date'] = $this->now;
353        $val['del_flg'] = 0;
354        $this->objQuery->insert('dtb_products_class', $val);
355    }
356
357    function setClassCombination($class_combination_id,
358                                 $parent_class_combination_id, $classcategory_id,
359                                 $level) {
360        $val['class_combination_id'] = $class_combination_id;
361        $val['parent_class_combination_id'] = $parent_class_combination_id;
362        $val['classcategory_id'] = $classcategory_id;
363        $val['level'] = $level;
364        $this->objQuery->insert('dtb_class_combination', $val);
365    }
366
367    function clearClass() {
368        $this->objQuery->delete('dtb_class');
369        $this->objQuery->delete('dtb_classcategory');
370    }
371
372    /**
373     * 規格と規格分類を生成する.
374     *
375     * @param integer $class_id 規格ID
376     * @param string $class_name 規格名
377     * @param integer $rank 規格の表示順
378     * @param array $classcategory 規格分類名の配列
379     */
380    function setClass($class_id, $class_name, $rank, $classcategory) {
381        $val['class_id'] = $class_id;
382        $val['name'] = $class_name;
383        $val['creator_id'] = 1;
384        $val['del_flg'] = 0;
385        $val['rank'] = $rank;
386
387        $this->objQuery->insert('dtb_class', $val);
388        $i = 1;
389        foreach ($classcategory as $name) {
390            $val['classcategory_id'] = $class_id . '00000' . $i;
391            $val['name'] = $name;
392            $val['rank'] = $i;
393            $this->objQuery->insert('dtb_classcategory', $val);
394            $i++;
395        }
396    }
397}
398
399class LC_Page_Admin_Products_ProductClass_Mock extends LC_Page_Admin_Products_ProductClass {
400
401    function authorization() {
402        // quiet.
403    }
404
405    function assignView() {
406        // quiet.
407    }
408}
409?>
Note: See TracBrowser for help on using the repository browser.