Skip to content

Commit d35e02a

Browse files
committed
Sending correct patch for previous commit
1 parent f4cf945 commit d35e02a

File tree

1 file changed

+38
-52
lines changed

1 file changed

+38
-52
lines changed

cake/tests/cases/libs/model/datasources/dbo/dbo_sqlite.test.php

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -88,42 +88,27 @@ class DboSqliteTest extends CakeTestCase {
8888
* @var DboSource
8989
* @access public
9090
*/
91-
public $db = null;
91+
public $Dbo = null;
9292

9393
/**
9494
* Simulated DB connection used in testing
9595
*
9696
* @var DboSource
9797
* @access public
9898
*/
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;
117100

118101
/**
119102
* Sets up a Dbo class instance for testing
120103
*
121104
*/
122105
public function setUp() {
123106
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);
127112
}
128113

129114
/**
@@ -132,21 +117,21 @@ public function setUp() {
132117
*/
133118
public function tearDown() {
134119
Configure::write('Cache.disable', false);
135-
unset($this->db2);
120+
unset($this->Dbo2);
136121
}
137122

138123
/**
139124
* Tests that SELECT queries from DboSqlite::listSources() are not cached
140125
*
141126
*/
142127
public function testTableListCacheDisabling() {
143-
$this->assertFalse(in_array('foo_test', $this->db->listSources()));
128+
$this->assertFalse(in_array('foo_test', $this->Dbo->listSources()));
144129

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()));
147132

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()));
150135
}
151136

152137
/**
@@ -156,29 +141,29 @@ public function testTableListCacheDisabling() {
156141
* @return void
157142
*/
158143
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")');
163148
$expected = array(
164149
'PRIMARY' => array('column' => 'id', 'unique' => 1),
165150
'pointless_bool' => array('column' => 'bool', 'unique' => 0),
166151
'char_index' => array('column' => 'small_char', 'unique' => 1),
167152

168153
);
169-
$result = $this->db->index($name);
154+
$result = $this->Dbo->index($name);
170155
$this->assertEqual($expected, $result);
171-
$this->db->query('DROP TABLE ' . $name);
156+
$this->Dbo->query('DROP TABLE ' . $name);
172157

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")');
175160
$expected = array(
176161
'PRIMARY' => array('column' => 'id', 'unique' => 1),
177162
'multi_col' => array('column' => array('small_char', 'bool'), 'unique' => 1),
178163
);
179-
$result = $this->db->index($name);
164+
$result = $this->Dbo->index($name);
180165
$this->assertEqual($expected, $result);
181-
$this->db->query('DROP TABLE ' . $name);
166+
$this->Dbo->query('DROP TABLE ' . $name);
182167
}
183168

184169
/**
@@ -191,8 +176,8 @@ public function testCacheKeyName() {
191176
$dbName = 'db' . rand() . '$(*%&).db';
192177
$this->assertFalse(file_exists(TMP . $dbName));
193178

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)));
196181
$this->assertTrue(file_exists(TMP . $dbName));
197182

198183
$db->execute("CREATE TABLE test_list (id VARCHAR(255));");
@@ -221,7 +206,7 @@ function testBuildColumn() {
221206
'type' => 'integer',
222207
'null' => false,
223208
);
224-
$result = $this->db->buildColumn($data);
209+
$result = $this->Dbo->buildColumn($data);
225210
$expected = '"int_field" integer(11) NOT NULL';
226211
$this->assertEqual($result, $expected);
227212

@@ -231,7 +216,7 @@ function testBuildColumn() {
231216
'length' => 20,
232217
'null' => false,
233218
);
234-
$result = $this->db->buildColumn($data);
219+
$result = $this->Dbo->buildColumn($data);
235220
$expected = '"name" varchar(20) NOT NULL';
236221
$this->assertEqual($result, $expected);
237222

@@ -243,7 +228,7 @@ function testBuildColumn() {
243228
'null' => true,
244229
'collate' => 'NOCASE'
245230
);
246-
$result = $this->db->buildColumn($data);
231+
$result = $this->Dbo->buildColumn($data);
247232
$expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE';
248233
$this->assertEqual($result, $expected);
249234

@@ -254,7 +239,7 @@ function testBuildColumn() {
254239
'default' => 'test-value',
255240
'null' => false,
256241
);
257-
$result = $this->db->buildColumn($data);
242+
$result = $this->Dbo->buildColumn($data);
258243
$expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL';
259244
$this->assertEqual($result, $expected);
260245

@@ -265,7 +250,7 @@ function testBuildColumn() {
265250
'default' => 10,
266251
'null' => false,
267252
);
268-
$result = $this->db->buildColumn($data);
253+
$result = $this->Dbo->buildColumn($data);
269254
$expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL';
270255
$this->assertEqual($result, $expected);
271256

@@ -277,7 +262,7 @@ function testBuildColumn() {
277262
'null' => false,
278263
'collate' => 'BADVALUE'
279264
);
280-
$result = $this->db->buildColumn($data);
265+
$result = $this->Dbo->buildColumn($data);
281266
$expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL';
282267
$this->assertEqual($result, $expected);
283268
}
@@ -288,8 +273,9 @@ function testBuildColumn() {
288273
* @return void
289274
*/
290275
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);
293279
$expected = array(
294280
'id' => array(
295281
'type' => 'integer',
@@ -333,9 +319,9 @@ function testDescribe() {
333319
*/
334320
function testDescribeWithUuidPrimaryKey() {
335321
$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);
339325
$expected = array(
340326
'type' => 'string',
341327
'length' => 36,
@@ -344,6 +330,6 @@ function testDescribeWithUuidPrimaryKey() {
344330
'key' => 'primary',
345331
);
346332
$this->assertEqual($result['id'], $expected);
347-
$this->db->query('DROP TABLE ' . $tableName);
333+
$this->Dbo->query('DROP TABLE ' . $tableName);
348334
}
349335
}

0 commit comments

Comments
 (0)