function ConfirmFormHelperTest::testCancelLinkRoute

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php \Drupal\Tests\Core\Form\ConfirmFormHelperTest::testCancelLinkRoute()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php \Drupal\Tests\Core\Form\ConfirmFormHelperTest::testCancelLinkRoute()
  3. 11.x core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php \Drupal\Tests\Core\Form\ConfirmFormHelperTest::testCancelLinkRoute()

@covers ::buildCancelLink

Tests a cancel link route.

File

core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php, line 41

Class

ConfirmFormHelperTest
@coversDefaultClass \Drupal\Core\Form\ConfirmFormHelper[[api-linebreak]] @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testCancelLinkRoute() : void {
  $route_name = 'foo_bar';
  $cancel_route = new Url($route_name);
  $form = $this->createMock('Drupal\\Core\\Form\\ConfirmFormInterface');
  $form->expects($this->any())
    ->method('getCancelUrl')
    ->willReturn($cancel_route);
  $link = ConfirmFormHelper::buildCancelLink($form, new Request());
  $this->assertEquals(Url::fromRoute($route_name), $link['#url']);
  $this->assertSame([
    'contexts' => [
      'url.query_args:destination',
    ],
  ], $link['#cache']);
}

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