mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-09-03 10:02:42 +00:00
Fixing infinite loop when importing models that have relations that are also fixturized. Closes #5166.
Tests updated and added. Added documentation concerning use of app_error.php git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7550 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
57c633a64f
commit
ba2542ec29
3 changed files with 19 additions and 9 deletions
|
@ -174,7 +174,7 @@ class Object {
|
|||
}
|
||||
/**
|
||||
* Used to report user friendly errors.
|
||||
* If there is a file app/error.php this file will be loaded
|
||||
* If there is a file app/error.php or app/app_error.php this file will be loaded
|
||||
* error.php is the AppError class it should extend ErrorHandler class.
|
||||
*
|
||||
* @param string $method Method to be called in the error class (AppError or ErrorHandler classes)
|
||||
|
|
|
@ -98,7 +98,6 @@ class CakeTestFixtureImportFixture extends CakeTestFixture {
|
|||
* @subpackage cake.cake.tests.cases.libs.
|
||||
**/
|
||||
class FixtureImportTestModel extends Model {
|
||||
|
||||
var $name = 'FixtureImport';
|
||||
var $useTable = 'fixture_tests';
|
||||
var $useDbConfig = 'test_suite';
|
||||
|
@ -130,32 +129,41 @@ class CakeTestFixtureTest extends CakeTestCase {
|
|||
$Fixture->init();
|
||||
$this->assertEqual($Fixture->table, 'fixture_tests');
|
||||
$this->assertEqual($Fixture->primaryKey, 'id');
|
||||
|
||||
|
||||
$Fixture =& new CakeTestFixtureTestFixture();
|
||||
$Fixture->primaryKey = 'my_random_key';
|
||||
$Fixture->init();
|
||||
$this->assertEqual($Fixture->primaryKey, 'my_random_key');
|
||||
|
||||
|
||||
$this->_initDb();
|
||||
$Source =& new CakeTestFixtureTestFixture();
|
||||
$Source->create($this->db);
|
||||
$Source->insert($this->db);
|
||||
|
||||
|
||||
$Fixture =& new CakeTestFixtureImportFixture();
|
||||
$expected = array('id', 'name', 'created');
|
||||
$this->assertEqual(array_keys($Fixture->fields), $expected);
|
||||
|
||||
|
||||
$db =& ConnectionManager::getDataSource('test_suite');
|
||||
$config = $db->config;
|
||||
$config['prefix'] = 'fixture_test_suite_';
|
||||
ConnectionManager::create('fixture_test_suite', $config);
|
||||
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('table' => 'fixture_tests', 'connection' => 'test_suite', 'records' => true);
|
||||
$Fixture->init();
|
||||
$this->assertEqual(count($Fixture->records), count($Source->records));
|
||||
|
||||
|
||||
$Fixture =& new CakeTestFixtureImportFixture();
|
||||
$Fixture->fields = $Fixture->records = null;
|
||||
$Fixture->import = array('model' => 'FixtureImportTestModel');
|
||||
$Fixture->init();
|
||||
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
|
||||
|
||||
|
||||
//assert that model has been removed from registry, stops infinite loops.
|
||||
$keys = array_flip(ClassRegistry::keys());
|
||||
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
|
||||
|
||||
$Source->drop($this->db);
|
||||
}
|
||||
/**
|
||||
|
|
|
@ -86,10 +86,12 @@ class CakeTestFixture extends Object {
|
|||
$db->cacheSources = false;
|
||||
$this->fields = $model->schema(true);
|
||||
$this->fields[$model->primaryKey]['key'] = 'primary';
|
||||
ClassRegistry::removeObject($model->alias);
|
||||
} elseif (isset($import['table'])) {
|
||||
$model =& new Model(null, $import['table'], $import['connection']);
|
||||
$db =& ConnectionManager::getDataSource($import['connection']);
|
||||
$db->cacheSources = false;
|
||||
$model->useDbConfig = $import['connection'];
|
||||
$model->name = Inflector::camelize(Inflector::singularize($import['table']));
|
||||
$model->table = $import['table'];
|
||||
$model->tablePrefix = $db->config['prefix'];
|
||||
|
@ -101,7 +103,7 @@ class CakeTestFixture extends Object {
|
|||
|
||||
$query = array(
|
||||
'fields' => array_keys($this->fields),
|
||||
'table' => $db->name($model->table),
|
||||
'table' => $db->fullTableName($model->table),
|
||||
'alias' => $model->alias,
|
||||
'conditions' => array(),
|
||||
'order' => null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue