source: branches/version-2_13-dev/test/class/db/SC_DB_DBFactory_Test.php @ 22857

Revision 22857, 6.1 KB checked in by Seasoft, 11 years ago (diff)

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

  • 主に空白・空白行の調整。
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2013 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
25require_once(realpath(dirname(__FILE__)) . "/../../require.php");
26require_once(realpath(dirname(__FILE__)) . "/../../../data/class_extends/db_extends/SC_DB_DBFactory_Ex.php");
27
28/**
29 * SC_DB_DBFactory TestCase
30 *
31 * @package DB
32 * @author LOCKON CO.,LTD.
33 * @version $Id:SC_DB_DBFactory_Test.php 15532 2007-08-31 14:39:46Z nanasess $
34 */
35class SC_DB_DBFactory_Test extends PHPUnit_Framework_TestCase
36{
37
38    // }}}
39    // {{{ functions
40
41    /* TODO
42    function testSfGetDBVersion()
43    {
44        $dbFactory = SC_DB_DBFactory::getInstance();
45        $objQuery = new SC_Query(DEFAULT_DSN, true, true);
46        switch (DB_TYPE) {
47            case 'pgsql':
48                $this->assertEquals(true, preg_match("/^PostgreSQL [78].[0-9].[0-9]{1,}$/", $dbFactory->sfGetDBVersion()));
49            break;
50
51            case 'mysql':
52                $this->assertEquals(true, preg_match("/^MySQL [78].[0-9].[0-9]{1,}$/", $dbFactory->sfGetDBVersion()));
53            break;
54            default:
55        }
56    }
57    */
58
59    function testFindTableNames()
60    {
61        $dbFactory = SC_DB_DBFactory::getInstance();
62        $objQuery = new SC_Query(DEFAULT_DSN);
63        $actual = $dbFactory->findTableNames('mtb_pre');
64        $this->assertEquals('mtb_pref', $actual[0]);
65    }
66
67    function testConcatColumn()
68    {
69
70        $params = array('column1', 'column2');
71
72        switch (DB_TYPE) {
73        case 'pgsql':
74            $expected = "column1 || column2";
75            break;
76
77        case 'mysql':
78            $expected = "concat(column1, column2)";
79            break;
80
81        default:
82        }
83
84        $dbFactory = SC_DB_DBFactory::getInstance();
85        $actual = $dbFactory->concatColumn($params);
86
87        $this->assertEquals($expected, $actual);
88    }
89
90    /**
91     * 昨日の売上高・売上件数を算出する SQL のテスト.
92     */
93    function testGetOrderYesterdaySql()
94    {
95
96        switch (DB_TYPE) {
97        case 'pgsql':
98            $expected = "SELECT COUNT(total) FROM dtb_order "
99                       . "WHERE del_flg = 0 "
100                         . "AND to_char(create_date,'YYYY/MM/DD') = to_char(CURRENT_TIMESTAMP - interval '1 days','YYYY/MM/DD') "
101                         . "AND status <> " . ORDER_CANCEL;
102            break;
103
104        case 'mysql':
105            $expected = "SELECT COUNT(total) FROM dtb_order "
106                       . "WHERE del_flg = 0 "
107                         . "AND cast(create_date as date) = DATE_ADD(current_date, interval -1 day) "
108                         . "AND status <> " . ORDER_CANCEL;
109            break;
110
111        default:
112        }
113
114        $dbFactory = SC_DB_DBFactory::getInstance();
115        $actual = $dbFactory->getOrderYesterdaySql('COUNT');
116
117        $this->assertEquals($expected, $actual);
118    }
119
120    /**
121     * 当月の売上高・売上件数を算出する SQL のテスト.
122     */
123    function testGetOrderMonthSql()
124    {
125        switch (DB_TYPE) {
126        case 'pgsql':
127            $expected =  "SELECT COUNT(total) FROM dtb_order "
128                        . "WHERE del_flg = 0 "
129                          . "AND to_char(create_date,'YYYY/MM') = ? "
130                          . "AND to_char(create_date,'YYYY/MM/DD') <> to_char(CURRENT_TIMESTAMP,'YYYY/MM/DD') "
131                          . "AND status <> " . ORDER_CANCEL;
132            break;
133
134        case 'mysql':
135            $expected = "SELECT COUNT(total) FROM dtb_order "
136                       . "WHERE del_flg = 0 "
137                         . "AND date_format(create_date, '%Y/%m') = ? "
138                         . "AND date_format(create_date, '%Y/%m/%d') <> date_format(CURRENT_TIMESTAMP, '%Y/%m/%d') "
139                         . "AND status <> " . ORDER_CANCEL;
140            break;
141
142        default:
143        }
144
145        $dbFactory = SC_DB_DBFactory::getInstance();
146        $actual = $dbFactory->getOrderMonthSql('COUNT');
147
148        $this->assertEquals($expected, $actual);
149    }
150
151    /**
152     * 昨日のレビュー書き込み件数を算出する SQL のテスト.
153     */
154    function testGetReviewYesterdaySql()
155    {
156        switch (DB_TYPE) {
157        case 'pgsql':
158            $expected = "SELECT COUNT(*) FROM dtb_review AS A "
159                   . "LEFT JOIN dtb_products AS B "
160                          . "ON A.product_id = B.product_id "
161                       . "WHERE A.del_flg=0 "
162                         . "AND B.del_flg = 0 "
163                         . "AND to_char(A.create_date, 'YYYY/MM/DD') = to_char(CURRENT_TIMESTAMP - interval '1 days','YYYY/MM/DD') "
164                         . "AND to_char(A.create_date,'YYYY/MM/DD') != to_char(CURRENT_TIMESTAMP,'YYYY/MM/DD')";
165            break;
166
167        case 'mysql':
168            $expected = "SELECT COUNT(*) FROM dtb_review AS A "
169                   . "LEFT JOIN dtb_products AS B "
170                          . "ON A.product_id = B.product_id "
171                       . "WHERE A.del_flg = 0 "
172                         . "AND B.del_flg = 0 "
173                         . "AND cast(A.create_date as date) = DATE_ADD(current_date, interval -1 day) "
174                         . "AND cast(A.create_date as date) != current_date";
175
176            break;
177
178        default:
179        }
180
181        $dbFactory = SC_DB_DBFactory::getInstance();
182        $actual = $dbFactory->getReviewYesterdaySql();
183
184        $this->assertEquals($expected, $actual);
185    }
186}
187
188/*
189 * Local variables:
190 * coding: utf-8
191 * End:
192 */
193?>
Note: See TracBrowser for help on using the repository browser.