cakephp2でpostgresqlを使ってテストするときにprefixをつけた場合

環境
  1. postgres (PostgreSQL) 8.1.23
  2. PHP 5.3.8 (cli) (built: Sep 30 2011 20:23:54) 
  3. PHPUnit 3.5.15 by Sebastian Bergmann.
  4. cake2.0.4

例えば'prefix' => 'prf_',として、モデルのテスト実行した時、
Articleモデルがあったとしたら、

コンソールで
$cake testsuite app Model/Article
とすると、
Undefined table: 7 ERROR:  relation "prf_prf_articles" does not exist
と2つprefixがついてしまいます。

fixされました。

https://github.com/cakephp/cakephp/commit/c3f17c24f39e683d0032429e50ad193a878f88b4


hiromi2424さんのおかげで報告できました。(_ _)
英語に自信がなくてもできるCakePHPへの貢献 -バグ報告編-
http://d.hatena.ne.jp/hiromi2424/20111204/1322984803





Model/Datasource/Database/Postgres.phpを修正
/**
* Deletes all the records in a table and drops all associated auto-increment sequences
*
* @param mixed $table A string or model class representing the table to be truncated
* @param boolean $reset true for resseting the sequence, false to leave it as is.
* and if 1, sequences are not modified
* @return boolean SQL TRUNCATE TABLE statement, false if not applicable.
*/
public function truncate($table, $reset = 0) {
$table = $this->fullTableName($table, false);
if (!isset($this->_sequenceMap[$table])) {
$cache = $this->cacheSources;
$this->cacheSources = false;
$this->describe($table);
$this->cacheSources = $cache;
}
// if ($this->execute('DELETE FROM ' . $this->fullTableName($table))) {
if ($this->execute('DELETE FROM ' . $table)) {
// $table = $this->fullTableName($table, false);
if (isset($this->_sequenceMap[$table]) && $reset !== 1) {
foreach ($this->_sequenceMap[$table] as $field => $sequence) {
$this->_execute("ALTER SEQUENCE \"{$sequence}\" RESTART WITH 1");
}
}
return true;
}
return false;
}

コアをすべて見れてないのですが基本的な使い方でエラーが。。・・・・><



追記、上記のままだとトランケートされないところがあったのでfullTableNameを変更しました
Model/Datasource/Database/DboSource.phpを変更
/**
/**
* Gets full table name including prefix
*
* @param mixed $model Either a Model object or a string table name.
* @param boolean $quote Whether you want the table name quoted.
* @return string Full quoted table name
*/
public function fullTableName($model, $quote = true) {
if (is_object($model)) {
$table = $model->tablePrefix . $model->table;
} elseif (isset($this->config['prefix'])) {
$prefix = strpos($model,$this->config['prefix']);
if($prefix ===false){
$table = $this->config['prefix'] . strval($model);
}else{
$table = strval($model);
}
} else {
$table = strval($model);
}
if ($quote) {
return $this->name($table);
}
return $table;
}