source: branches/version-2_13-dev/tests/class/helper/SC_Helper_BestProducts/SC_Helper_BestProducts_saveBestProductsTest.php @ 22856

Revision 22856, 5.2 KB checked in by Seasoft, 11 years ago (diff)

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

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • Property svn:executable set to *
Line 
1<?php
2
3$HOME = realpath(dirname(__FILE__)) . "/../../../..";
4require_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 */
32class 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
79        $this->actual = Test_Utils::mapArray($arrRet,
80            array('product_id',
81                'category_id',
82                'rank',
83                'title',
84                'comment',
85                'creator_id',
86                'create_date',
87                'del_flg'
88            )
89        );
90
91        $this->verify();
92    }
93
94    // best_idがnullでデータインサートされる。
95    public function testSaveBestProducts_ベストIDがない場合_インサートされる(){
96
97        if(DB_TYPE != 'pgsql') { //postgresqlだとどうしてもDBエラーになるのでとりいそぎ回避
98            $sqlVal = array(
99                'product_id'=>'4',
100                'category_id' => '2',
101                'rank' => '4',
102                'title' => 'タイトルですよ1004',
103                'comment' => 'コメントですよ1004',
104                'creator_id' => '3',
105                'del_flg' => '0'
106            );
107
108            $best_id = SC_Helper_BestProducts_Ex::saveBestProducts($sqlVal);
109
110            $this->expected = array(
111                'product_id'=>'4',
112                'category_id' => '2',
113                'rank' => '4',
114                'title' => 'タイトルですよ1004',
115                'comment' => 'コメントですよ1004',
116                'creator_id' => '3',
117                'del_flg' => '0'
118            );
119
120            $arrRet = SC_Helper_BestProducts_Ex::getBestProducts($best_id);
121
122
123            $this->actual = Test_Utils::mapArray($arrRet,
124                array('product_id',
125                    'category_id',
126                    'rank',
127                    'title',
128                    'comment',
129                    'creator_id',
130                    'del_flg'
131                )
132            );
133
134            $this->verify();
135        }
136
137    }
138
139    // best_idがnull、かつrankがnullの場合、想定されたランクが登録される
140    public function testSaveBestProducts_インサート処理でrankがsetされてない場合_採番された値がセットされる(){
141
142        if(DB_TYPE != 'pgsql') { //postgresqlだとどうしてもDBエラーになるのでとりいそぎ回避
143            $sqlVal = array(
144                'product_id'=>'5',
145                'category_id' => '2',
146                'title' => 'タイトルですよ5',
147                'comment' => 'コメントですよ5',
148                'creator_id' => '3',
149                'del_flg' => '0'
150            );
151
152            $best_id = SC_Helper_BestProducts_Ex::saveBestProducts($sqlVal);
153
154            $this->expected = "4"; //ランク
155
156            $arrRet = SC_Helper_BestProducts_Ex::getBestProducts($best_id);
157
158
159            $this->actual = $arrRet['rank'];
160
161            $this->verify();
162        }
163    }
164
165}
166
Note: See TracBrowser for help on using the repository browser.