mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Added test for datasource prefixes.
Fixed another instance of error in prefix replacement in CakeSchema.
This commit is contained in:
parent
52b90872df
commit
c5d763773c
4 changed files with 58 additions and 3 deletions
|
@ -257,7 +257,7 @@ class CakeSchema extends Object {
|
|||
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);
|
||||
|
|
|
@ -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 @@ class CakeSchemaTest extends CakeTestCase {
|
|||
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']));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3591,4 +3591,15 @@ class TransactionTestModel extends CakeTestModel {
|
|||
);
|
||||
$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
cake/tests/fixtures/prefix_test_fixture.php
vendored
Normal file
35
cake/tests/fixtures/prefix_test_fixture.php
vendored
Normal file
|
@ -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'),
|
||||
);
|
||||
}
|
Loading…
Reference in a new issue