source: branches/version-2_5-dev/test/class/page/LC_Page_Admin_Products_ProductClass_Test.php @ 20764

Revision 20764, 17.7 KB checked in by nanasess, 13 years ago (diff)

#601 (コピーライトの更新)

  • 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-2011 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/subnavi.tpl',
57                            $this->objPage->tpl_subnavi);
58        $this->assertEquals('products',
59                            $this->objPage->tpl_mainno);
60        $this->assertEquals('product',
61                            $this->objPage->tpl_subno);
62        $this->assertEquals('商品登録(商品規格)',
63                            $this->objPage->tpl_subtitle);
64    }
65
66    function testProcess() {
67        $this->objPage->process();
68    }
69
70    function testCreateSearchParams() {
71        $keys = array('search_product_id',
72                      'search_product_code',
73                      'search_category_id',
74                      'search_product_class_name',
75                      'search_name',
76                      'search_startyear',
77                      'search_startmonth',
78                      'search_startday',
79                      'search_endyear',
80                      'search_endmonth',
81                      'search_endday',
82                      'search_page_max',
83                      'search_pageno',
84                      'mode');
85        foreach ($keys as $key) {
86            $_POST[$key] = $key . " in value.";
87        }
88
89        $this->expected = array('search_product_id' => 'search_product_id in value.',
90                                'search_product_code' => 'search_product_code in value.',
91                                'search_category_id' => 'search_category_id in value.',
92                                'search_product_class_name' => 'search_product_class_name in value.',
93                                'search_name' => 'search_name in value.',
94                                'search_startyear' => 'search_startyear in value.',
95                                'search_startmonth' => 'search_startmonth in value.',
96                                'search_startday' => 'search_startday in value.',
97                                'search_endyear' => 'search_endyear in value.',
98                                'search_endmonth' => 'search_endmonth in value.',
99                                'search_endday' => 'search_endday in value.',
100                                'search_page_max' => 'search_page_max in value.',
101                                'search_pageno' => 'search_pageno in value.');
102
103        $this->actual = $this->objPage->createSearchParams($_POST);
104
105        $this->verify();
106    }
107
108    function testGetProductName() {
109        $product_id = 10000000;
110        $this->expected = "テスト商品";
111        $this->setProduct($product_id, $this->expected);
112
113        $this->actual = $this->objPage->getProductName($product_id);
114
115        $this->verify();
116    }
117
118    function testGetProductsClass() {
119        $product_id = 10000000;
120        $product_class_id = 10000;
121        $this->setProductsClass($product_id, $product_class_id);
122        $this->expected = array('product_class_id' => $product_class_id,
123                                'product_id' => $product_id,
124                                'class_combination_id' => null,
125                                'product_code' => 'product_code' . $product_class_id,
126                                'stock' => null,
127                                'stock_unlimited' => 0,
128                                'sale_limit' => null,
129                                'price01' => 10000,
130                                'price02' => null,
131                                'deliv_fee' => null,
132                                'point_rate' => null,
133                                'status' => null,
134                                'creator_id' => 1,
135                                'create_date' => $this->now,
136                                'update_date' => null,
137                                'del_flg' => 0
138                                );
139
140        $this->actual = $this->objPage->getProductsClass($product_id);
141
142        $this->verify();
143    }
144
145    function testGetAllClass() {
146        $this->clearClass();
147        $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL"));
148        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
149        $this->setClass(3, "味", 3, array());
150
151        $this->expected = array("1000" => "大きさ",
152                                "2" => "色");
153        $this->actual = $this->objPage->getAllClass();
154
155        $this->verify();
156    }
157
158    function testGetAllClassCategory規格1のみ() {
159        $this->clearClass();
160        $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL"));
161        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
162        $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口"));
163
164        $this->expected = array(
165                                array("class_id1" => 1000,
166                                      "classcategory_id1" => 1000000004,
167                                      "name1" => "LL",
168                                      "rank1" => 4),
169                                array("class_id1" => 1000,
170                                      "classcategory_id1" => 1000000003,
171                                      "name1" => "L",
172                                      "rank1" => 3),
173                                array("class_id1" => 1000,
174                                      "classcategory_id1" => 1000000002,
175                                      "name1" => "M",
176                                      "rank1" => 2),
177                                array("class_id1" => 1000,
178                                      "classcategory_id1" => 1000000001,
179                                      "name1" => "S",
180                                      "rank1" => 1));
181
182        $this->actual = $this->objPage->getAllClassCategory(1000);
183        $this->verify();
184    }
185
186    function testGetAllClassCategory規格1と3() {
187        $this->clearClass();
188        $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL"));
189        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
190        $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口"));
191
192        $this->expected = array(
193                                array("class_id1" => 1000,
194                                      "classcategory_id1" => 1000000004,
195                                      "name1" => "LL",
196                                      "rank1" => 4,
197                                      "class_id2" => 3,
198                                      "classcategory_id2" => 3000003,
199                                      "name2" => "辛口",
200                                      "rank2" => 3),
201                                array("class_id1" => 1000,
202                                      "classcategory_id1" => 1000000004,
203                                      "name1" => "LL",
204                                      "rank1" => 4,
205                                      "class_id2" => 3,
206                                      "classcategory_id2" => 3000002,
207                                      "name2" => "中辛",
208                                      "rank2" => 2),
209                                array("class_id1" => 1000,
210                                      "classcategory_id1" => 1000000004,
211                                      "name1" => "LL",
212                                      "rank1" => 4,
213                                      "class_id2" => 3,
214                                      "classcategory_id2" => 3000001,
215                                      "name2" => "甘口",
216                                      "rank2" => 1),
217
218                                array("class_id1" => 1000,
219                                      "classcategory_id1" => 1000000003,
220                                      "name1" => "L",
221                                      "rank1" => 3,
222                                      "class_id2" => 3,
223                                      "classcategory_id2" => 3000003,
224                                      "name2" => "辛口",
225                                      "rank2" => 3),
226                                array("class_id1" => 1000,
227                                      "classcategory_id1" => 1000000003,
228                                      "name1" => "L",
229                                      "rank1" => 3,
230                                      "class_id2" => 3,
231                                      "classcategory_id2" => 3000002,
232                                      "name2" => "中辛",
233                                      "rank2" => 2),
234                                array("class_id1" => 1000,
235                                      "classcategory_id1" => 1000000003,
236                                      "name1" => "L",
237                                      "rank1" => 3,
238                                      "class_id2" => 3,
239                                      "classcategory_id2" => 3000001,
240                                      "name2" => "甘口",
241                                      "rank2" => 1),
242
243                                array("class_id1" => 1000,
244                                      "classcategory_id1" => 1000000002,
245                                      "name1" => "M",
246                                      "rank1" => 2,
247                                      "class_id2" => 3,
248                                      "classcategory_id2" => 3000003,
249                                      "name2" => "辛口",
250                                      "rank2" => 3),
251                                array("class_id1" => 1000,
252                                      "classcategory_id1" => 1000000002,
253                                      "name1" => "M",
254                                      "rank1" => 2,
255                                      "class_id2" => 3,
256                                      "classcategory_id2" => 3000002,
257                                      "name2" => "中辛",
258                                      "rank2" => 2),
259                                array("class_id1" => 1000,
260                                      "classcategory_id1" => 1000000002,
261                                      "name1" => "M",
262                                      "rank1" => 2,
263                                      "class_id2" => 3,
264                                      "classcategory_id2" => 3000001,
265                                      "name2" => "甘口",
266                                      "rank2" => 1),
267
268                                array("class_id1" => 1000,
269                                      "classcategory_id1" => 1000000001,
270                                      "name1" => "S",
271                                      "rank1" => 1,
272                                      "class_id2" => 3,
273                                      "classcategory_id2" => 3000003,
274                                      "name2" => "辛口",
275                                      "rank2" => 3),
276                                array("class_id1" => 1000,
277                                      "classcategory_id1" => 1000000001,
278                                      "name1" => "S",
279                                      "rank1" => 1,
280                                      "class_id2" => 3,
281                                      "classcategory_id2" => 3000002,
282                                      "name2" => "中辛",
283                                      "rank2" => 2),
284                                array("class_id1" => 1000,
285                                      "classcategory_id1" => 1000000001,
286                                      "name1" => "S",
287                                      "rank1" => 1,
288                                      "class_id2" => 3,
289                                      "classcategory_id2" => 3000001,
290                                      "name2" => "甘口",
291                                      "rank2" => 1),
292                                );
293
294        $this->actual = $this->objPage->getAllClassCategory(1000, 3);
295        $this->verify();
296    }
297
298    function testGetProductsClassAndClasscategory() {
299        $product_id = 10000;
300        $product_class_id = 1000;
301        $class_combination_id = 200;
302        $this->clearClass();
303        $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL"));
304        $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑"));
305        $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口"));
306        $this->setProductsClass($product_id, $product_class_id,
307                                $class_combination_id);
308        $this->setClassCombination($class_combination_id, 100, 3000001, 2);
309        $this->setClassCombination(100, null, 2000001, 1);
310
311
312        $this->expected = array(
313                                array("class_id1" => 2,
314                                      "class_id2" => 3,
315                                      "name1" => "赤",
316                                      "name2" => "甘口",
317                                      "rank1" => 1,
318                                      "rank2" => 1,
319                                      "product_class_id" => 1000,
320                                      "product_id" => 10000,
321                                      "classcategory_id1" => 2000001,
322                                      "classcategory_id2" => 3000001,
323                                      "product_code" => "product_code1000",
324                                      "stock" => null,
325                                      "stock_unlimited" => 0,
326                                      "sale_limit" => null,
327                                      "price01" => 10000,
328                                      "price02" => null));
329
330        $this->actual = $this->objPage->getProductsClassAndClasscategory($product_id);
331
332        $this->verify();
333    }
334
335    function verify() {
336        $this->assertEquals($this->expected, $this->actual);
337    }
338
339    function setProduct($product_id, $name) {
340        $val['product_id'] = $product_id;
341        $val['name'] = $name;
342        $val['creator_id'] = 1;
343        $val['deliv_date_id'] = 1;
344        $this->objQuery->insert("dtb_products", $val);
345    }
346
347    function setProductsClass($product_id, $product_class_id, $class_combination_id = null) {
348        $val['product_class_id'] = $product_class_id;
349        $val['product_id'] = $product_id;
350        $val['class_combination_id'] = $class_combination_id;
351        $val['product_code'] = 'product_code' . $product_class_id;
352        $val['price01'] = 10000;
353        $val['creator_id'] = 1;
354        $val['create_date'] = $this->now;
355        $val['del_flg'] = 0;
356        $this->objQuery->insert("dtb_products_class", $val);
357    }
358
359    function setClassCombination($class_combination_id,
360                                 $parent_class_combination_id, $classcategory_id,
361                                 $level) {
362        $val['class_combination_id'] = $class_combination_id;
363        $val['parent_class_combination_id'] = $parent_class_combination_id;
364        $val['classcategory_id'] = $classcategory_id;
365        $val['level'] = $level;
366        $this->objQuery->insert("dtb_class_combination", $val);
367    }
368
369    function clearClass() {
370        $this->objQuery->delete("dtb_class");
371        $this->objQuery->delete("dtb_classcategory");
372    }
373
374    /**
375     * 規格と規格分類を生成する.
376     *
377     * @param integer $class_id 規格ID
378     * @param string $class_name 規格名
379     * @param integer $rank 規格の表示順
380     * @param array $classcategory 規格分類名の配列
381     */
382    function setClass($class_id, $class_name, $rank, $classcategory) {
383        $val['class_id'] = $class_id;
384        $val['name'] = $class_name;
385        $val['creator_id'] = 1;
386        $val['del_flg'] = 0;
387        $val['rank'] = $rank;
388
389        $this->objQuery->insert("dtb_class", $val);
390        $i = 1;
391        foreach ($classcategory as $name) {
392            $val['classcategory_id'] = $class_id . "00000" . $i;
393            $val['name'] = $name;
394            $val['rank'] = $i;
395            $this->objQuery->insert("dtb_classcategory", $val);
396            $i++;
397        }
398    }
399}
400
401class LC_Page_Admin_Products_ProductClass_Mock extends LC_Page_Admin_Products_ProductClass {
402
403    function authorization() {
404        // quiet.
405    }
406
407    function assignView() {
408        // quiet.
409    }
410}
411?>
Note: See TracBrowser for help on using the repository browser.