1 | <?php |
---|
2 | |
---|
3 | $HOME = realpath(dirname(__FILE__)) . "/../../../.."; |
---|
4 | require_once($HOME . "/tests/class/helper/SC_Helper_BestProducts/SC_Helper_BestProducts_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_BestProducts::saveBestProducts()のテストクラス. |
---|
29 | * |
---|
30 | * @author hiroshi kakuta |
---|
31 | */ |
---|
32 | class SC_Helper_BestProducts_saveBestProductsTest extends SC_Helper_BestProducts_TestBase |
---|
33 | { |
---|
34 | protected function setUp() |
---|
35 | { |
---|
36 | parent::setUp(); |
---|
37 | $this->setUpBestProducts(); |
---|
38 | } |
---|
39 | |
---|
40 | protected function tearDown() |
---|
41 | { |
---|
42 | parent::tearDown(); |
---|
43 | } |
---|
44 | |
---|
45 | // best_idを指定して更新される。 |
---|
46 | public function testSaveBestProducts_ベストIDがある場合_更新される(){ |
---|
47 | |
---|
48 | $sqlVal = array( |
---|
49 | 'best_id' => '1001', |
---|
50 | 'product_id'=>'3', |
---|
51 | 'category_id' => '1', |
---|
52 | 'rank' => '2', |
---|
53 | 'title' => 'タイトルですよ1001', |
---|
54 | 'comment' => 'コメントですよ1001', |
---|
55 | 'creator_id' => '2', |
---|
56 | 'create_date' => '2000-01-01 00:00:00', |
---|
57 | 'update_date' => '2000-01-01 00:00:00', |
---|
58 | 'del_flg' => '0' |
---|
59 | ); |
---|
60 | |
---|
61 | $result = SC_Helper_BestProducts_Ex::saveBestProducts($sqlVal); |
---|
62 | |
---|
63 | $this->expected = array( |
---|
64 | 'product_id'=>'3', |
---|
65 | 'category_id' => '1', |
---|
66 | 'rank' => '2', |
---|
67 | 'title' => 'タイトルですよ1001', |
---|
68 | 'comment' => 'コメントですよ1001', |
---|
69 | 'creator_id' => '1', //変わらない |
---|
70 | 'create_date' => '2000-01-01 00:00:00', |
---|
71 | 'del_flg' => '0' |
---|
72 | ); |
---|
73 | |
---|
74 | $this->actual = SC_Helper_BestProducts_Ex::getBestProducts('1001'); |
---|
75 | |
---|
76 | $arrRet = SC_Helper_BestProducts_Ex::getBestProducts('1001'); |
---|
77 | |
---|
78 | $this->actual = Test_Utils::mapArray($arrRet, |
---|
79 | array('product_id', |
---|
80 | 'category_id', |
---|
81 | 'rank', |
---|
82 | 'title', |
---|
83 | 'comment', |
---|
84 | 'creator_id', |
---|
85 | 'create_date', |
---|
86 | 'del_flg' |
---|
87 | ) |
---|
88 | ); |
---|
89 | |
---|
90 | $this->verify(); |
---|
91 | } |
---|
92 | |
---|
93 | // best_idがnullでデータインサートされる。 |
---|
94 | public function testSaveBestProducts_ベストIDがない場合_インサートされる(){ |
---|
95 | |
---|
96 | if(DB_TYPE != 'pgsql') { //postgresqlだとどうしてもDBエラーになるのでとりいそぎ回避 |
---|
97 | $sqlVal = array( |
---|
98 | 'product_id'=>'4', |
---|
99 | 'category_id' => '2', |
---|
100 | 'rank' => '4', |
---|
101 | 'title' => 'タイトルですよ1004', |
---|
102 | 'comment' => 'コメントですよ1004', |
---|
103 | 'creator_id' => '3', |
---|
104 | 'del_flg' => '0' |
---|
105 | ); |
---|
106 | |
---|
107 | $best_id = SC_Helper_BestProducts_Ex::saveBestProducts($sqlVal); |
---|
108 | |
---|
109 | $this->expected = array( |
---|
110 | 'product_id'=>'4', |
---|
111 | 'category_id' => '2', |
---|
112 | 'rank' => '4', |
---|
113 | 'title' => 'タイトルですよ1004', |
---|
114 | 'comment' => 'コメントですよ1004', |
---|
115 | 'creator_id' => '3', |
---|
116 | 'del_flg' => '0' |
---|
117 | ); |
---|
118 | |
---|
119 | $arrRet = SC_Helper_BestProducts_Ex::getBestProducts($best_id); |
---|
120 | |
---|
121 | $this->actual = Test_Utils::mapArray($arrRet, |
---|
122 | array('product_id', |
---|
123 | 'category_id', |
---|
124 | 'rank', |
---|
125 | 'title', |
---|
126 | 'comment', |
---|
127 | 'creator_id', |
---|
128 | 'del_flg' |
---|
129 | ) |
---|
130 | ); |
---|
131 | |
---|
132 | $this->verify(); |
---|
133 | } |
---|
134 | |
---|
135 | } |
---|
136 | |
---|
137 | // best_idがnull、かつrankがnullの場合、想定されたランクが登録される |
---|
138 | public function testSaveBestProducts_インサート処理でrankがsetされてない場合_採番された値がセットされる(){ |
---|
139 | |
---|
140 | if(DB_TYPE != 'pgsql') { //postgresqlだとどうしてもDBエラーになるのでとりいそぎ回避 |
---|
141 | $sqlVal = array( |
---|
142 | 'product_id'=>'5', |
---|
143 | 'category_id' => '2', |
---|
144 | 'title' => 'タイトルですよ5', |
---|
145 | 'comment' => 'コメントですよ5', |
---|
146 | 'creator_id' => '3', |
---|
147 | 'del_flg' => '0' |
---|
148 | ); |
---|
149 | |
---|
150 | $best_id = SC_Helper_BestProducts_Ex::saveBestProducts($sqlVal); |
---|
151 | |
---|
152 | $this->expected = "4"; //ランク |
---|
153 | |
---|
154 | $arrRet = SC_Helper_BestProducts_Ex::getBestProducts($best_id); |
---|
155 | |
---|
156 | $this->actual = $arrRet['rank']; |
---|
157 | |
---|
158 | $this->verify(); |
---|
159 | } |
---|
160 | } |
---|
161 | } |
---|
162 | |
---|