You are here

public function PreviewLinkSessionTokenTest::testRouteSimulateNoRedirect in Preview Link 2.0.x

Same name and namespace in other branches
  1. 2.x tests/src/Functional/PreviewLinkSessionTokenTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkSessionTokenTest::testRouteSimulateNoRedirect()

Test simulating route access doesnt result in a Preview Link redirection.

Ensures a user rendering a page which also simulates an access check to the canonical route doesnt get redirected to the Preview Link route. For example on the entity edit form, the breadcrumb will simulate the request on the canonical route because it renders a link to canonical.

File

tests/src/Functional/PreviewLinkSessionTokenTest.php, line 248

Class

PreviewLinkSessionTokenTest
Tests tokens claimed against sessions.

Namespace

Drupal\Tests\preview_link\Functional

Code

public function testRouteSimulateNoRedirect() : void {
  $this
    ->drupalPlaceBlock('system_breadcrumb_block');
  $this
    ->drupalLogin($this
    ->createUser([
    'view test entity',
    'administer entity_test content',
  ]));

  // Must be accessible.
  $claimedEntity = EntityTestMulRevPub::create();
  $claimedEntity
    ->save();
  $previewLink = PreviewLink::create()
    ->addEntity($claimedEntity);
  $previewLink
    ->save();

  // Claim the token to the session.
  $previewLinkUrl = Url::fromRoute('entity.entity_test_mulrevpub.preview_link', [
    $claimedEntity
      ->getEntityTypeId() => $claimedEntity
      ->id(),
    'preview_token' => $previewLink
      ->getToken(),
  ]);
  $this
    ->drupalGet($previewLinkUrl);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
  $editUrl = $claimedEntity
    ->toUrl('edit-form');
  $this
    ->drupalGet($editUrl);
  $this
    ->assertSession()
    ->addressEquals($editUrl
    ->toString());
}