source: branches/camp/camp-2_13-tests/tests/class/helper/SC_Helper_BestProducts/SC_Helper_BestProducts_saveBestProductsTest.php @ 22689

Revision 22689, 4.8 KB checked in by hiro151, 11 years ago (diff)

#2183 SC_Helper_BestProductsのテストコード

  • 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
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        $sqlVal = array(
100            'product_id'=>'4',
101            'category_id' => '2',
102            'rank' => '4',
103            'title' => 'タイトルですよ1004',
104            'comment' => 'コメントですよ1004',
105            'creator_id' => '3',
106            'del_flg' => '0'
107        );
108
109        $best_id = SC_Helper_BestProducts::saveBestProducts($sqlVal);
110
111        $this->expected = array(
112            'product_id'=>'4',
113            'category_id' => '2',
114            'rank' => '4',
115            'title' => 'タイトルですよ1004',
116            'comment' => 'コメントですよ1004',
117            'creator_id' => '3',
118            'del_flg' => '0'
119        );
120
121        $arrRet = SC_Helper_BestProducts::getBestProducts($best_id);
122
123
124        $this->actual = Test_Utils::mapArray($arrRet,
125            array('product_id',
126                'category_id',
127                'rank',
128                'title',
129                'comment',
130                'creator_id',
131                'del_flg'
132            )
133        );
134
135        $this->verify();
136    }
137
138
139    // best_idがnull、かつrankがnullの場合、想定されたランクが登録される
140    public function testSaveBestProducts_インサート処理でrankがsetされてない場合_採番された値がセットされる(){
141
142        $sqlVal = array(
143            'product_id'=>'5',
144            'category_id' => '2',
145            'title' => 'タイトルですよ5',
146            'comment' => 'コメントですよ5',
147            'creator_id' => '3',
148            'del_flg' => '0'
149        );
150
151        $best_id = SC_Helper_BestProducts::saveBestProducts($sqlVal);
152
153        $this->expected = "4"; //ランク
154
155        $arrRet = SC_Helper_BestProducts::getBestProducts($best_id);
156
157
158        $this->actual = $arrRet['rank'];
159
160        $this->verify();
161    }
162
163}
164
Note: See TracBrowser for help on using the repository browser.