function DisplayPathTest::testUseAdminTheme

Same name and namespace in other branches
  1. 11.x core/modules/views_ui/tests/src/Functional/DisplayPathTest.php \Drupal\Tests\views_ui\Functional\DisplayPathTest::testUseAdminTheme()

Tests the "Use the administration theme" configuration.

See also

\Drupal\Tests\views\Functional\Plugin\DisplayPageWebTest::testAdminTheme

File

core/modules/views_ui/tests/src/Functional/DisplayPathTest.php, line 300

Class

DisplayPathTest
Tests the UI of generic display path plugin.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testUseAdminTheme() : void {
  $this->drupalGet('admin/structure/views/view/test_view');
  // Add a new page display.
  $this->submitForm([], 'Add Page');
  $this->assertSession()
    ->pageTextContains('No path is set');
  $this->assertSession()
    ->pageTextContains('Administration theme: No');
  // Test with a path starting with "/admin".
  $admin_path = 'admin/test_admin_path';
  $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
  $this->submitForm([
    'path' => $admin_path,
  ], 'Apply');
  $this->assertSession()
    ->pageTextContains('/' . $admin_path);
  $this->assertSession()
    ->pageTextContains('Administration theme: Yes (admin path)');
  $this->submitForm([], 'Save');
  $this->assertConfigSchemaByName('views.view.test_view');
  $display_options = $this->config('views.view.test_view')
    ->get('display.page_1.display_options');
  $this->assertArrayNotHasKey('use_admin_theme', $display_options);
  $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/use_admin_theme');
  $this->assertSession()
    ->elementExists('css', 'input[name="use_admin_theme"][disabled="disabled"][checked="checked"]');
  // Test with a non-administration path.
  $non_admin_path = 'kittens';
  $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/path');
  $this->submitForm([
    'path' => $non_admin_path,
  ], 'Apply');
  $this->assertSession()
    ->pageTextContains('/' . $non_admin_path);
  $this->assertSession()
    ->pageTextContains('Administration theme: No');
  $this->submitForm([], 'Save');
  $this->assertConfigSchemaByName('views.view.test_view');
  $display_options = $this->config('views.view.test_view')
    ->get('display.page_1.display_options');
  $this->assertArrayNotHasKey('use_admin_theme', $display_options);
  // Enable administration theme.
  $this->drupalGet('admin/structure/views/nojs/display/test_view/page_1/use_admin_theme');
  $this->submitForm([
    'use_admin_theme' => TRUE,
  ], 'Apply');
  $this->assertSession()
    ->pageTextContains('Administration theme: Yes');
  $this->submitForm([], 'Save');
  $this->assertConfigSchemaByName('views.view.test_view');
  $display_options = $this->config('views.view.test_view')
    ->get('display.page_1.display_options');
  $this->assertArrayHasKey('use_admin_theme', $display_options);
  $this->assertTrue($display_options['use_admin_theme']);
}

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