diff --git includes/bootstrap.inc includes/bootstrap.inc index 1c13c6f..c311bea 100644 --- includes/bootstrap.inc +++ includes/bootstrap.inc @@ -675,9 +675,12 @@ function drupal_get_filename($type, $name, $filename = NULL) { // 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; } } diff --git modules/simpletest/tests/bootstrap.test modules/simpletest/tests/bootstrap.test index 333f34b..5fa7b2a 100644 --- modules/simpletest/tests/bootstrap.test +++ modules/simpletest/tests/bootstrap.test @@ -322,26 +322,53 @@ class HookBootExitTestCase extends DrupalWebTestCase { } /** - * Test drupal_get_filename()'s availability. + * Test drupal_get_filename()'s availability without a DB. */ -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', ); } /** - * Test that drupal_get_filename() works correctly when the file is not found in the database. + * Test that drupal_get_filename() works correctly when not using the DB. */ 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 the location of an install profile. + $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'profiles/standard/standard.profile', t('Retrieve install profile location.')); + } +} + +/** + * Test drupal_get_filename()'s availability with a DB. + */ +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.')); @@ -351,8 +378,11 @@ class BootstrapGetFilenameTestCase extends DrupalUnitTestCase { // 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. + // Retrieving the location of an install profile. $this->assertIdentical(drupal_get_filename('profile', 'standard'), 'profiles/standard/standard.profile', t('Retrieve install profile location.')); + + // Retrieving the location of an install profile, that isn't in the DB. + $this->assertIdentical(drupal_get_filename('profile', 'testing'), 'profiles/testing/testing.profile', t('Retrieve install profile location, without DB.')); } } @@ -497,4 +527,3 @@ class BootstrapOverrideServerVariablesTestCase extends DrupalUnitTestCase { } } } -