function ConfirmFormHelperTest::testCancelLinkDestination

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php \Drupal\Tests\Core\Form\ConfirmFormHelperTest::testCancelLinkDestination()
  2. 8.9.x core/tests/Drupal/Tests/Core/Form/ConfirmFormHelperTest.php \Drupal\Tests\Core\Form\ConfirmFormHelperTest::testCancelLinkDestination()
  3. 11.x 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 99

Class

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

Namespace

Drupal\Tests\Core\Form

Code

public function testCancelLinkDestination($destination) : void {
    $query = [
        'destination' => $destination,
    ];
    $form = $this->createMock('Drupal\\Core\\Form\\ConfirmFormInterface');
    $path_validator = $this->createMock('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']);
}

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