diff --git a/core/modules/system/tests/modules/theme_test/theme_test.inc b/core/modules/system/tests/modules/theme_test/theme_test.inc index 6cde683..33622ab 100644 --- a/core/modules/system/tests/modules/theme_test/theme_test.inc +++ b/core/modules/system/tests/modules/theme_test/theme_test.inc @@ -13,3 +13,20 @@ function theme_theme_test($variables) { function template_preprocess_theme_test(&$variables) { $variables['foo'] = 'template_preprocess_theme_test'; } + +/** + * Implements hook_preprocess_HOOK() for theme_theme_test_preprocess(). + * + * Despite not having a corresponding theme function for this suggestion, the + * specific preprocess function should still be used. + */ +function template_preprocess_theme_test_preprocess__suggestion(&$variables) { + $variables['foo'] = 'template_preprocess_theme_test_preprocess__suggestion'; +} + +/** + * Returns HTML for the 'theme_test_preprocess' theme hook used by tests. + */ +function theme_theme_test_preprocess($variables) { + return 'Theme hook implementor=theme_theme_test_preprocess(). Foo=' . $variables['foo']; +} diff --git a/core/modules/system/tests/modules/theme_test/theme_test.module b/core/modules/system/tests/modules/theme_test/theme_test.module index 4ed90d2..3c0f0f1 100644 --- a/core/modules/system/tests/modules/theme_test/theme_test.module +++ b/core/modules/system/tests/modules/theme_test/theme_test.module @@ -8,6 +8,9 @@ function theme_test_theme($existing, $type, $theme, $path) { 'file' => 'theme_test.inc', 'variables' => array('foo' => ''), ); + $items['theme_test_preprocess'] = array( + 'variables' => array('foo' => ''), + ); $items['theme_test_template_test'] = array( 'template' => 'theme_test.template_test', ); @@ -41,6 +44,13 @@ function theme_test_menu() { 'theme callback' => '_theme_custom_theme', 'type' => MENU_CALLBACK, ); + $items['theme-test/preprocess-suggestion'] = array( + 'title' => 'Preprocess suggestion', + 'page callback' => '_theme_test_preprocess_suggestion', + 'access callback' => TRUE, + 'theme callback' => '_theme_custom_theme', + 'type' => MENU_CALLBACK, + ); $items['theme-test/alter'] = array( 'title' => 'Suggestion', 'page callback' => '_theme_test_alter', @@ -139,6 +149,13 @@ function _theme_test_suggestion() { } /** + * Page callback, calls a theme hook suggestion. + */ +function _theme_test_preprocess_suggestion() { + return theme(array('theme_test_preprocess__suggestion', 'theme_test_preprocess'), array()); +} + +/** * Implements hook_preprocess_HOOK() for html.tpl.php. */ function theme_test_preprocess_html(&$variables) { diff --git a/core/modules/system/tests/theme.test b/core/modules/system/tests/theme.test index d7c6fb2..20dd57b 100644 --- a/core/modules/system/tests/theme.test +++ b/core/modules/system/tests/theme.test @@ -69,6 +69,22 @@ class ThemeUnitTest extends WebTestBase { } /** + * Ensures suggestion preprocess functions run even for default implementations. + * + * The theme hook used by this test has its base preprocess function in a + * separate file, so this test also ensures that that file is correctly loaded + * when needed. + */ + function testSuggestionPreprocessForDefaults() { + // Test with both an unprimed and primed theme registry. + drupal_theme_rebuild(); + for ($i = 0; $i < 2; $i++) { + $this->drupalGet('theme-test/preprocess-suggestion'); + $this->assertText('Theme hook implementor=theme_theme_test_preprocess(). Foo=template_preprocess_theme_test_preprocess__suggestion', 'Theme hook ran with data available from a preprocess function for the suggested hook.'); + } + } + + /** * Ensure page-front template suggestion is added when on front page. */ function testFrontPageThemeSuggestion() {