diff --git a/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php b/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php new file mode 100644 index 000000000..d33f23406 --- /dev/null +++ b/lib/Cake/Test/Case/TestSuite/Fixture/CakeFixtureManagerTest.php @@ -0,0 +1,103 @@ +fixtureManager = new CakeFixtureManager(); + } + +/** + * tearDown + * + * @return void + */ + public function tearDown() { + parent::tearDown(); + unset($this->fixtureManager); + } + +/** + * testLoadTruncatesTable + * + * @return void + */ + public function testLoadTruncatesTable() { + $MockFixture = $this->getMock('UuidFixture', array('truncate')); + $MockFixture + ->expects($this->once()) + ->method('truncate') + ->will($this->returnValue(true)); + + $fixtureManager = $this->fixtureManager; + $fixtureManagerReflection = new ReflectionClass($fixtureManager); + + $loadedProperty = $fixtureManagerReflection->getProperty('_loaded'); + $loadedProperty->setAccessible(true); + $loadedProperty->setValue($fixtureManager, array('core.uuid' => $MockFixture)); + + $TestCase = $this->getMock('CakeTestCase'); + $TestCase->fixtures = array('core.uuid'); + $TestCase->autoFixtures = true; + $TestCase->dropTables = false; + + $fixtureManager->load($TestCase); + } + +/** + * testLoadSingleTruncatesTable + * + * @return void + */ + public function testLoadSingleTruncatesTable() { + $MockFixture = $this->getMock('UuidFixture', array('truncate')); + $MockFixture + ->expects($this->once()) + ->method('truncate') + ->will($this->returnValue(true)); + + $fixtureManager = $this->fixtureManager; + $fixtureManagerReflection = new ReflectionClass($fixtureManager); + + $fixtureMapProperty = $fixtureManagerReflection->getProperty('_fixtureMap'); + $fixtureMapProperty->setAccessible(true); + $fixtureMapProperty->setValue($fixtureManager, array('UuidFixture' => $MockFixture)); + + $dboMethods = array_diff(get_class_methods('DboSource'), array('enabled')); + $dboMethods[] = 'connect'; + $db = $this->getMock('DboSource', $dboMethods); + $db->config['prefix'] = ''; + + $fixtureManager->loadSingle('Uuid', $db, false); + } +} diff --git a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php index f4a833080..ec53163c5 100644 --- a/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php +++ b/lib/Cake/TestSuite/Fixture/CakeFixtureManager.php @@ -209,6 +209,7 @@ class CakeFixtureManager { $db = ConnectionManager::getDataSource($fixture->useDbConfig); $db->begin(); $this->_setupTable($fixture, $db, $test->dropTables); + $fixture->truncate($db); $fixture->insert($db); $db->commit(); }