You are here

public function AccessTest::testAccessWithExpiredToken in Access unpublished 8

Checks entity access before and after token creation.

File

tests/src/Functional/AccessTest.php, line 102

Class

AccessTest
Tests the article creation.

Namespace

Drupal\Tests\access_unpublished\Functional

Code

public function testAccessWithExpiredToken() {
  $assert_session = $this
    ->assertSession();

  // Create a token for the entity.
  $token = AccessToken::create([
    'entity_type' => 'node',
    'entity_id' => $this->entity
      ->id(),
    'value' => '12345',
    'expire' => \Drupal::time()
      ->getRequestTime() - 100,
  ]);
  $token
    ->save();

  // Verify that entity is accessible, but only with the correct hash.
  $this
    ->drupalGet($this->entity
    ->toUrl('canonical'), [
    'query' => [
      'auHash' => 12345,
    ],
  ]);
  $assert_session
    ->statusCodeEquals(403);
}