You are here

public function DisplayPageWebTest::testArguments in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php \Drupal\Tests\views\Functional\Plugin\DisplayPageWebTest::testArguments()

Tests arguments.

File

core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php, line 50

Class

DisplayPageWebTest
Tests the views page display plugin as webtest.

Namespace

Drupal\Tests\views\Functional\Plugin

Code

public function testArguments() {
  $xpath = '//span[@class="field-content"]';

  // Ensure that all the entries are returned.
  $this
    ->drupalGet('test_route_without_arguments');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementsCount('xpath', $xpath, 5);
  $this
    ->drupalGet('test_route_without_arguments/1');
  $this
    ->assertSession()
    ->statusCodeEquals(404);

  // Ensure that just the filtered entry is returned.
  $this
    ->drupalGet('test_route_with_argument/1');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertCacheContexts([
    'languages:language_interface',
    'route',
    'theme',
    'url',
  ]);
  $this
    ->assertSession()
    ->elementsCount('xpath', $xpath, 1);
  $this
    ->assertSession()
    ->elementTextEquals('xpath', $xpath, 1);

  // Ensure that just the filtered entry is returned.
  $this
    ->drupalGet('test_route_with_suffix/1/suffix');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementsCount('xpath', $xpath, 1);
  $this
    ->assertSession()
    ->elementTextEquals('xpath', $xpath, 1);

  // Ensure that no result is returned.
  $this
    ->drupalGet('test_route_with_suffix_and_argument/1/suffix/2');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementNotExists('xpath', $xpath);

  // Ensure that just the filtered entry is returned.
  $this
    ->drupalGet('test_route_with_suffix_and_argument/1/suffix/1');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementsCount('xpath', $xpath, 1);
  $this
    ->assertSession()
    ->elementTextEquals('xpath', $xpath, 1);

  // Ensure that just the filtered entry is returned.
  $this
    ->drupalGet('test_route_with_long_argument/1');
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $this
    ->assertSession()
    ->elementsCount('xpath', $xpath, 1);
  $this
    ->assertSession()
    ->elementTextEquals('xpath', $xpath, 1);
}