function ThemeSuggestionsAlterTest::testSpecificSuggestionsAlter in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/system/src/Tests/Theme/ThemeSuggestionsAlterTest.php \Drupal\system\Tests\Theme\ThemeSuggestionsAlterTest::testSpecificSuggestionsAlter()
Tests that theme suggestion alter hooks work for specific theme calls.
File
- core/
modules/ system/ src/ Tests/ Theme/ ThemeSuggestionsAlterTest.php, line 96 - Contains \Drupal\system\Tests\Theme\ThemeSuggestionsAlterTest.
Class
- ThemeSuggestionsAlterTest
- Tests theme suggestion alter hooks.
Namespace
Drupal\system\Tests\ThemeCode
function testSpecificSuggestionsAlter() {
// Test that the default template is rendered.
$this
->drupalGet('theme-test/specific-suggestion-alter');
$this
->assertText('Template for testing specific theme calls.');
$this
->config('system.theme')
->set('default', 'test_theme')
->save();
// Test a specific theme call similar to '#theme' => 'node__article'.
$this
->drupalGet('theme-test/specific-suggestion-alter');
$this
->assertText('Template matching the specific theme call.');
$this
->assertText('theme_test_specific_suggestions__variant', 'Specific theme call is added to the suggestions array.');
// Ensure that the base hook is used to determine the suggestion alter hook.
\Drupal::service('module_installer')
->install(array(
'theme_suggestions_test',
));
$this
->resetAll();
$this
->drupalGet('theme-test/specific-suggestion-alter');
$this
->assertText('Template overridden based on suggestion alter hook determined by the base hook.');
$this
->assertTrue(strpos($this
->getRawContent(), 'theme_test_specific_suggestions__variant') < strpos($this
->getRawContent(), 'theme_test_specific_suggestions__variant__foo'), 'Specific theme call is added to the suggestions array before the suggestions alter hook.');
}