Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added test for datasource prefixes.

Fixed another instance of error in prefix replacement in CakeSchema.
  • Loading branch information...
commit c5d763773c3d21ad4755abf7c026e68df1a406e2 1 parent 52b9087
@predominant predominant authored
View
2  cake/libs/model/cake_schema.php
@@ -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);
View
11 cake/tests/cases/libs/model/cake_schema.test.php
@@ -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'
);
/**
@@ -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']));
}
/**
View
13 cake/tests/cases/libs/model/models.php
@@ -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';
+}
View
35 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'),
+ );
+}
Please sign in to comment.
Something went wrong with that request. Please try again.