You are here

public function PreviewLinkExpiryTest::testPreviewLinkExpires in Preview Link 2.x

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

Test preview links are automatically expired on cron.

File

tests/src/Kernel/PreviewLinkExpiryTest.php, line 54

Class

PreviewLinkExpiryTest
Preview link expiry test.

Namespace

Drupal\Tests\preview_link\Kernel

Code

public function testPreviewLinkExpires() : void {
  $days = \Drupal::state()
    ->get('preview_link_expiry_days', 7);

  // Add an extra day to make it expired.
  $days = $days + 1;
  $days_in_seconds = $days * 86400;
  $expired_preview_link = PreviewLink::create()
    ->addEntity($this->node);

  // Set a timestamp that will definitely be expired.
  $expired_preview_link->generated_timestamp = $days_in_seconds;
  $expired_preview_link
    ->save();
  $id = $expired_preview_link
    ->id();

  // Run cron and then ensure the entity is gone.
  preview_link_cron();
  $this
    ->assertNull($this->storage
    ->load($id));
}