function ViewsThemeIntegrationTest::testThemedViewPage

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

Tests pre_render and post_render hooks in a theme and sub-theme.

File

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

Class

ViewsThemeIntegrationTest
Tests the Views theme integration.

Namespace

Drupal\Tests\views\Functional

Code

public function testThemedViewPage() : void {
  \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->assertEquals('test_basetheme', $this->config('system.theme')
    ->get('default'));
  // Make sure a views rendered page is touched.
  $this->drupalGet('test_page_display_200');
  $this->assertSession()
    ->responseContains("test_basetheme_views_pre_render");
  $this->assertSession()
    ->responseContains("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->assertEquals('test_subtheme', $this->config('system.theme')
    ->get('default'));
  // Make sure a views rendered page is touched.
  $this->drupalGet('test_page_display_200');
  $this->assertSession()
    ->responseContains("test_subtheme_views_pre_render");
  $this->assertSession()
    ->responseContains("test_subtheme_views_post_render");
  $this->assertSession()
    ->responseContains("test_basetheme_views_pre_render");
  $this->assertSession()
    ->responseContains("test_basetheme_views_post_render");
  // Verify that the views group title is added.
  $this->assertSession()
    ->responseContains('<em class="placeholder">' . count($this->dataSet()) . '</em> items found.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.