You are here

public function PreviewLinkTest::testReset in Preview Link 2.0.x

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

Test preview link reset.

File

tests/src/Functional/PreviewLinkTest.php, line 127

Class

PreviewLinkTest
Integration test for the preview link.

Namespace

Drupal\Tests\preview_link\Functional

Code

public function testReset() : void {

  /** @var \Drupal\preview_link_test_time\TimeMachine $timeMachine */
  $timeMachine = \Drupal::service('datetime.time');
  $currentTime = new \DateTime('14 May 2014 14:00:00');
  $timeMachine
    ->setTime($currentTime);
  $this
    ->drupalLogin($this
    ->createUser([
    'generate preview links',
  ]));
  $entity = EntityTestRevPub::create();
  $entity
    ->save();
  $previewLink = PreviewLink::create()
    ->addEntity($entity);
  $previewLink
    ->save();
  $token = $previewLink
    ->getToken();
  $previewLink
    ->save();
  $this
    ->assertEquals($currentTime
    ->getTimestamp(), $previewLink
    ->getGeneratedTimestamp());
  $url = $entity
    ->toUrl('preview-link-generate');
  $this
    ->drupalGet($url);
  $this
    ->assertSession()
    ->pageTextContains('Generate a preview link for the entity.');
  $currentTime = new \DateTime('14 May 2014 20:00:00');
  $timeMachine
    ->setTime($currentTime);
  $this
    ->drupalPostForm(NULL, [], 'Reset lifetime');
  $this
    ->assertSession()
    ->pageTextContains('Preview link will now expire at Wed, 05/21/2014 - 20:00.');

  // Reload preview link.
  $previewLink = PreviewLink::load($previewLink
    ->id());
  $this
    ->assertEquals($currentTime
    ->getTimestamp(), $previewLink
    ->getGeneratedTimestamp());

  // Ensure token was not regenerated.
  $this
    ->assertEquals($token, $previewLink
    ->getToken());
}