source: branches/version-2_13-dev/test/class/page/LC_Page_Admin_Products_ProductClass_Test.php @ 22857

Revision 22857, 17.6 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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