You are here

public function PreviewTest::testPreviewContextual in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/views_ui/tests/src/Functional/PreviewTest.php \Drupal\Tests\views_ui\Functional\PreviewTest::testPreviewContextual()
  2. 9 core/modules/views_ui/tests/src/Functional/PreviewTest.php \Drupal\Tests\views_ui\Functional\PreviewTest::testPreviewContextual()

Tests contextual links in the preview form.

File

core/modules/views_ui/tests/src/Functional/PreviewTest.php, line 27

Class

PreviewTest
Tests the UI preview functionality.

Namespace

Drupal\Tests\views_ui\Functional

Code

public function testPreviewContextual() {
  \Drupal::service('module_installer')
    ->install([
    'contextual',
  ]);
  $this
    ->resetAll();
  $this
    ->drupalGet('admin/structure/views/view/test_preview/edit');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->submitForm($edit = [], 'Update preview');

  // Verify that the contextual link to add a new field is shown.
  $selector = $this
    ->assertSession()
    ->buildXPathQuery('//div[@id="views-live-preview"]//ul[contains(@class, :ul-class)]/li/a[contains(@href, :href)]', [
    ':ul-class' => 'contextual-links',
    ':href' => '/admin/structure/views/nojs/add-handler/test_preview/default/filter',
  ]);
  $this
    ->assertSession()
    ->elementsCount('xpath', $selector, 1);
  $this
    ->submitForm([
    'view_args' => '100',
  ], 'Update preview');

  // Test that area text and exposed filters are present and rendered.
  $this
    ->assertSession()
    ->fieldExists('id');
  $this
    ->assertSession()
    ->pageTextContains('Test header text');
  $this
    ->assertSession()
    ->pageTextContains('Test footer text');
  $this
    ->assertSession()
    ->pageTextContains('Test empty text');
  $this
    ->submitForm([
    'view_args' => '0',
  ], 'Update preview');

  // Test that area text and exposed filters are present and rendered.
  $this
    ->assertSession()
    ->fieldExists('id');
  $this
    ->assertSession()
    ->pageTextContains('Test header text');
  $this
    ->assertSession()
    ->pageTextContains('Test footer text');
  $this
    ->assertSession()
    ->pageTextContains('Test empty text');
}