You are here

public function ConfirmFormHelperTest::testCancelLinkDestination in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php \Drupal\Tests\Core\Form\ConfirmFormHelperTest::testCancelLinkDestination()

@covers ::buildCancelLink

Tests a cancel link provided by the destination.

@dataProvider providerTestCancelLinkDestination

File

core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php, line 102
Contains \Drupal\Tests\Core\Form\ConfirmFormHelperTest.

Class

ConfirmFormHelperTest
@coversDefaultClass \Drupal\Core\Form\ConfirmFormHelper @group Form

Namespace

Drupal\Tests\Core\Form

Code

public function testCancelLinkDestination($destination) {
  $query = array(
    'destination' => $destination,
  );
  $form = $this
    ->getMock('Drupal\\Core\\Form\\ConfirmFormInterface');
  $path_validator = $this
    ->getMock('Drupal\\Core\\Path\\PathValidatorInterface');
  $container_builder = new ContainerBuilder();
  $container_builder
    ->set('path.validator', $path_validator);
  \Drupal::setContainer($container_builder);
  $url = Url::fromRoute('test_route');
  $path_validator
    ->expects($this
    ->atLeastOnce())
    ->method('getUrlIfValidWithoutAccessCheck')
    ->with('baz')
    ->willReturn($url);
  $link = ConfirmFormHelper::buildCancelLink($form, new Request($query));
  $this
    ->assertSame($url, $link['#url']);
  $this
    ->assertSame([
    'contexts' => [
      'url.query_args:destination',
    ],
  ], $link['#cache']);
}