@@ -88,42 +88,27 @@ class DboSqliteTest extends CakeTestCase {
88
88
* @var DboSource
89
89
* @access public
90
90
*/
91
- public $ db = null ;
91
+ public $ Dbo = null ;
92
92
93
93
/**
94
94
* Simulated DB connection used in testing
95
95
*
96
96
* @var DboSource
97
97
* @access public
98
98
*/
99
- public $ db2 = null ;
100
-
101
- /**
102
- * Skip if cannot connect to SQLite
103
- *
104
- */
105
- public function skip () {
106
- $ this ->_initDb ();
107
- $ this ->skipUnless ($ this ->db ->config ['driver ' ] == 'sqlite ' , '%s SQLite connection not available ' );
108
- }
109
-
110
- /**
111
- * Set up test suite database connection
112
- *
113
- */
114
- public function startTest () {
115
- $ this ->_initDb ();
116
- }
99
+ public $ Dbo2 = null ;
117
100
118
101
/**
119
102
* Sets up a Dbo class instance for testing
120
103
*
121
104
*/
122
105
public function setUp () {
123
106
Configure::write ('Cache.disable ' , true );
124
- $ this ->startTest ();
125
- $ this ->db =& ConnectionManager::getDataSource ('test_suite ' );
126
- $ this ->db2 = new DboSqliteTestDb ($ this ->db ->config , false );
107
+ $ this ->Dbo = ConnectionManager::getDataSource ('test_suite ' );
108
+ if ($ this ->Dbo ->config ['driver ' ] !== 'sqlite ' ) {
109
+ $ this ->markTestSkipped ('The Sqlite extension is not available. ' );
110
+ }
111
+ $ this ->Dbo2 = new DboSqliteTestDb ($ this ->Dbo ->config , false );
127
112
}
128
113
129
114
/**
@@ -132,21 +117,21 @@ public function setUp() {
132
117
*/
133
118
public function tearDown () {
134
119
Configure::write ('Cache.disable ' , false );
135
- unset($ this ->db2 );
120
+ unset($ this ->Dbo2 );
136
121
}
137
122
138
123
/**
139
124
* Tests that SELECT queries from DboSqlite::listSources() are not cached
140
125
*
141
126
*/
142
127
public function testTableListCacheDisabling () {
143
- $ this ->assertFalse (in_array ('foo_test ' , $ this ->db ->listSources ()));
128
+ $ this ->assertFalse (in_array ('foo_test ' , $ this ->Dbo ->listSources ()));
144
129
145
- $ this ->db ->query ('CREATE TABLE foo_test (test VARCHAR(255)); ' );
146
- $ this ->assertTrue (in_array ('foo_test ' , $ this ->db ->listSources ()));
130
+ $ this ->Dbo ->query ('CREATE TABLE foo_test (test VARCHAR(255)); ' );
131
+ $ this ->assertTrue (in_array ('foo_test ' , $ this ->Dbo ->listSources ()));
147
132
148
- $ this ->db ->query ('DROP TABLE foo_test; ' );
149
- $ this ->assertFalse (in_array ('foo_test ' , $ this ->db ->listSources ()));
133
+ $ this ->Dbo ->query ('DROP TABLE foo_test; ' );
134
+ $ this ->assertFalse (in_array ('foo_test ' , $ this ->Dbo ->listSources ()));
150
135
}
151
136
152
137
/**
@@ -156,29 +141,29 @@ public function testTableListCacheDisabling() {
156
141
* @return void
157
142
*/
158
143
function testIndex () {
159
- $ name = $ this ->db ->fullTableName ('with_a_key ' );
160
- $ this ->db ->query ('CREATE TABLE ' . $ name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) ); ' );
161
- $ this ->db ->query ('CREATE INDEX pointless_bool ON ' . $ name . '("bool") ' );
162
- $ this ->db ->query ('CREATE UNIQUE INDEX char_index ON ' . $ name . '("small_char") ' );
144
+ $ name = $ this ->Dbo ->fullTableName ('with_a_key ' );
145
+ $ this ->Dbo ->query ('CREATE TABLE ' . $ name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) ); ' );
146
+ $ this ->Dbo ->query ('CREATE INDEX pointless_bool ON ' . $ name . '("bool") ' );
147
+ $ this ->Dbo ->query ('CREATE UNIQUE INDEX char_index ON ' . $ name . '("small_char") ' );
163
148
$ expected = array (
164
149
'PRIMARY ' => array ('column ' => 'id ' , 'unique ' => 1 ),
165
150
'pointless_bool ' => array ('column ' => 'bool ' , 'unique ' => 0 ),
166
151
'char_index ' => array ('column ' => 'small_char ' , 'unique ' => 1 ),
167
152
168
153
);
169
- $ result = $ this ->db ->index ($ name );
154
+ $ result = $ this ->Dbo ->index ($ name );
170
155
$ this ->assertEqual ($ expected , $ result );
171
- $ this ->db ->query ('DROP TABLE ' . $ name );
156
+ $ this ->Dbo ->query ('DROP TABLE ' . $ name );
172
157
173
- $ this ->db ->query ('CREATE TABLE ' . $ name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) ); ' );
174
- $ this ->db ->query ('CREATE UNIQUE INDEX multi_col ON ' . $ name . '("small_char", "bool") ' );
158
+ $ this ->Dbo ->query ('CREATE TABLE ' . $ name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) ); ' );
159
+ $ this ->Dbo ->query ('CREATE UNIQUE INDEX multi_col ON ' . $ name . '("small_char", "bool") ' );
175
160
$ expected = array (
176
161
'PRIMARY ' => array ('column ' => 'id ' , 'unique ' => 1 ),
177
162
'multi_col ' => array ('column ' => array ('small_char ' , 'bool ' ), 'unique ' => 1 ),
178
163
);
179
- $ result = $ this ->db ->index ($ name );
164
+ $ result = $ this ->Dbo ->index ($ name );
180
165
$ this ->assertEqual ($ expected , $ result );
181
- $ this ->db ->query ('DROP TABLE ' . $ name );
166
+ $ this ->Dbo ->query ('DROP TABLE ' . $ name );
182
167
}
183
168
184
169
/**
@@ -191,8 +176,8 @@ public function testCacheKeyName() {
191
176
$ dbName = 'db ' . rand () . '$(*%&).db ' ;
192
177
$ this ->assertFalse (file_exists (TMP . $ dbName ));
193
178
194
- $ config = $ this ->db ->config ;
195
- $ db = new DboSqlite (array_merge ($ this ->db ->config , array ('database ' => TMP . $ dbName )));
179
+ $ config = $ this ->Dbo ->config ;
180
+ $ db = new DboSqlite (array_merge ($ this ->Dbo ->config , array ('database ' => TMP . $ dbName )));
196
181
$ this ->assertTrue (file_exists (TMP . $ dbName ));
197
182
198
183
$ db ->execute ("CREATE TABLE test_list (id VARCHAR(255)); " );
@@ -221,7 +206,7 @@ function testBuildColumn() {
221
206
'type ' => 'integer ' ,
222
207
'null ' => false ,
223
208
);
224
- $ result = $ this ->db ->buildColumn ($ data );
209
+ $ result = $ this ->Dbo ->buildColumn ($ data );
225
210
$ expected = '"int_field" integer(11) NOT NULL ' ;
226
211
$ this ->assertEqual ($ result , $ expected );
227
212
@@ -231,7 +216,7 @@ function testBuildColumn() {
231
216
'length ' => 20 ,
232
217
'null ' => false ,
233
218
);
234
- $ result = $ this ->db ->buildColumn ($ data );
219
+ $ result = $ this ->Dbo ->buildColumn ($ data );
235
220
$ expected = '"name" varchar(20) NOT NULL ' ;
236
221
$ this ->assertEqual ($ result , $ expected );
237
222
@@ -243,7 +228,7 @@ function testBuildColumn() {
243
228
'null ' => true ,
244
229
'collate ' => 'NOCASE '
245
230
);
246
- $ result = $ this ->db ->buildColumn ($ data );
231
+ $ result = $ this ->Dbo ->buildColumn ($ data );
247
232
$ expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE ' ;
248
233
$ this ->assertEqual ($ result , $ expected );
249
234
@@ -254,7 +239,7 @@ function testBuildColumn() {
254
239
'default ' => 'test-value ' ,
255
240
'null ' => false ,
256
241
);
257
- $ result = $ this ->db ->buildColumn ($ data );
242
+ $ result = $ this ->Dbo ->buildColumn ($ data );
258
243
$ expected = '"testName" varchar(20) DEFAULT \'test-value \' NOT NULL ' ;
259
244
$ this ->assertEqual ($ result , $ expected );
260
245
@@ -265,7 +250,7 @@ function testBuildColumn() {
265
250
'default ' => 10 ,
266
251
'null ' => false ,
267
252
);
268
- $ result = $ this ->db ->buildColumn ($ data );
253
+ $ result = $ this ->Dbo ->buildColumn ($ data );
269
254
$ expected = '"testName" integer(10) DEFAULT \'10 \' NOT NULL ' ;
270
255
$ this ->assertEqual ($ result , $ expected );
271
256
@@ -277,7 +262,7 @@ function testBuildColumn() {
277
262
'null ' => false ,
278
263
'collate ' => 'BADVALUE '
279
264
);
280
- $ result = $ this ->db ->buildColumn ($ data );
265
+ $ result = $ this ->Dbo ->buildColumn ($ data );
281
266
$ expected = '"testName" integer(10) DEFAULT \'10 \' NOT NULL ' ;
282
267
$ this ->assertEqual ($ result , $ expected );
283
268
}
@@ -288,8 +273,9 @@ function testBuildColumn() {
288
273
* @return void
289
274
*/
290
275
function testDescribe () {
291
- $ Model =& new Model (array ('name ' => 'User ' , 'ds ' => 'test_suite ' , 'table ' => 'users ' ));
292
- $ result = $ this ->db ->describe ($ Model );
276
+ $ this ->loadFixtures ('User ' );
277
+ $ Model = new Model (array ('name ' => 'User ' , 'ds ' => 'test_suite ' , 'table ' => 'users ' ));
278
+ $ result = $ this ->Dbo ->describe ($ Model );
293
279
$ expected = array (
294
280
'id ' => array (
295
281
'type ' => 'integer ' ,
@@ -333,9 +319,9 @@ function testDescribe() {
333
319
*/
334
320
function testDescribeWithUuidPrimaryKey () {
335
321
$ tableName = 'uuid_tests ' ;
336
- $ this ->db ->query ("CREATE TABLE {$ tableName } (id VARCHAR(36) PRIMARY KEY, name VARCHAR, created DATETIME, modified DATETIME) " );
337
- $ Model =& new Model (array ('name ' => 'UuidTest ' , 'ds ' => 'test_suite ' , 'table ' => 'uuid_tests ' ));
338
- $ result = $ this ->db ->describe ($ Model );
322
+ $ this ->Dbo ->query ("CREATE TABLE {$ tableName } (id VARCHAR(36) PRIMARY KEY, name VARCHAR, created DATETIME, modified DATETIME) " );
323
+ $ Model = new Model (array ('name ' => 'UuidTest ' , 'ds ' => 'test_suite ' , 'table ' => 'uuid_tests ' ));
324
+ $ result = $ this ->Dbo ->describe ($ Model );
339
325
$ expected = array (
340
326
'type ' => 'string ' ,
341
327
'length ' => 36 ,
@@ -344,6 +330,6 @@ function testDescribeWithUuidPrimaryKey() {
344
330
'key ' => 'primary ' ,
345
331
);
346
332
$ this ->assertEqual ($ result ['id ' ], $ expected );
347
- $ this ->db ->query ('DROP TABLE ' . $ tableName );
333
+ $ this ->Dbo ->query ('DROP TABLE ' . $ tableName );
348
334
}
349
335
}
0 commit comments