You are here

public function ViewsThemeIntegrationTest::testThemedViewPage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php \Drupal\Tests\views\Functional\ViewsThemeIntegrationTest::testThemedViewPage()

Tests for exceptions and successful execution of hook_views_pre_render() and hook_views_post_render() in theme and subtheme.

File

core/modules/views/tests/src/Functional/ViewsThemeIntegrationTest.php, line 51

Class

ViewsThemeIntegrationTest
Tests the Views theme integration.

Namespace

Drupal\Tests\views\Functional

Code

public function testThemedViewPage() {
  \Drupal::service('theme_installer')
    ->install([
    'test_basetheme',
    'test_subtheme',
  ]);

  // Make base theme default then test for hook invocations.
  $this
    ->config('system.theme')
    ->set('default', 'test_basetheme')
    ->save();
  $this
    ->assertEqual($this
    ->config('system.theme')
    ->get('default'), 'test_basetheme');

  // Make sure a views rendered page is touched.
  $this
    ->drupalGet('test_page_display_200');
  $this
    ->assertRaw("test_basetheme_views_pre_render", "Views title changed by test_basetheme.test_basetheme_views_pre_render");
  $this
    ->assertRaw("test_basetheme_views_post_render", "Views title changed by test_basetheme.test_basetheme_views_post_render");

  // Make sub theme default to test for hook invocation
  // from both sub and base theme.
  $this
    ->config('system.theme')
    ->set('default', 'test_subtheme')
    ->save();
  $this
    ->assertEqual($this
    ->config('system.theme')
    ->get('default'), 'test_subtheme');

  // Make sure a views rendered page is touched.
  $this
    ->drupalGet('test_page_display_200');
  $this
    ->assertRaw("test_subtheme_views_pre_render", "Views title changed by test_subtheme.test_subtheme_views_pre_render");
  $this
    ->assertRaw("test_subtheme_views_post_render", "Views title changed by test_subtheme.test_subtheme_views_post_render");
  $this
    ->assertRaw("test_basetheme_views_pre_render", "Views title changed by test_basetheme.test_basetheme_views_pre_render");
  $this
    ->assertRaw("test_basetheme_views_post_render", "Views title changed by test_basetheme.test_basetheme_views_post_render");
  $this
    ->assertRaw('<em class="placeholder">' . count($this
    ->dataSet()) . '</em> items found.', 'Views group title added by test_subtheme.test_subtheme_views_post_render');
}