You are here

public function PreviewLinkAccessTest::testPreviewRealToken in Preview Link 8

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

Ensure access is allowed with a real token.

File

tests/src/Functional/PreviewLinkAccessTest.php, line 67

Class

PreviewLinkAccessTest
Test access to preview pages with valid/invalid tokens.

Namespace

Drupal\Tests\preview_link\Functional

Code

public function testPreviewRealToken() {
  $account = $this
    ->createUser([
    'view test entity',
  ]);
  $this
    ->drupalLogin($account);
  $entity = EntityTestRev::create();
  $entity
    ->save();
  $access = $entity
    ->access('view', $account, TRUE);

  // Make sure the current user has access to the entity.
  $this
    ->assertTrue($access
    ->isAllowed());

  // Create a temporary preview link entity to utilize whichever token
  // generation process is in use.
  $preview = $this
    ->getNewPreviewLinkForEntity($entity);
  $token = $preview
    ->getToken();
  $url = Url::fromRoute('entity.entity_test_rev.preview_link', [
    'entity_test_rev' => $entity
      ->id(),
    'preview_token' => $token,
  ]);
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->statusCodeEquals(200);
}