Sending correct patch for previous commit

This commit is contained in:
José Lorenzo Rodríguez 2010-06-10 00:02:45 -04:30
parent f4cf945e30
commit d35e02a1e1

View file

@ -88,7 +88,7 @@ class DboSqliteTest extends CakeTestCase {
* @var DboSource * @var DboSource
* @access public * @access public
*/ */
public $db = null; public $Dbo = null;
/** /**
* Simulated DB connection used in testing * Simulated DB connection used in testing
@ -96,24 +96,7 @@ class DboSqliteTest extends CakeTestCase {
* @var DboSource * @var DboSource
* @access public * @access public
*/ */
public $db2 = null; public $Dbo2 = null;
/**
* Skip if cannot connect to SQLite
*
*/
public function skip() {
$this->_initDb();
$this->skipUnless($this->db->config['driver'] == 'sqlite', '%s SQLite connection not available');
}
/**
* Set up test suite database connection
*
*/
public function startTest() {
$this->_initDb();
}
/** /**
* Sets up a Dbo class instance for testing * Sets up a Dbo class instance for testing
@ -121,9 +104,11 @@ class DboSqliteTest extends CakeTestCase {
*/ */
public function setUp() { public function setUp() {
Configure::write('Cache.disable', true); Configure::write('Cache.disable', true);
$this->startTest(); $this->Dbo = ConnectionManager::getDataSource('test_suite');
$this->db =& ConnectionManager::getDataSource('test_suite'); if ($this->Dbo->config['driver'] !== 'sqlite') {
$this->db2 = new DboSqliteTestDb($this->db->config, false); $this->markTestSkipped('The Sqlite extension is not available.');
}
$this->Dbo2 = new DboSqliteTestDb($this->Dbo->config, false);
} }
/** /**
@ -132,7 +117,7 @@ class DboSqliteTest extends CakeTestCase {
*/ */
public function tearDown() { public function tearDown() {
Configure::write('Cache.disable', false); Configure::write('Cache.disable', false);
unset($this->db2); unset($this->Dbo2);
} }
/** /**
@ -140,13 +125,13 @@ class DboSqliteTest extends CakeTestCase {
* *
*/ */
public function testTableListCacheDisabling() { public function testTableListCacheDisabling() {
$this->assertFalse(in_array('foo_test', $this->db->listSources())); $this->assertFalse(in_array('foo_test', $this->Dbo->listSources()));
$this->db->query('CREATE TABLE foo_test (test VARCHAR(255));'); $this->Dbo->query('CREATE TABLE foo_test (test VARCHAR(255));');
$this->assertTrue(in_array('foo_test', $this->db->listSources())); $this->assertTrue(in_array('foo_test', $this->Dbo->listSources()));
$this->db->query('DROP TABLE foo_test;'); $this->Dbo->query('DROP TABLE foo_test;');
$this->assertFalse(in_array('foo_test', $this->db->listSources())); $this->assertFalse(in_array('foo_test', $this->Dbo->listSources()));
} }
/** /**
@ -156,29 +141,29 @@ class DboSqliteTest extends CakeTestCase {
* @return void * @return void
*/ */
function testIndex() { function testIndex() {
$name = $this->db->fullTableName('with_a_key'); $name = $this->Dbo->fullTableName('with_a_key');
$this->db->query('CREATE TABLE ' . $name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) );'); $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) );');
$this->db->query('CREATE INDEX pointless_bool ON ' . $name . '("bool")'); $this->Dbo->query('CREATE INDEX pointless_bool ON ' . $name . '("bool")');
$this->db->query('CREATE UNIQUE INDEX char_index ON ' . $name . '("small_char")'); $this->Dbo->query('CREATE UNIQUE INDEX char_index ON ' . $name . '("small_char")');
$expected = array( $expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1), 'PRIMARY' => array('column' => 'id', 'unique' => 1),
'pointless_bool' => array('column' => 'bool', 'unique' => 0), 'pointless_bool' => array('column' => 'bool', 'unique' => 0),
'char_index' => array('column' => 'small_char', 'unique' => 1), 'char_index' => array('column' => 'small_char', 'unique' => 1),
); );
$result = $this->db->index($name); $result = $this->Dbo->index($name);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name); $this->Dbo->query('DROP TABLE ' . $name);
$this->db->query('CREATE TABLE ' . $name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) );'); $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) );');
$this->db->query('CREATE UNIQUE INDEX multi_col ON ' . $name . '("small_char", "bool")'); $this->Dbo->query('CREATE UNIQUE INDEX multi_col ON ' . $name . '("small_char", "bool")');
$expected = array( $expected = array(
'PRIMARY' => array('column' => 'id', 'unique' => 1), 'PRIMARY' => array('column' => 'id', 'unique' => 1),
'multi_col' => array('column' => array('small_char', 'bool'), 'unique' => 1), 'multi_col' => array('column' => array('small_char', 'bool'), 'unique' => 1),
); );
$result = $this->db->index($name); $result = $this->Dbo->index($name);
$this->assertEqual($expected, $result); $this->assertEqual($expected, $result);
$this->db->query('DROP TABLE ' . $name); $this->Dbo->query('DROP TABLE ' . $name);
} }
/** /**
@ -191,8 +176,8 @@ class DboSqliteTest extends CakeTestCase {
$dbName = 'db' . rand() . '$(*%&).db'; $dbName = 'db' . rand() . '$(*%&).db';
$this->assertFalse(file_exists(TMP . $dbName)); $this->assertFalse(file_exists(TMP . $dbName));
$config = $this->db->config; $config = $this->Dbo->config;
$db = new DboSqlite(array_merge($this->db->config, array('database' => TMP . $dbName))); $db = new DboSqlite(array_merge($this->Dbo->config, array('database' => TMP . $dbName)));
$this->assertTrue(file_exists(TMP . $dbName)); $this->assertTrue(file_exists(TMP . $dbName));
$db->execute("CREATE TABLE test_list (id VARCHAR(255));"); $db->execute("CREATE TABLE test_list (id VARCHAR(255));");
@ -221,7 +206,7 @@ class DboSqliteTest extends CakeTestCase {
'type' => 'integer', 'type' => 'integer',
'null' => false, 'null' => false,
); );
$result = $this->db->buildColumn($data); $result = $this->Dbo->buildColumn($data);
$expected = '"int_field" integer(11) NOT NULL'; $expected = '"int_field" integer(11) NOT NULL';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -231,7 +216,7 @@ class DboSqliteTest extends CakeTestCase {
'length' => 20, 'length' => 20,
'null' => false, 'null' => false,
); );
$result = $this->db->buildColumn($data); $result = $this->Dbo->buildColumn($data);
$expected = '"name" varchar(20) NOT NULL'; $expected = '"name" varchar(20) NOT NULL';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -243,7 +228,7 @@ class DboSqliteTest extends CakeTestCase {
'null' => true, 'null' => true,
'collate' => 'NOCASE' 'collate' => 'NOCASE'
); );
$result = $this->db->buildColumn($data); $result = $this->Dbo->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE'; $expected = '"testName" varchar(20) DEFAULT NULL COLLATE NOCASE';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -254,7 +239,7 @@ class DboSqliteTest extends CakeTestCase {
'default' => 'test-value', 'default' => 'test-value',
'null' => false, 'null' => false,
); );
$result = $this->db->buildColumn($data); $result = $this->Dbo->buildColumn($data);
$expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL'; $expected = '"testName" varchar(20) DEFAULT \'test-value\' NOT NULL';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -265,7 +250,7 @@ class DboSqliteTest extends CakeTestCase {
'default' => 10, 'default' => 10,
'null' => false, 'null' => false,
); );
$result = $this->db->buildColumn($data); $result = $this->Dbo->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL'; $expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
@ -277,7 +262,7 @@ class DboSqliteTest extends CakeTestCase {
'null' => false, 'null' => false,
'collate' => 'BADVALUE' 'collate' => 'BADVALUE'
); );
$result = $this->db->buildColumn($data); $result = $this->Dbo->buildColumn($data);
$expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL'; $expected = '"testName" integer(10) DEFAULT \'10\' NOT NULL';
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
@ -288,8 +273,9 @@ class DboSqliteTest extends CakeTestCase {
* @return void * @return void
*/ */
function testDescribe() { function testDescribe() {
$Model =& new Model(array('name' => 'User', 'ds' => 'test_suite', 'table' => 'users')); $this->loadFixtures('User');
$result = $this->db->describe($Model); $Model = new Model(array('name' => 'User', 'ds' => 'test_suite', 'table' => 'users'));
$result = $this->Dbo->describe($Model);
$expected = array( $expected = array(
'id' => array( 'id' => array(
'type' => 'integer', 'type' => 'integer',
@ -333,9 +319,9 @@ class DboSqliteTest extends CakeTestCase {
*/ */
function testDescribeWithUuidPrimaryKey() { function testDescribeWithUuidPrimaryKey() {
$tableName = 'uuid_tests'; $tableName = 'uuid_tests';
$this->db->query("CREATE TABLE {$tableName} (id VARCHAR(36) PRIMARY KEY, name VARCHAR, created DATETIME, modified DATETIME)"); $this->Dbo->query("CREATE TABLE {$tableName} (id VARCHAR(36) PRIMARY KEY, name VARCHAR, created DATETIME, modified DATETIME)");
$Model =& new Model(array('name' => 'UuidTest', 'ds' => 'test_suite', 'table' => 'uuid_tests')); $Model = new Model(array('name' => 'UuidTest', 'ds' => 'test_suite', 'table' => 'uuid_tests'));
$result = $this->db->describe($Model); $result = $this->Dbo->describe($Model);
$expected = array( $expected = array(
'type' => 'string', 'type' => 'string',
'length' => 36, 'length' => 36,
@ -344,6 +330,6 @@ class DboSqliteTest extends CakeTestCase {
'key' => 'primary', 'key' => 'primary',
); );
$this->assertEqual($result['id'], $expected); $this->assertEqual($result['id'], $expected);
$this->db->query('DROP TABLE ' . $tableName); $this->Dbo->query('DROP TABLE ' . $tableName);
} }
} }