You are here

public function ConfirmFormTest::testConfirmFormWithExternalDestination in Drupal 9

Same name and namespace in other branches
  1. 8 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()

Tests that the confirm form does not use external destinations.

File

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

Class

ConfirmFormTest
Tests confirmation forms.

Namespace

Drupal\Tests\system\Functional\Form

Code

public function testConfirmFormWithExternalDestination() {
  $this
    ->drupalGet('form-test/confirm-form');
  $this
    ->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
  $this
    ->drupalGet('form-test/confirm-form', [
    'query' => [
      'destination' => 'node',
    ],
  ]);
  $this
    ->assertCancelLinkUrl(Url::fromUri('internal:/node'));
  $this
    ->drupalGet('form-test/confirm-form', [
    'query' => [
      'destination' => 'http://example.com',
    ],
  ]);
  $this
    ->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
  $this
    ->drupalGet('form-test/confirm-form', [
    'query' => [
      'destination' => '<front>',
    ],
  ]);
  $this
    ->assertCancelLinkUrl(Url::fromRoute('<front>'));

  // Other invalid destinations, should fall back to the form default.
  $this
    ->drupalGet('form-test/confirm-form', [
    'query' => [
      'destination' => '/http://example.com',
    ],
  ]);
  $this
    ->assertCancelLinkUrl(Url::fromRoute('form_test.route8'));
}