Adding tests for r7867

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7868 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
mariano.iglesias 2008-11-12 17:00:00 +00:00
parent 910be6e368
commit f8b69b10e2

View file

@ -84,11 +84,26 @@ class CakeTestFixtureImportFixture extends CakeTestFixture {
/** /**
* Import property * Import property
* *
* @var array * @var mixed
*/ */
var $import = array('table' => 'fixture_tests', 'connection' => 'test_suite'); var $import = array('table' => 'fixture_tests', 'connection' => 'test_suite');
} }
/**
* Import Fixture Test Fixture
*
* @package cake
* @subpackage cake.cake.tests.cases.libs
*/
class CakeTestFixtureDefaultImportFixture extends CakeTestFixture {
/**
* Name property
*
* @var string
*/
var $name = 'ImportFixture';
}
/** /**
* Fixture Test Case Model * Fixture Test Case Model
* *
@ -110,7 +125,6 @@ Mock::generate('DboSource', 'FixtureMockDboSource');
* @subpackage cake.cake.tests.cases.libs * @subpackage cake.cake.tests.cases.libs
*/ */
class CakeTestFixtureTest extends CakeTestCase { class CakeTestFixtureTest extends CakeTestCase {
function setUp() { function setUp() {
$this->criticDb =& new FixtureMockDboSource(); $this->criticDb =& new FixtureMockDboSource();
$this->criticDb->fullDebug = true; $this->criticDb->fullDebug = true;
@ -158,12 +172,46 @@ class CakeTestFixtureTest extends CakeTestCase {
$Fixture->init(); $Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created')); $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()); $keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys)); $this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($this->db); $Source->drop($this->db);
} }
/**
* testImport
*
* @access public
* @return void
*/
function testImport() {
$this->_initDb();
$defaultDb =& ConnectionManager::getDataSource('default');
$testSuiteDb =& ConnectionManager::getDataSource('test_suite');
$defaultConfig = $defaultDb->config;
$testSuiteConfig = $testSuiteDb->config;
ConnectionManager::create('new_test_suite', array_merge($testSuiteConfig, array('prefix' => 'new_' . $testSuiteConfig['prefix'])));
$newTestSuiteDb =& ConnectionManager::getDataSource('new_test_suite');
$Source =& new CakeTestFixtureTestFixture();
$Source->create($newTestSuiteDb);
$Source->insert($newTestSuiteDb);
$defaultDb->config = $newTestSuiteDb->config;
$Fixture =& new CakeTestFixtureDefaultImportFixture();
$Fixture->fields = $Fixture->records = null;
$Fixture->import = 'FixtureImportTestModel';
$Fixture->init();
$this->assertEqual(array_keys($Fixture->fields), array('id', 'name', 'created'));
$defaultDb->config = $defaultConfig;
$keys = array_flip(ClassRegistry::keys());
$this->assertFalse(array_key_exists('fixtureimporttestmodel', $keys));
$Source->drop($newTestSuiteDb);
}
/** /**
* test create method * test create method
* *