Skip to content

Commit

Permalink
Added test for datasource prefixes.
Browse files Browse the repository at this point in the history
Fixed another instance of error in prefix replacement in CakeSchema.
  • Loading branch information
predominant committed May 31, 2011
1 parent 52b9087 commit c5d7637
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cake/libs/model/cake_schema.php
Expand Up @@ -257,7 +257,7 @@ function read($options = array()) {
if ($prefix && strpos($table, $prefix) !== 0) {
continue;
}
$table = str_replace($prefix, '', $table);
$table = preg_replace('/^' . preg_quote($prefix) . '/', '', $table);

if (in_array($fulltable, $currentTables)) {
$key = array_search($fulltable, $currentTables);
Expand Down
11 changes: 10 additions & 1 deletion cake/tests/cases/libs/model/cake_schema.test.php
Expand Up @@ -493,7 +493,8 @@ class CakeSchemaTest extends CakeTestCase {
var $fixtures = array(
'core.post', 'core.tag', 'core.posts_tag', 'core.test_plugin_comment',
'core.datatype', 'core.auth_user', 'core.author',
'core.test_plugin_article', 'core.user', 'core.comment'
'core.test_plugin_article', 'core.user', 'core.comment',
'core.prefix_test'
);

/**
Expand Down Expand Up @@ -609,6 +610,14 @@ function testSchemaReadWithConfigPrefix() {
ConnectionManager::create('schema_prefix', $config);
$read = $this->Schema->read(array('connection' => 'schema_prefix', 'models' => false));
$this->assertTrue(empty($read['tables']));

$config['prefix'] = 'prefix_';
ConnectionManager::create('schema_prefix2', $config);
$read = $this->Schema->read(array(
'connection' => 'schema_prefix2',
'name' => 'TestApp',
'models' => false));
$this->assertTrue(isset($read['tables']['prefix_tests']));
}

/**
Expand Down
13 changes: 12 additions & 1 deletion cake/tests/cases/libs/model/models.php
Expand Up @@ -3591,4 +3591,15 @@ function afterSave($created) {
);
$this->saveAll($data, array('atomic' => true, 'callbacks' => false));
}
}
}

/**
* Test model for datasource prefixes
*
*/
class PrefixTestModel extends CakeTestModel {
}
class PrefixTestUseTableModel extends CakeTestModel {
var $name = 'PrefixTest';
var $useTable = 'prefix_tests';
}
35 changes: 35 additions & 0 deletions cake/tests/fixtures/prefix_test_fixture.php
@@ -0,0 +1,35 @@
<?php
/**
* Short description for file.
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing>
* Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright 2005-2011, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests
* @package cake
* @subpackage cake.tests.fixtures
* @since CakePHP(tm) v 1.2.0.4667
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/

/**
* Short description for class.
*
* @package cake
* @subpackage cake.tests.fixtures
*/
class PrefixTestFixture extends CakeTestFixture {

var $name = 'PrefixTest';
var $table = 'prefix_prefix_tests';

var $fields = array(
'id' => array('type' => 'integer', 'key' => 'primary'),
);
}

0 comments on commit c5d7637

Please sign in to comment.