From 1f7c2926519b2d0ef30a89fec499bf8715b52595 Mon Sep 17 00:00:00 2001 From: Rachman Chavik Date: Tue, 8 Nov 2011 12:38:36 +0700 Subject: [PATCH] fixing broken tests: updating fullTableName() use At the same time, reversing arguments since phpunit wants 'expected' as the first parameter. --- .../Model/Datasource/Database/MysqlTest.php | 49 ++++++++++--------- .../Datasource/Database/PostgresTest.php | 4 +- .../Model/Datasource/Database/SqliteTest.php | 2 +- .../Case/Model/Datasource/DboSourceTest.php | 6 +-- .../Test/Case/Model/ModelIntegrationTest.php | 32 ++++++------ lib/Cake/Test/Case/Model/ModelReadTest.php | 10 ++-- 6 files changed, 53 insertions(+), 50 deletions(-) diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php index 16c53632a08..d43022f9483 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php @@ -660,7 +660,7 @@ public function testAlteringTableParameters() { $this->assertContains('COLLATE=utf8_general_ci', $result); $this->Dbo->rawQuery($result); - $result = $this->Dbo->listDetailedSources($this->Dbo->fullTableName('altertest', false)); + $result = $this->Dbo->listDetailedSources($this->Dbo->fullTableName('altertest', false, false)); $this->assertEquals($result['Collation'], 'utf8_general_ci'); $this->assertEquals($result['Engine'], 'InnoDB'); $this->assertEquals($result['charset'], 'utf8'); @@ -712,7 +712,7 @@ public function testReadTableParameters() { $tableName = 'tinyint_' . uniqid(); $table = $this->Dbo->fullTableName($tableName); $this->Dbo->rawQuery('CREATE TABLE ' . $table . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;'); - $result = $this->Dbo->readTableParameters($this->Dbo->fullTableName($tableName, false)); + $result = $this->Dbo->readTableParameters($this->Dbo->fullTableName($tableName, false, false)); $this->Dbo->rawQuery('DROP TABLE ' . $table); $expected = array( 'charset' => 'utf8', @@ -722,7 +722,7 @@ public function testReadTableParameters() { $table = $this->Dbo->fullTableName($tableName); $this->Dbo->rawQuery('CREATE TABLE ' . $table . ' (id int(11) AUTO_INCREMENT, bool tinyint(1), small_int tinyint(2), primary key(id)) ENGINE=MyISAM DEFAULT CHARSET=cp1250 COLLATE=cp1250_general_ci;'); - $result = $this->Dbo->readTableParameters($this->Dbo->fullTableName($tableName, false)); + $result = $this->Dbo->readTableParameters($this->Dbo->fullTableName($tableName, false, false)); $this->Dbo->rawQuery('DROP TABLE ' . $table); $expected = array( 'charset' => 'cp1250', @@ -875,7 +875,7 @@ public function testListDetailedSourcesNamed() { $this->assertEquals(array(), $result, 'Should be empty when table does not exist.'); $result = $this->Dbo->listDetailedSources(); - $tableName = $this->Dbo->fullTableName('apples', false); + $tableName = $this->Dbo->fullTableName('apples', false, false); $this->assertTrue(isset($result[$tableName]), 'Key should exist'); } @@ -928,7 +928,7 @@ public function testFieldDoubleEscaping() { $this->assertEquals($result, array('`Article`.`id`')); $test->expects($this->at(0))->method('execute') - ->with('SELECT `Article`.`id` FROM `articles` AS `Article` WHERE 1 = 1'); + ->with('SELECT `Article`.`id` FROM ' . $test->fullTableName('articles'). ' AS `Article` WHERE 1 = 1'); $result = $test->read($this->Model, array( 'fields' => $this->Model->escapeField(), @@ -944,7 +944,7 @@ public function testFieldDoubleEscaping() { $this->assertEquals($result, array('[Article].[id]')); $test->expects($this->at(0))->method('execute') - ->with('SELECT [Article].[id] FROM [' . $test->fullTableName('articles', false) . '] AS [Article] WHERE 1 = 1'); + ->with('SELECT [Article].[id] FROM ' . $test->fullTableName('articles') . ' AS [Article] WHERE 1 = 1'); $result = $test->read($this->Model, array( 'fields' => $this->Model->escapeField(), 'conditions' => null, @@ -1017,7 +1017,7 @@ public function testGenerateAssociationQuerySelfJoin() { ), 'joins' => array( array( - 'table' => '`test_model4`', + 'table' => $this->Dbo->fullTableName($this->Model), 'alias' => 'TestModel4Parent', 'type' => 'LEFT', 'conditions' => '`TestModel4`.`parent_id` = `TestModel4Parent`.`id`' @@ -1106,11 +1106,13 @@ public function testGenerateInnerJoinAssociationQuery() { ->method('getDataSource') ->will($this->returnValue($test)); + $testModel8Table = $this->Model->TestModel8->getDataSource()->fullTableName($this->Model->TestModel8); + $test->expects($this->at(0))->method('execute') - ->with($this->stringContains('`TestModel9` LEFT JOIN `test_model8`')); + ->with($this->stringContains('`TestModel9` LEFT JOIN ' . $testModel8Table)); $test->expects($this->at(1))->method('execute') - ->with($this->stringContains('TestModel9` INNER JOIN `test_model8`')); + ->with($this->stringContains('TestModel9` INNER JOIN ' . $testModel8Table)); $test->read($this->Model, array('recursive' => 1)); $this->Model->belongsTo['TestModel8']['type'] = 'INNER'; @@ -2914,10 +2916,11 @@ public function testHasAny() { ->with('harry') ->will($this->returnValue("'harry'")); + $modelTable = $this->Dbo->fullTableName($this->Model); $this->Dbo->expects($this->at(1))->method('execute') - ->with('SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE `TestModel`.`name` = \'harry\''); + ->with('SELECT COUNT(`TestModel`.`id`) AS count FROM ' .$modelTable. ' AS `TestModel` WHERE `TestModel`.`name` = \'harry\''); $this->Dbo->expects($this->at(2))->method('execute') - ->with('SELECT COUNT(`TestModel`.`id`) AS count FROM `test_models` AS `TestModel` WHERE 1 = 1'); + ->with('SELECT COUNT(`TestModel`.`id`) AS count FROM ' .$modelTable. ' AS `TestModel` WHERE 1 = 1'); $this->Dbo->hasAny($this->Model, array('TestModel.name' => 'harry')); $this->Dbo->hasAny($this->Model, array()); @@ -2933,7 +2936,7 @@ public function testVirtualFields() { $this->loadFixtures('Article', 'Comment', 'Tag'); $this->Dbo->virtualFieldSeparator = '__'; $Article = ClassRegistry::init('Article'); - $commentsTable = $this->Dbo->fullTableName('comments', false); + $commentsTable = $this->Dbo->fullTableName('comments', false, false); $Article->virtualFields = array( 'this_moment' => 'NOW()', 'two' => '1 + 1', @@ -3003,7 +3006,7 @@ public function testVirtualFields() { */ public function testVirtualFieldsInConditions() { $Article = ClassRegistry::init('Article'); - $commentsTable = $this->Dbo->fullTableName('comments', false); + $commentsTable = $this->Dbo->fullTableName('comments', false, false); $Article->virtualFields = array( 'this_moment' => 'NOW()', @@ -3062,7 +3065,7 @@ public function testConditionsWithComplexVirtualFields() { */ public function testVirtualFieldsInCalculate() { $Article = ClassRegistry::init('Article'); - $commentsTable = $this->Dbo->fullTableName('comments', false); + $commentsTable = $this->Dbo->fullTableName('comments', false, false); $Article->virtualFields = array( 'this_moment' => 'NOW()', 'two' => '1 + 1', @@ -3393,7 +3396,7 @@ public function testRealQueries() { $this->assertTrue(!empty($result)); $result = $this->Dbo->fetchRow($result); - $expected = array($this->Dbo->fullTableName('apples', false) => array( + $expected = array($this->Dbo->fullTableName('apples', false, false) => array( 'color' => 'Red 1', 'name' => 'Red Apple 1' )); @@ -3401,17 +3404,17 @@ public function testRealQueries() { $result = $this->Dbo->fetchAll('SELECT name FROM ' . $this->Dbo->fullTableName('apples') . ' ORDER BY id'); $expected = array( - array($this->Dbo->fullTableName('apples', false) => array('name' => 'Red Apple 1')), - array($this->Dbo->fullTableName('apples', false) => array('name' => 'Bright Red Apple')), - array($this->Dbo->fullTableName('apples', false) => array('name' => 'green blue')), - array($this->Dbo->fullTableName('apples', false) => array('name' => 'Test Name')), - array($this->Dbo->fullTableName('apples', false) => array('name' => 'Blue Green')), - array($this->Dbo->fullTableName('apples', false) => array('name' => 'My new apple')), - array($this->Dbo->fullTableName('apples', false) => array('name' => 'Some odd color')) + array($this->Dbo->fullTableName('apples', false, false) => array('name' => 'Red Apple 1')), + array($this->Dbo->fullTableName('apples', false, false) => array('name' => 'Bright Red Apple')), + array($this->Dbo->fullTableName('apples', false, false) => array('name' => 'green blue')), + array($this->Dbo->fullTableName('apples', false, false) => array('name' => 'Test Name')), + array($this->Dbo->fullTableName('apples', false, false) => array('name' => 'Blue Green')), + array($this->Dbo->fullTableName('apples', false, false) => array('name' => 'My new apple')), + array($this->Dbo->fullTableName('apples', false, false) => array('name' => 'Some odd color')) ); $this->assertEquals($expected, $result); - $result = $this->Dbo->field($this->Dbo->fullTableName('apples', false), 'SELECT color, name FROM ' . $this->Dbo->fullTableName('apples') . ' ORDER BY id'); + $result = $this->Dbo->field($this->Dbo->fullTableName('apples', false, false), 'SELECT color, name FROM ' . $this->Dbo->fullTableName('apples') . ' ORDER BY id'); $expected = array( 'color' => 'Red 1', 'name' => 'Red Apple 1' diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php index 6469dd1afc9..32859850e38 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php @@ -566,7 +566,7 @@ public function testCakeSchema() { * @return void */ public function testIndexGeneration() { - $name = $this->Dbo->fullTableName('index_test', false); + $name = $this->Dbo->fullTableName('index_test', false, false); $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" serial NOT NULL PRIMARY KEY, "bool" integer, "small_char" varchar(50), "description" varchar(40) )'); $this->Dbo->query('CREATE INDEX pointless_bool ON ' . $name . '("bool")'); $this->Dbo->query('CREATE UNIQUE INDEX char_index ON ' . $name . '("small_char")'); @@ -579,7 +579,7 @@ public function testIndexGeneration() { $this->Dbo->query('DROP TABLE ' . $name); $this->assertEquals($expected, $result); - $name = $this->Dbo->fullTableName('index_test_2', false); + $name = $this->Dbo->fullTableName('index_test_2', false, false); $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" serial NOT NULL PRIMARY KEY, "bool" integer, "small_char" varchar(50), "description" varchar(40) )'); $this->Dbo->query('CREATE UNIQUE INDEX multi_col ON ' . $name . '("small_char", "bool")'); $expected = array( diff --git a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php index 95fc709bdf5..439aa6b4bc4 100644 --- a/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/Database/SqliteTest.php @@ -128,7 +128,7 @@ public function testTableListCacheDisabling() { * @return void */ public function testIndex() { - $name = $this->Dbo->fullTableName('with_a_key'); + $name = $this->Dbo->fullTableName('with_a_key', false, false); $this->Dbo->query('CREATE TABLE ' . $name . ' ("id" int(11) PRIMARY KEY, "bool" int(1), "small_char" varchar(50), "description" varchar(40) );'); $this->Dbo->query('CREATE INDEX pointless_bool ON ' . $name . '("bool")'); $this->Dbo->query('CREATE UNIQUE INDEX char_index ON ' . $name . '("small_char")'); diff --git a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php index 6fc217c0960..73c623e32be 100644 --- a/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php +++ b/lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php @@ -697,16 +697,16 @@ public function testVirtualFieldsInOrder() { */ public function testFullTablePermutations() { $Article = ClassRegistry::init('Article'); - $result = $this->testDb->fullTableName($Article, false); + $result = $this->testDb->fullTableName($Article, false, false); $this->assertEquals($result, 'articles'); $Article->tablePrefix = 'tbl_'; - $result = $this->testDb->fullTableName($Article, false); + $result = $this->testDb->fullTableName($Article, false, false); $this->assertEquals($result, 'tbl_articles'); $Article->useTable = $Article->table = 'with spaces'; $Article->tablePrefix = ''; - $result = $this->testDb->fullTableName($Article); + $result = $this->testDb->fullTableName($Article, true, false); $this->assertEquals($result, '`with spaces`'); } diff --git a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php index cf2cfbe2530..da2a368701b 100644 --- a/lib/Cake/Test/Case/Model/ModelIntegrationTest.php +++ b/lib/Cake/Test/Case/Model/ModelIntegrationTest.php @@ -944,39 +944,39 @@ public function testTablePrefixSwitching() { $TestModel = new Apple(); $TestModel->setDataSource('database1'); - $this->assertEquals($this->db->fullTableName($TestModel, false), 'aaa_apples'); - $this->assertEquals($db1->fullTableName($TestModel, false), 'aaa_apples'); - $this->assertEquals($db2->fullTableName($TestModel, false), 'aaa_apples'); + $this->assertContains('aaa_apples', $this->db->fullTableName($TestModel)); + $this->assertContains('aaa_apples', $db1->fullTableName($TestModel)); + $this->assertContains('aaa_apples', $db2->fullTableName($TestModel)); $TestModel->setDataSource('database2'); - $this->assertEquals($this->db->fullTableName($TestModel, false), 'bbb_apples'); - $this->assertEquals($db1->fullTableName($TestModel, false), 'bbb_apples'); - $this->assertEquals($db2->fullTableName($TestModel, false), 'bbb_apples'); + $this->assertContains('bbb_apples', $this->db->fullTableName($TestModel)); + $this->assertContains('bbb_apples', $db1->fullTableName($TestModel)); + $this->assertContains('bbb_apples', $db2->fullTableName($TestModel)); $TestModel = new Apple(); $TestModel->tablePrefix = 'custom_'; - $this->assertEquals($this->db->fullTableName($TestModel, false), 'custom_apples'); + $this->assertContains('custom_apples', $this->db->fullTableName($TestModel)); $TestModel->setDataSource('database1'); - $this->assertEquals($this->db->fullTableName($TestModel, false), 'custom_apples'); - $this->assertEquals($db1->fullTableName($TestModel, false), 'custom_apples'); + $this->assertContains('custom_apples', $this->db->fullTableName($TestModel)); + $this->assertContains('custom_apples', $db1->fullTableName($TestModel)); $TestModel = new Apple(); $TestModel->setDataSource('database1'); - $this->assertEquals($this->db->fullTableName($TestModel, false), 'aaa_apples'); + $this->assertContains('aaa_apples', $this->db->fullTableName($TestModel)); $TestModel->tablePrefix = ''; $TestModel->setDataSource('database2'); - $this->assertEquals($db2->fullTableName($TestModel, false), 'apples'); - $this->assertEquals($db1->fullTableName($TestModel, false), 'apples'); + $this->assertContains('apples', $db2->fullTableName($TestModel)); + $this->assertContains('apples', $db1->fullTableName($TestModel)); $TestModel->tablePrefix = null; $TestModel->setDataSource('database1'); - $this->assertEquals($db2->fullTableName($TestModel, false), 'aaa_apples'); - $this->assertEquals($db1->fullTableName($TestModel, false), 'aaa_apples'); + $this->assertContains('aaa_apples', $db2->fullTableName($TestModel)); + $this->assertContains('aaa_apples', $db1->fullTableName($TestModel)); $TestModel->tablePrefix = false; $TestModel->setDataSource('database2'); - $this->assertEquals($db2->fullTableName($TestModel, false), 'apples'); - $this->assertEquals($db1->fullTableName($TestModel, false), 'apples'); + $this->assertContains('apples', $db2->fullTableName($TestModel)); + $this->assertContains('apples', $db1->fullTableName($TestModel)); } /** diff --git a/lib/Cake/Test/Case/Model/ModelReadTest.php b/lib/Cake/Test/Case/Model/ModelReadTest.php index d45b910856a..ea3c4e0b22d 100644 --- a/lib/Cake/Test/Case/Model/ModelReadTest.php +++ b/lib/Cake/Test/Case/Model/ModelReadTest.php @@ -282,13 +282,13 @@ public function testPreparedQuery() { $result = $Article->query($query, $params); $expected = array( '0' => array( - $this->db->fullTableName('articles', false) => array( + $this->db->fullTableName('articles', false, false) => array( 'title' => 'First Article', 'published' => 'Y') )); if (isset($result[0][0])) { - $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false)]; - unset($expected[0][$this->db->fullTableName('articles', false)]); + $expected[0][0] = $expected[0][$this->db->fullTableName('articles', false, false)]; + unset($expected[0][$this->db->fullTableName('articles', false, false)]); } $this->assertEquals($expected, $result); @@ -303,7 +303,7 @@ public function testPreparedQuery() { $result = $Article->query($query, $params, false); $this->assertTrue(is_array($result)); $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false)]) + isset($result[0][$this->db->fullTableName('articles', false, false)]) || isset($result[0][0]) ); $result = $this->db->getQueryCache($query, $params); @@ -317,7 +317,7 @@ public function testPreparedQuery() { $result = $Article->query($query, $params); $this->assertTrue(is_array($result)); $this->assertTrue( - isset($result[0][$this->db->fullTableName('articles', false)]['title']) + isset($result[0][$this->db->fullTableName('articles', false, false)]['title']) || isset($result[0][0]['title']) );