function ConfirmFormTest::testConfirmFormWithExternalDestination

Same name in other branches
  1. 8.9.x core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php \Drupal\Tests\system\Functional\Form\ConfirmFormTest::testConfirmFormWithExternalDestination()
  2. 10 core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php \Drupal\Tests\system\Functional\Form\ConfirmFormTest::testConfirmFormWithExternalDestination()
  3. 11.x core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php \Drupal\Tests\system\Functional\Form\ConfirmFormTest::testConfirmFormWithExternalDestination()

Tests that the confirm form does not use external destinations.

File

core/modules/system/tests/src/Functional/Form/ConfirmFormTest.php, line 60

Class

ConfirmFormTest
Tests confirmation forms.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testConfirmFormWithExternalDestination() {
    $this->drupalGet('form-test/confirm-form');
    $this->assertSession()
        ->linkByHrefExists(Url::fromRoute('form_test.route8')->toString());
    $this->drupalGet('form-test/confirm-form', [
        'query' => [
            'destination' => 'node',
        ],
    ]);
    $this->assertSession()
        ->linkByHrefExists(Url::fromUri('internal:/node')->toString());
    $this->drupalGet('form-test/confirm-form', [
        'query' => [
            'destination' => 'http://example.com',
        ],
    ]);
    $this->assertSession()
        ->linkByHrefExists(Url::fromRoute('form_test.route8')->toString());
    $this->drupalGet('form-test/confirm-form', [
        'query' => [
            'destination' => '<front>',
        ],
    ]);
    $this->assertSession()
        ->linkByHrefExists(Url::fromRoute('<front>')->toString());
    // Other invalid destinations, should fall back to the form default.
    $this->drupalGet('form-test/confirm-form', [
        'query' => [
            'destination' => '/http://example.com',
        ],
    ]);
    $this->assertSession()
        ->linkByHrefExists(Url::fromRoute('form_test.route8')->toString());
}

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