Skip to content

Commit

Permalink
fixing broken tests: updating fullTableName() use
Browse files Browse the repository at this point in the history
At the same time, reversing arguments since phpunit wants 'expected' as
the first parameter.
  • Loading branch information
rchavik committed Nov 25, 2011
1 parent c4cbf1c commit 1f7c292
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 50 deletions.
49 changes: 26 additions & 23 deletions lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php
Expand Up @@ -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');
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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');
}

Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand Down Expand Up @@ -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`'
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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());
Expand All @@ -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',
Expand Down Expand Up @@ -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()',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -3393,25 +3396,25 @@ 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'
));
$this->assertEquals($expected, $result);

$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'
Expand Down
4 changes: 2 additions & 2 deletions lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php
Expand Up @@ -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")');
Expand All @@ -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(
Expand Down
Expand Up @@ -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")');
Expand Down
6 changes: 3 additions & 3 deletions lib/Cake/Test/Case/Model/Datasource/DboSourceTest.php
Expand Up @@ -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`');
}

Expand Down
32 changes: 16 additions & 16 deletions lib/Cake/Test/Case/Model/ModelIntegrationTest.php
Expand Up @@ -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));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/Cake/Test/Case/Model/ModelReadTest.php
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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'])
);

Expand Down

0 comments on commit 1f7c292

Please sign in to comment.