function DisplayTest::testLinkDisplay

Same name and namespace in other branches
  1. 8.9.x core/modules/views_ui/tests/src/Functional/DisplayTest.php \Drupal\Tests\views_ui\Functional\DisplayTest::testLinkDisplay()
  2. 10 core/modules/views_ui/tests/src/Functional/DisplayTest.php \Drupal\Tests\views_ui\Functional\DisplayTest::testLinkDisplay()
  3. 11.x core/modules/views_ui/tests/src/Functional/DisplayTest.php \Drupal\Tests\views_ui\Functional\DisplayTest::testLinkDisplay()

Tests the link-display setting.

File

core/modules/views_ui/tests/src/Functional/DisplayTest.php, line 157

Class

DisplayTest
Tests the display UI.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testLinkDisplay() {
    // Test setting the link display in the UI form.
    $path = 'admin/structure/views/view/test_display/edit/block_1';
    $link_display_path = 'admin/structure/views/nojs/display/test_display/block_1/link_display';
    // Test the link text displays 'None' and not 'Block 1'
    $this->drupalGet($path);
    $this->assertSession()
        ->elementTextEquals('xpath', "//a[contains(@href, '{$link_display_path}')]", 'None');
    $this->drupalGet($link_display_path);
    $this->assertSession()
        ->checkboxChecked('edit-link-display-0');
    // Test the default radio option on the link display form.
    $this->drupalGet($link_display_path);
    $this->submitForm([
        'link_display' => 'page_1',
    ], 'Apply');
    // The form redirects to the default display.
    $this->drupalGet($path);
    // Test that the link option summary shows the right linked display.
    $this->assertSession()
        ->elementTextEquals('xpath', "//a[contains(@href, '{$link_display_path}')]", 'Page');
    $this->drupalGet($link_display_path);
    $this->submitForm([
        'link_display' => 'custom_url',
        'link_url' => 'a-custom-url',
    ], 'Apply');
    // The form redirects to the default display.
    $this->drupalGet($path);
    $this->assertSession()
        ->linkExists('Custom URL', 0, 'The link option has custom URL as summary.');
    // Test the default link_url value for new display
    $this->submitForm([], 'Add Block');
    $this->assertSession()
        ->addressEquals('admin/structure/views/view/test_display/edit/block_2');
    $this->clickLink('Custom URL');
    $this->assertSession()
        ->fieldValueEquals('link_url', 'a-custom-url');
}

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