You are here

public function WebAssertTest::testAddressEquals in Drupal 9

@covers ::addressEquals

File

core/tests/Drupal/FunctionalTests/WebAssertTest.php, line 104

Class

WebAssertTest
Tests WebAssert functionality.

Namespace

Drupal\FunctionalTests

Code

public function testAddressEquals() : void {
  $this
    ->drupalGet('test-page');
  $this
    ->assertSession()
    ->addressEquals('test-page');
  $this
    ->assertSession()
    ->addressEquals('test-page?');
  $this
    ->assertSession()
    ->addressNotEquals('test-page?a=b');
  $this
    ->assertSession()
    ->addressNotEquals('other-page');
  $this
    ->drupalGet('test-page', [
    'query' => [
      'a' => 'b',
      'c' => 'd',
    ],
  ]);
  $this
    ->assertSession()
    ->addressEquals('test-page');
  $this
    ->assertSession()
    ->addressEquals('test-page?a=b&c=d');
  $this
    ->assertSession()
    ->addressEquals(Url::fromRoute('test_page_test.test_page', [], [
    'query' => [
      'a' => 'b',
      'c' => 'd',
    ],
  ]));
  $this
    ->assertSession()
    ->addressNotEquals('test-page?c=d&a=b');
  $this
    ->assertSession()
    ->addressNotEquals('test-page?a=b');
  $this
    ->assertSession()
    ->addressNotEquals('test-page?a=b&c=d&e=f');
  $this
    ->assertSession()
    ->addressNotEquals('other-page');
  $this
    ->assertSession()
    ->addressNotEquals('other-page?a=b&c=d');
  $this
    ->expectException(ExpectationException::class);
  $this
    ->expectExceptionMessage('Current page is "/test-page?a=b&c=d", but "/test-page?a=b&c=e" expected.');
  $this
    ->assertSession()
    ->addressEquals('test-page?a=b&c=e');
}