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