function OverrideDisplaysTest::testOverrideDisplays

Same name in other branches
  1. 9 core/modules/views_ui/tests/src/Functional/OverrideDisplaysTest.php \Drupal\Tests\views_ui\Functional\OverrideDisplaysTest::testOverrideDisplays()
  2. 8.9.x core/modules/views_ui/tests/src/Functional/OverrideDisplaysTest.php \Drupal\Tests\views_ui\Functional\OverrideDisplaysTest::testOverrideDisplays()
  3. 10 core/modules/views_ui/tests/src/Functional/OverrideDisplaysTest.php \Drupal\Tests\views_ui\Functional\OverrideDisplaysTest::testOverrideDisplays()

Tests that displays can be overridden via the UI.

File

core/modules/views_ui/tests/src/Functional/OverrideDisplaysTest.php, line 31

Class

OverrideDisplaysTest
Tests that displays can be correctly overridden via the user interface.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testOverrideDisplays() : void {
    // Create a basic view that shows all content, with a page and a block
    // display.
    $view['label'] = $this->randomMachineName(16);
    $view['id'] = $this->randomMachineName(16);
    $view['page[create]'] = 1;
    $view['page[path]'] = $this->randomMachineName(16);
    $view['block[create]'] = 1;
    $view_path = $view['page[path]'];
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Save and edit');
    // Configure its title. Since the page and block both started off with the
    // same (empty) title in the views wizard, we expect the wizard to have set
    // things up so that they both inherit from the default display, and we
    // therefore only need to change that to have it take effect for both.
    $edit = [];
    $edit['title'] = $original_title = $this->randomMachineName(16);
    $edit['override[dropdown]'] = 'default';
    $this->drupalGet("admin/structure/views/nojs/display/{$view['id']}/page_1/title");
    $this->submitForm($edit, 'Apply');
    $this->drupalGet("admin/structure/views/view/{$view['id']}/edit/page_1");
    $this->submitForm([], 'Save');
    // Add a node that will appear in the view, so that the block will actually
    // be displayed.
    $this->drupalCreateContentType([
        'type' => 'page',
    ]);
    $this->drupalCreateNode();
    // Make sure the title appears in the page.
    $this->drupalGet($view_path);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains($original_title);
    // Confirm that the view block is available in the block administration UI.
    $this->drupalGet('admin/structure/block/list/' . $this->config('system.theme')
        ->get('default'));
    $this->clickLink('Place block');
    $this->assertSession()
        ->pageTextContains($view['label']);
    // Place the block.
    $this->container
        ->get('plugin.manager.block')
        ->clearCachedDefinitions();
    $this->drupalPlaceBlock("views_block:{$view['id']}-block_1");
    // Make sure the title appears in the block.
    $this->drupalGet('');
    $this->assertSession()
        ->pageTextContains($original_title);
    // Change the title for the page display only, and make sure that the
    // original title still appears on the page.
    $edit = [];
    $edit['title'] = $new_title = $this->randomMachineName(16);
    $edit['override[dropdown]'] = 'page_1';
    $this->drupalGet("admin/structure/views/nojs/display/{$view['id']}/page_1/title");
    $this->submitForm($edit, 'Apply');
    $this->drupalGet("admin/structure/views/view/{$view['id']}/edit/page_1");
    $this->submitForm([], 'Save');
    $this->drupalGet($view_path);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains($new_title);
    $this->assertSession()
        ->pageTextContains($original_title);
}

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