You are here

public function PreviewLinkStorageTest::testRegenerateToken in Preview Link 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/PreviewLinkStorageTest.php \Drupal\Tests\preview_link\Kernel\PreviewLinkStorageTest::testRegenerateToken()
  2. 2.x tests/src/Kernel/PreviewLinkStorageTest.php \Drupal\Tests\preview_link\Kernel\PreviewLinkStorageTest::testRegenerateToken()

Ensure we can re-generate a token.

File

tests/src/Kernel/PreviewLinkStorageTest.php, line 67

Class

PreviewLinkStorageTest
Preview link session test.

Namespace

Drupal\Tests\preview_link\Kernel

Code

public function testRegenerateToken() : void {
  $preview_link = PreviewLink::create()
    ->addEntity($this->node);
  $preview_link
    ->save();
  $current_token = $preview_link
    ->getToken();
  $current_timestamp = $preview_link
    ->getGeneratedTimestamp();

  // Regenerate and ensure it changed.
  $preview_link
    ->regenerateToken(TRUE);
  $preview_link
    ->save();
  $this
    ->assertNotEquals($current_token, $preview_link
    ->getToken());
  $this
    ->assertNotEquals($current_timestamp, $preview_link
    ->getGeneratedTimestamp());
}