diff --git a/includes/path.inc b/includes/path.inc index db60537..804345e 100644 --- a/includes/path.inc +++ b/includes/path.inc @@ -55,21 +55,13 @@ function drupal_lookup_path($action, $path = '', $path_language = NULL) { $cache = array( 'map' => array(), 'no_source' => array(), - 'whitelist' => NULL, + 'whitelist' => new PathAliasWhitelist('path_alias_whitelist', 'cache'), 'system_paths' => array(), 'no_aliases' => array(), 'first_call' => TRUE, ); } - // Retrieve the path alias whitelist. - if (!isset($cache['whitelist'])) { - $cache['whitelist'] = variable_get('path_alias_whitelist', NULL); - if (!isset($cache['whitelist'])) { - $cache['whitelist'] = drupal_path_alias_whitelist_rebuild(); - } - } - // If no language is explicitly specified we default to the current URL // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path @@ -356,33 +348,40 @@ function current_path() { } /** + * Extends DrupalCacheArray to build the path alias whitelist over time. + */ +class PathAliasWhitelist extends DrupalCacheArray { + function resolveCacheMiss($offset) { + $exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE source LIKE :path', 0, 1, array(':path' => $offset . '%'))->fetchField(); + // If a path prefix does not exist, store it as NULL rather than FALSE + // since DrupalCacheArray uses isset() in offsetExists(). + $value = $exists ? TRUE : NULL; + $this->storage[$offset] = $value; + $this->persist($offset); + return $value; + } +} + +/** * Rebuild the path alias white list. * * @param $source * An optional system path for which an alias is being inserted. * * @return - * An array containing a white list of path aliases. + * An instance of the PathAliasWhitelist class. */ function drupal_path_alias_whitelist_rebuild($source = NULL) { // When paths are inserted, only rebuild the whitelist if the system path // has a top level component which is not already in the whitelist. if (!empty($source)) { - $whitelist = variable_get('path_alias_whitelist', NULL); + $whitelist = new PathAliasWhitelist('path_alias_whitelist', 'cache'); if (isset($whitelist[strtok($source, '/')])) { return $whitelist; } } - // For each alias in the database, get the top level component of the system - // path it corresponds to. This is the portion of the path before the first - // '/', if present, otherwise the whole path itself. - $whitelist = array(); - $result = db_query("SELECT DISTINCT SUBSTRING_INDEX(source, '/', 1) AS path FROM {url_alias}"); - foreach ($result as $row) { - $whitelist[$row->path] = TRUE; - } - variable_set('path_alias_whitelist', $whitelist); - return $whitelist; + cache_clear_all('path_alias_whitelist', 'cache'); + return new PathAliasWhitelist('path_alias_whitelist', 'cache'); } /** diff --git a/modules/simpletest/drupal_web_test_case.php b/modules/simpletest/drupal_web_test_case.php index 5c39cfc..b2a7bf1 100644 --- a/modules/simpletest/drupal_web_test_case.php +++ b/modules/simpletest/drupal_web_test_case.php @@ -1238,6 +1238,10 @@ class DrupalWebTestCase extends DrupalTestCase { ->condition('test_id', $this->testId) ->execute(); + // Reset all statics and variables to perform tests in a clean environment. + $conf = array(); + drupal_static_reset(); + // Clone the current connection and replace the current prefix. $connection_info = Database::getConnectionInfo('default'); Database::renameConnection('default', 'simpletest_original_default'); @@ -1285,10 +1289,6 @@ class DrupalWebTestCase extends DrupalTestCase { ini_set('log_errors', 1); ini_set('error_log', $public_files_directory . '/error.log'); - // Reset all statics and variables to perform tests in a clean environment. - $conf = array(); - drupal_static_reset(); - // Set the test information for use in other parts of Drupal. $test_info = &$GLOBALS['drupal_test_info']; $test_info['test_run_id'] = $this->databasePrefix; diff --git a/modules/simpletest/tests/theme.test b/modules/simpletest/tests/theme.test index f1e1bd5..2529e8d 100644 --- a/modules/simpletest/tests/theme.test +++ b/modules/simpletest/tests/theme.test @@ -194,7 +194,7 @@ class ThemeItemListUnitTest extends DrupalWebTestCase { /** * Unit tests for theme_links(). */ -class ThemeLinksUnitTest extends DrupalUnitTestCase { +class ThemeLinksTest extends DrupalWebTestCase { public static function getInfo() { return array( 'name' => 'Links',