function WebAssertTest::testAddressEquals

Same name in this branch
  1. 10 core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testAddressEquals()
Same name in other branches
  1. 9 core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testAddressEquals()
  2. 11.x core/tests/Drupal/FunctionalTests/WebAssertTest.php \Drupal\FunctionalTests\WebAssertTest::testAddressEquals()
  3. 11.x core/tests/Drupal/Tests/Core/Test/WebAssertTest.php \Drupal\Tests\Core\Test\WebAssertTest::testAddressEquals()

@covers ::addressEquals

File

core/tests/Drupal/Tests/Core/Test/WebAssertTest.php, line 136

Class

WebAssertTest
Tests WebAssert functionality.

Namespace

Drupal\Tests\Core\Test

Code

public function testAddressEquals() : void {
    $this->visit('http://localhost/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->visit('http://localhost/test-page?a=b&c=d');
    $this->assertSession()
        ->addressEquals('test-page');
    $this->assertSession()
        ->addressEquals('test-page?a=b&c=d');
    $url = $this->createMock(Url::class);
    $url->expects($this->any())
        ->method('setAbsolute')
        ->willReturn($url);
    $url->expects($this->any())
        ->method('toString')
        ->willReturn('test-page?a=b&c=d');
    $this->assertSession()
        ->addressEquals($url);
    $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');
}

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