. */ /** * Doctrine_Base_TestCase * * @package Doctrine * @author Konsta Vesterinen * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.org * @since 1.0 * @version $Revision$ */ class Doctrine_Base_TestCase extends Doctrine_UnitTestCase { public function testAggressiveModelLoading() { $path = realpath('ModelLoadingTest/Aggressive'); $models = Doctrine::loadModels($path, Doctrine::MODEL_LOADING_AGGRESSIVE); // Ensure the correct model names were returned $this->assertTrue(isset($models['AggressiveModelLoadingUser']) && $models['AggressiveModelLoadingUser'] == 'AggressiveModelLoadingUser'); $this->assertTrue(isset($models['AggressiveModelLoadingProfile']) && $models['AggressiveModelLoadingProfile'] == 'AggressiveModelLoadingProfile'); $this->assertTrue(isset($models['AggressiveModelLoadingContact']) && $models['AggressiveModelLoadingContact'] == 'AggressiveModelLoadingContact'); // Make sure it does not include the base classes $this->assertTrue( ! isset($models['BaseAggressiveModelLoadingUser'])); $filteredModels = Doctrine::filterInvalidModels($models); // Make sure filterInvalidModels filters out base abstract classes $this->assertTrue( ! isset($models['BaseAggressiveModelLoadingUser'])); } public function testConservativeModelLoading() { $path = realpath('ModelLoadingTest/Conservative'); $models = Doctrine::loadModels($path, Doctrine::MODEL_LOADING_CONSERVATIVE); $this->assertTrue( ! class_exists('ConservativeModelLoadingUser', false)); $this->assertTrue( ! class_exists('ConservativeModelLoadingProfile', false)); $this->assertTrue( ! class_exists('ConservativeModelLoadingContact', false)); $this->assertTrue( ! class_exists('BaseConservativeModelLoadingUser', false)); } public function testAllModelsAvailable() { // Ensure models were loaded $this->assertTrue(class_exists('AggressiveModelLoadingUser')); $this->assertTrue(class_exists('AggressiveModelLoadingProfile')); $this->assertTrue(class_exists('AggressiveModelLoadingContact')); $this->assertTrue(class_exists('BaseAggressiveModelLoadingUser')); $this->assertTrue( class_exists('ConservativeModelLoadingUser', true)); $this->assertTrue( class_exists('ConservativeModelLoadingProfile', true)); $this->assertTrue( class_exists('ConservativeModelLoadingContact', true)); $this->assertTrue( class_exists('BaseConservativeModelLoadingUser', true)); } public function testModelLoadingCacheInformation() { $models = Doctrine::getLoadedModels(); $this->assertTrue(in_array('AggressiveModelLoadingUser', $models)); $this->assertTrue(in_array('ConservativeModelLoadingProfile', $models)); $this->assertTrue(in_array('ConservativeModelLoadingContact', $models)); $modelFiles = Doctrine::getLoadedModelFiles(); $this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingUser'])); $this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingProfile'])); $this->assertTrue(file_exists($modelFiles['ConservativeModelLoadingContact'])); } public function testGetConnectionByTableName() { $connectionBefore = Doctrine::getConnectionByTableName('entity'); Doctrine_Manager::connection('sqlite::memory:', 'test_memory'); Doctrine_Manager::getInstance()->bindComponent('Entity', 'test_memory'); $connectionAfter = Doctrine::getConnectionByTableName('entity'); $this->assertEqual($connectionAfter->getName(), 'test_memory'); Doctrine_Manager::getInstance()->bindComponent('Entity', $connectionBefore->getName()); $connectionAfter = Doctrine::getConnectionByTableName('entity'); $this->assertEqual($connectionBefore->getName(), $connectionAfter->getName()); } }