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