mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
fix fullTableName duplicate prefix, closes #2355
This commit is contained in:
parent
d2eac08e6b
commit
a8d0447e61
3 changed files with 68 additions and 1 deletions
|
@ -920,7 +920,7 @@ class DboSource extends DataSource {
|
|||
if (is_object($model)) {
|
||||
$schemaName = $model->schemaName;
|
||||
$table = $model->tablePrefix . $model->table;
|
||||
} elseif (isset($this->config['prefix'])) {
|
||||
} elseif (!empty($this->config['prefix']) && strpos($model, $this->config['prefix']) === false) {
|
||||
$table = $this->config['prefix'] . strval($model);
|
||||
} else {
|
||||
$table = strval($model);
|
||||
|
|
|
@ -3540,4 +3540,37 @@ class MysqlTest extends CakeTestCase {
|
|||
$this->Dbo->delete($Article, true);
|
||||
$this->Dbo->delete($Article, '2=2');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test truncate with a mock.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTruncateStatements() {
|
||||
$this->loadFixtures('Article', 'User');
|
||||
$db = ConnectionManager::getDatasource('test');
|
||||
$schema = $db->config['database'];
|
||||
$Article = new Article();
|
||||
|
||||
$this->Dbo = $this->getMock('Mysql', array('execute'), array($db->config));
|
||||
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("TRUNCATE TABLE `$schema`.`articles`");
|
||||
$this->Dbo->truncate($Article);
|
||||
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("TRUNCATE TABLE `$schema`.`articles`");
|
||||
$this->Dbo->truncate('articles');
|
||||
|
||||
// #2355: prevent duplicate prefix
|
||||
$this->Dbo->config['prefix'] = 'tbl_';
|
||||
$Article->tablePrefix = 'tbl_';
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("TRUNCATE TABLE `$schema`.`tbl_articles`");
|
||||
$this->Dbo->truncate($Article);
|
||||
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("TRUNCATE TABLE `$schema`.`tbl_articles`");
|
||||
$this->Dbo->truncate('articles');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -871,4 +871,38 @@ class PostgresTest extends CakeTestCase {
|
|||
$result = $this->Dbo->getEncoding();
|
||||
$this->assertEquals('EUC-JP', $result) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test truncate with a mock.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testTruncateStatements() {
|
||||
$this->loadFixtures('Article', 'User');
|
||||
$db = ConnectionManager::getDatasource('test');
|
||||
$schema = $db->config['schema'];
|
||||
$Article = new Article();
|
||||
|
||||
$this->Dbo = $this->getMock('Postgres', array('execute'), array($db->config));
|
||||
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("DELETE FROM \"$schema\".\"articles\"");
|
||||
$this->Dbo->truncate($Article);
|
||||
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("DELETE FROM \"$schema\".\"articles\"");
|
||||
$this->Dbo->truncate('articles');
|
||||
|
||||
// #2355: prevent duplicate prefix
|
||||
$this->Dbo->config['prefix'] = 'tbl_';
|
||||
$Article->tablePrefix = 'tbl_';
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("DELETE FROM \"$schema\".\"tbl_articles\"");
|
||||
$this->Dbo->truncate($Article);
|
||||
|
||||
$this->Dbo->expects($this->at(0))->method('execute')
|
||||
->with("DELETE FROM \"$schema\".\"tbl_articles\"");
|
||||
$this->Dbo->truncate('articles');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue