function DisplayAttachmentTest::testAttachmentUI

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

Tests the attachment UI.

File

core/modules/views_ui/tests/src/Functional/DisplayAttachmentTest.php, line 33

Class

DisplayAttachmentTest
Tests the UI for the attachment display plugin.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testAttachmentUI() : void {
    $this->drupalGet('admin/structure/views/view/test_attachment_ui/edit/attachment_1');
    $this->assertSession()
        ->pageTextContains('Not defined');
    $attachment_display_url = 'admin/structure/views/nojs/display/test_attachment_ui/attachment_1/displays';
    $this->drupalGet($attachment_display_url);
    // Display labels should be escaped.
    $this->assertSession()
        ->assertEscaped('<em>Page</em>');
    $this->assertSession()
        ->checkboxNotChecked("edit-displays-default");
    $this->assertSession()
        ->checkboxNotChecked("edit-displays-page-1");
    // Save the attachments and test the value on the view.
    $this->drupalGet($attachment_display_url);
    $this->submitForm([
        'displays[page_1]' => 1,
    ], 'Apply');
    // Options summary should be escaped.
    $this->assertSession()
        ->assertEscaped('<em>Page</em>');
    $this->assertSession()
        ->responseNotContains('<em>Page</em>');
    $this->assertSession()
        ->elementAttributeContains('xpath', '//a[@id = "views-attachment-1-displays"]', 'title', 'Page');
    $this->submitForm([], 'Save');
    $view = Views::getView('test_attachment_ui');
    $view->initDisplay();
    $this->assertEquals([
        'page_1',
    ], array_keys(array_filter($view->displayHandlers
        ->get('attachment_1')
        ->getOption('displays'))), 'The attached displays got saved as expected');
    $this->drupalGet($attachment_display_url);
    $this->submitForm([
        'displays[default]' => 1,
        'displays[page_1]' => 1,
    ], 'Apply');
    $this->assertSession()
        ->elementAttributeContains('xpath', '//a[@id = "views-attachment-1-displays"]', 'title', 'Multiple displays');
    $this->submitForm([], 'Save');
    $view = Views::getView('test_attachment_ui');
    $view->initDisplay();
    $this->assertEquals([
        'default',
        'page_1',
    ], array_keys($view->displayHandlers
        ->get('attachment_1')
        ->getOption('displays')), 'The attached displays got saved as expected');
}

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