function OverrideDisplaysTest::testWizardMixedDefaultOverriddenDisplays

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

Tests that the wizard correctly sets up default and overridden displays.

File

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

Class

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

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testWizardMixedDefaultOverriddenDisplays() : void {
    // Create a basic view with a page, block, and feed. Give the page and feed
    // identical titles, but give the block a different one, so we expect the
    // page and feed to inherit their titles from the default display, but the
    // block to override it.
    $view['label'] = $this->randomMachineName(16);
    $view['id'] = $this->randomMachineName(16);
    $view['page[create]'] = 1;
    $view['page[title]'] = $this->randomMachineName(16);
    $view['page[path]'] = $this->randomMachineName(16);
    $view['page[feed]'] = 1;
    $view['page[feed_properties][path]'] = $this->randomMachineName(16);
    $view['block[create]'] = 1;
    $view['block[title]'] = $this->randomMachineName(16);
    $this->drupalGet('admin/structure/views/add');
    $this->submitForm($view, 'Save and edit');
    // 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 that the feed, page and block all start off with the correct
    // titles.
    $this->drupalGet($view['page[path]']);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains($view['page[title]']);
    $this->assertSession()
        ->pageTextNotContains($view['block[title]']);
    $this->drupalGet($view['page[feed_properties][path]']);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains($view['page[title]']);
    $this->assertSession()
        ->responseNotContains($view['block[title]']);
    // Confirm that the 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']);
    // Put the block into the first sidebar region, and make sure it will not
    // display on the view's page display (since we will be searching for the
    // presence/absence of the view's title in both the page and the block).
    $this->container
        ->get('plugin.manager.block')
        ->clearCachedDefinitions();
    $this->drupalPlaceBlock("views_block:{$view['id']}-block_1", [
        'visibility' => [
            'request_path' => [
                'pages' => '/' . $view['page[path]'],
                'negate' => TRUE,
            ],
        ],
    ]);
    $this->drupalGet('');
    $this->assertSession()
        ->pageTextContains($view['block[title]']);
    $this->assertSession()
        ->pageTextNotContains($view['page[title]']);
    // Edit the page and change the title. This should automatically change
    // the feed's title also, but not the block.
    $edit = [];
    $edit['title'] = $new_default_title = $this->randomMachineName(16);
    $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['page[path]']);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains($new_default_title);
    $this->assertSession()
        ->pageTextNotContains($view['page[title]']);
    $this->assertSession()
        ->pageTextNotContains($view['block[title]']);
    $this->drupalGet($view['page[feed_properties][path]']);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains($new_default_title);
    $this->assertSession()
        ->responseNotContains($view['page[title]']);
    $this->assertSession()
        ->responseNotContains($view['block[title]']);
    $this->drupalGet('');
    $this->assertSession()
        ->pageTextNotContains($new_default_title);
    $this->assertSession()
        ->pageTextNotContains($view['page[title]']);
    $this->assertSession()
        ->pageTextContains($view['block[title]']);
    // Edit the block and change the title. This should automatically change
    // the block title only, and leave the defaults alone.
    $edit = [];
    $edit['title'] = $new_block_title = $this->randomMachineName(16);
    $this->drupalGet("admin/structure/views/nojs/display/{$view['id']}/block_1/title");
    $this->submitForm($edit, 'Apply');
    $this->drupalGet("admin/structure/views/view/{$view['id']}/edit/block_1");
    $this->submitForm([], 'Save');
    $this->drupalGet($view['page[path]']);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->pageTextContains($new_default_title);
    $this->drupalGet($view['page[feed_properties][path]']);
    $this->assertSession()
        ->statusCodeEquals(200);
    $this->assertSession()
        ->responseContains($new_default_title);
    $this->assertSession()
        ->responseNotContains($new_block_title);
    $this->drupalGet('');
    $this->assertSession()
        ->pageTextContains($new_block_title);
    $this->assertSession()
        ->pageTextNotContains($view['block[title]']);
}

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