1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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 |
---|
25 | require_once(realpath(dirname(__FILE__)) . '/../../require.php'); |
---|
26 | require_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 | */ |
---|
35 | class 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_unlimited' => 0, |
---|
129 | 'sale_limit' => null, |
---|
130 | 'price01' => 10000, |
---|
131 | 'price02' => null, |
---|
132 | 'deliv_fee' => null, |
---|
133 | 'point_rate' => null, |
---|
134 | 'status' => null, |
---|
135 | 'creator_id' => 1, |
---|
136 | 'create_date' => $this->now, |
---|
137 | 'update_date' => null, |
---|
138 | 'del_flg' => 0 |
---|
139 | ); |
---|
140 | |
---|
141 | $this->actual = $this->objPage->getProductsClass($product_id); |
---|
142 | |
---|
143 | $this->verify(); |
---|
144 | } |
---|
145 | |
---|
146 | function testGetAllClass() { |
---|
147 | $this->clearClass(); |
---|
148 | $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL")); |
---|
149 | $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑")); |
---|
150 | $this->setClass(3, "味", 3, array()); |
---|
151 | |
---|
152 | $this->expected = array("1000" => "大きさ", |
---|
153 | "2" => "色"); |
---|
154 | $this->actual = $this->objPage->getAllClass(); |
---|
155 | |
---|
156 | $this->verify(); |
---|
157 | } |
---|
158 | |
---|
159 | function testGetAllClassCategory規格1のみ() { |
---|
160 | $this->clearClass(); |
---|
161 | $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL")); |
---|
162 | $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑")); |
---|
163 | $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口")); |
---|
164 | |
---|
165 | $this->expected = array( |
---|
166 | array("class_id1" => 1000, |
---|
167 | "classcategory_id1" => 1000000004, |
---|
168 | "name1" => "LL", |
---|
169 | "rank1" => 4), |
---|
170 | array("class_id1" => 1000, |
---|
171 | "classcategory_id1" => 1000000003, |
---|
172 | "name1" => "L", |
---|
173 | "rank1" => 3), |
---|
174 | array("class_id1" => 1000, |
---|
175 | "classcategory_id1" => 1000000002, |
---|
176 | "name1" => "M", |
---|
177 | "rank1" => 2), |
---|
178 | array("class_id1" => 1000, |
---|
179 | "classcategory_id1" => 1000000001, |
---|
180 | "name1" => "S", |
---|
181 | "rank1" => 1)); |
---|
182 | |
---|
183 | $this->actual = $this->objPage->getAllClassCategory(1000); |
---|
184 | $this->verify(); |
---|
185 | } |
---|
186 | |
---|
187 | function testGetAllClassCategory規格1と3() { |
---|
188 | $this->clearClass(); |
---|
189 | $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL")); |
---|
190 | $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑")); |
---|
191 | $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口")); |
---|
192 | |
---|
193 | $this->expected = array( |
---|
194 | array("class_id1" => 1000, |
---|
195 | "classcategory_id1" => 1000000004, |
---|
196 | "name1" => "LL", |
---|
197 | "rank1" => 4, |
---|
198 | "class_id2" => 3, |
---|
199 | "classcategory_id2" => 3000003, |
---|
200 | "name2" => "辛口", |
---|
201 | "rank2" => 3), |
---|
202 | array("class_id1" => 1000, |
---|
203 | "classcategory_id1" => 1000000004, |
---|
204 | "name1" => "LL", |
---|
205 | "rank1" => 4, |
---|
206 | "class_id2" => 3, |
---|
207 | "classcategory_id2" => 3000002, |
---|
208 | "name2" => "中辛", |
---|
209 | "rank2" => 2), |
---|
210 | array("class_id1" => 1000, |
---|
211 | "classcategory_id1" => 1000000004, |
---|
212 | "name1" => "LL", |
---|
213 | "rank1" => 4, |
---|
214 | "class_id2" => 3, |
---|
215 | "classcategory_id2" => 3000001, |
---|
216 | "name2" => "甘口", |
---|
217 | "rank2" => 1), |
---|
218 | |
---|
219 | array("class_id1" => 1000, |
---|
220 | "classcategory_id1" => 1000000003, |
---|
221 | "name1" => "L", |
---|
222 | "rank1" => 3, |
---|
223 | "class_id2" => 3, |
---|
224 | "classcategory_id2" => 3000003, |
---|
225 | "name2" => "辛口", |
---|
226 | "rank2" => 3), |
---|
227 | array("class_id1" => 1000, |
---|
228 | "classcategory_id1" => 1000000003, |
---|
229 | "name1" => "L", |
---|
230 | "rank1" => 3, |
---|
231 | "class_id2" => 3, |
---|
232 | "classcategory_id2" => 3000002, |
---|
233 | "name2" => "中辛", |
---|
234 | "rank2" => 2), |
---|
235 | array("class_id1" => 1000, |
---|
236 | "classcategory_id1" => 1000000003, |
---|
237 | "name1" => "L", |
---|
238 | "rank1" => 3, |
---|
239 | "class_id2" => 3, |
---|
240 | "classcategory_id2" => 3000001, |
---|
241 | "name2" => "甘口", |
---|
242 | "rank2" => 1), |
---|
243 | |
---|
244 | array("class_id1" => 1000, |
---|
245 | "classcategory_id1" => 1000000002, |
---|
246 | "name1" => "M", |
---|
247 | "rank1" => 2, |
---|
248 | "class_id2" => 3, |
---|
249 | "classcategory_id2" => 3000003, |
---|
250 | "name2" => "辛口", |
---|
251 | "rank2" => 3), |
---|
252 | array("class_id1" => 1000, |
---|
253 | "classcategory_id1" => 1000000002, |
---|
254 | "name1" => "M", |
---|
255 | "rank1" => 2, |
---|
256 | "class_id2" => 3, |
---|
257 | "classcategory_id2" => 3000002, |
---|
258 | "name2" => "中辛", |
---|
259 | "rank2" => 2), |
---|
260 | array("class_id1" => 1000, |
---|
261 | "classcategory_id1" => 1000000002, |
---|
262 | "name1" => "M", |
---|
263 | "rank1" => 2, |
---|
264 | "class_id2" => 3, |
---|
265 | "classcategory_id2" => 3000001, |
---|
266 | "name2" => "甘口", |
---|
267 | "rank2" => 1), |
---|
268 | |
---|
269 | array("class_id1" => 1000, |
---|
270 | "classcategory_id1" => 1000000001, |
---|
271 | "name1" => "S", |
---|
272 | "rank1" => 1, |
---|
273 | "class_id2" => 3, |
---|
274 | "classcategory_id2" => 3000003, |
---|
275 | "name2" => "辛口", |
---|
276 | "rank2" => 3), |
---|
277 | array("class_id1" => 1000, |
---|
278 | "classcategory_id1" => 1000000001, |
---|
279 | "name1" => "S", |
---|
280 | "rank1" => 1, |
---|
281 | "class_id2" => 3, |
---|
282 | "classcategory_id2" => 3000002, |
---|
283 | "name2" => "中辛", |
---|
284 | "rank2" => 2), |
---|
285 | array("class_id1" => 1000, |
---|
286 | "classcategory_id1" => 1000000001, |
---|
287 | "name1" => "S", |
---|
288 | "rank1" => 1, |
---|
289 | "class_id2" => 3, |
---|
290 | "classcategory_id2" => 3000001, |
---|
291 | "name2" => "甘口", |
---|
292 | "rank2" => 1), |
---|
293 | ); |
---|
294 | |
---|
295 | $this->actual = $this->objPage->getAllClassCategory(1000, 3); |
---|
296 | $this->verify(); |
---|
297 | } |
---|
298 | |
---|
299 | function testGetProductsClassAndClasscategory() { |
---|
300 | $product_id = 10000; |
---|
301 | $product_class_id = 1000; |
---|
302 | $class_combination_id = 200; |
---|
303 | $this->clearClass(); |
---|
304 | $this->setClass(1000, "大きさ", 1, array("S", "M", "L", "LL")); |
---|
305 | $this->setClass(2, "色", 2, array("赤", "青", "黄", "緑")); |
---|
306 | $this->setClass(3, "味", 3, array("甘口", "中辛", "辛口")); |
---|
307 | $this->setProductsClass($product_id, $product_class_id, |
---|
308 | $class_combination_id); |
---|
309 | $this->setClassCombination($class_combination_id, 100, 3000001, 2); |
---|
310 | $this->setClassCombination(100, null, 2000001, 1); |
---|
311 | |
---|
312 | |
---|
313 | $this->expected = array( |
---|
314 | array("class_id1" => 2, |
---|
315 | "class_id2" => 3, |
---|
316 | "name1" => "赤", |
---|
317 | "name2" => "甘口", |
---|
318 | "rank1" => 1, |
---|
319 | "rank2" => 1, |
---|
320 | "product_class_id" => 1000, |
---|
321 | "product_id" => 10000, |
---|
322 | "classcategory_id1" => 2000001, |
---|
323 | "classcategory_id2" => 3000001, |
---|
324 | "product_code" => "product_code1000", |
---|
325 | "stock" => null, |
---|
326 | "stock_unlimited" => 0, |
---|
327 | "sale_limit" => null, |
---|
328 | "price01" => 10000, |
---|
329 | "price02" => null)); |
---|
330 | |
---|
331 | $this->actual = $this->objPage->getProductsClassAndClasscategory($product_id); |
---|
332 | |
---|
333 | $this->verify(); |
---|
334 | } |
---|
335 | |
---|
336 | function verify() { |
---|
337 | $this->assertEquals($this->expected, $this->actual); |
---|
338 | } |
---|
339 | |
---|
340 | function setProduct($product_id, $name) { |
---|
341 | $val['product_id'] = $product_id; |
---|
342 | $val['name'] = $name; |
---|
343 | $val['creator_id'] = 1; |
---|
344 | $val['deliv_date_id'] = 1; |
---|
345 | $this->objQuery->insert("dtb_products", $val); |
---|
346 | } |
---|
347 | |
---|
348 | function setProductsClass($product_id, $product_class_id, $class_combination_id = null) { |
---|
349 | $val['product_class_id'] = $product_class_id; |
---|
350 | $val['product_id'] = $product_id; |
---|
351 | $val['class_combination_id'] = $class_combination_id; |
---|
352 | $val['product_code'] = 'product_code' . $product_class_id; |
---|
353 | $val['price01'] = 10000; |
---|
354 | $val['creator_id'] = 1; |
---|
355 | $val['create_date'] = $this->now; |
---|
356 | $val['del_flg'] = 0; |
---|
357 | $this->objQuery->insert("dtb_products_class", $val); |
---|
358 | } |
---|
359 | |
---|
360 | function setClassCombination($class_combination_id, |
---|
361 | $parent_class_combination_id, $classcategory_id, |
---|
362 | $level) { |
---|
363 | $val['class_combination_id'] = $class_combination_id; |
---|
364 | $val['parent_class_combination_id'] = $parent_class_combination_id; |
---|
365 | $val['classcategory_id'] = $classcategory_id; |
---|
366 | $val['level'] = $level; |
---|
367 | $this->objQuery->insert("dtb_class_combination", $val); |
---|
368 | } |
---|
369 | |
---|
370 | function clearClass() { |
---|
371 | $this->objQuery->delete("dtb_class"); |
---|
372 | $this->objQuery->delete("dtb_classcategory"); |
---|
373 | } |
---|
374 | |
---|
375 | /** |
---|
376 | * 規格と規格分類を生成する. |
---|
377 | * |
---|
378 | * @param integer $class_id 規格ID |
---|
379 | * @param string $class_name 規格名 |
---|
380 | * @param integer $rank 規格の表示順 |
---|
381 | * @param array $classcategory 規格分類名の配列 |
---|
382 | */ |
---|
383 | function setClass($class_id, $class_name, $rank, $classcategory) { |
---|
384 | $val['class_id'] = $class_id; |
---|
385 | $val['name'] = $class_name; |
---|
386 | $val['creator_id'] = 1; |
---|
387 | $val['del_flg'] = 0; |
---|
388 | $val['rank'] = $rank; |
---|
389 | |
---|
390 | $this->objQuery->insert("dtb_class", $val); |
---|
391 | $i = 1; |
---|
392 | foreach ($classcategory as $name) { |
---|
393 | $val['classcategory_id'] = $class_id . "00000" . $i; |
---|
394 | $val['name'] = $name; |
---|
395 | $val['rank'] = $i; |
---|
396 | $this->objQuery->insert("dtb_classcategory", $val); |
---|
397 | $i++; |
---|
398 | } |
---|
399 | } |
---|
400 | } |
---|
401 | |
---|
402 | class LC_Page_Admin_Products_ProductClass_Mock extends LC_Page_Admin_Products_ProductClass { |
---|
403 | |
---|
404 | function authorization() { |
---|
405 | // quiet. |
---|
406 | } |
---|
407 | |
---|
408 | function assignView() { |
---|
409 | // quiet. |
---|
410 | } |
---|
411 | } |
---|
412 | ?> |
---|