Index: includes/bootstrap.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v retrieving revision 1.458 diff -u -p -r1.458 bootstrap.inc --- includes/bootstrap.inc 28 Dec 2010 19:14:48 -0000 1.458 +++ includes/bootstrap.inc 29 Dec 2010 00:30:48 -0000 @@ -675,9 +675,12 @@ function drupal_get_filename($type, $nam // when a database connection fails. else { try { - if (function_exists('db_query')) { - $file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField(); - if (file_exists(DRUPAL_ROOT . '/' . $file)) { + if (class_exists('Database') && Database::isActiveConnection()) { + // If the 'profile' type is given, it's actually stored as 'module', so + // query using that type. + $type_token = $type == 'profile' ? 'module' : $type; + $file = db_query("SELECT filename FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type_token))->fetchField(); + if ($file && file_exists(DRUPAL_ROOT . '/' . $file)) { $files[$type][$name] = $file; } } Index: modules/simpletest/tests/bootstrap.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/bootstrap.test,v retrieving revision 1.35 diff -u -p -r1.35 bootstrap.test --- modules/simpletest/tests/bootstrap.test 23 Nov 2010 03:08:34 -0000 1.35 +++ modules/simpletest/tests/bootstrap.test 29 Dec 2010 00:30:49 -0000 @@ -324,12 +324,12 @@ class HookBootExitTestCase extends Drupa /** * Test drupal_get_filename()'s availability. */ -class BootstrapGetFilenameTestCase extends DrupalUnitTestCase { +class BootstrapGetFilenameTestCaseNoDatabase extends DrupalUnitTestCase { public static function getInfo() { return array( - 'name' => 'Get filename test', - 'description' => 'Test that drupal_get_filename() works correctly when the file is not found in the database.', + 'name' => 'Get filename test (no database)', + 'description' => 'Test that drupal_get_filename() works correctly without an active database connection.', 'group' => 'Bootstrap', ); } @@ -338,10 +338,37 @@ class BootstrapGetFilenameTestCase exten * Test that drupal_get_filename() works correctly when the file is not found in the database. */ function testDrupalGetFilename() { - // Reset the static cache so we can test the "db is not active" code of - // drupal_get_filename(). - drupal_static_reset('drupal_get_filename'); + // Retrieving the location of a module. + $this->assertIdentical(drupal_get_filename('module', 'php'), 'modules/php/php.module', t('Retrieve module location.')); + + // Retrieving the location of a theme. + $this->assertIdentical(drupal_get_filename('theme', 'stark'), 'themes/stark/stark.info', t('Retrieve theme location.')); + + // Retrieving the location of a theme engine. + $this->assertIdentical(drupal_get_filename('theme_engine', 'phptemplate'), 'themes/engines/phptemplate/phptemplate.engine', t('Retrieve theme engine location.')); + + // Retrieving a file that is definitely not stored in the database. + $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'profiles/standard/standard.profile', t('Retrieve install profile location.')); + } +} +/** + * Test drupal_get_filename()'s availability. + */ +class BootstrapGetFilenameTestCaseDatabase extends DrupalWebTestCase { + + public static function getInfo() { + return array( + 'name' => 'Get filename test (database)', + 'description' => 'Test that drupal_get_filename() works correctly with an active database connection.', + 'group' => 'Bootstrap', + ); + } + + /** + * Test that drupal_get_filename() works correctly when the file is not found in the database. + */ + function testDrupalGetFilename() { // Retrieving the location of a module. $this->assertIdentical(drupal_get_filename('module', 'php'), 'modules/php/php.module', t('Retrieve module location.'));