public function PreviewLinkTest::testReset in Preview Link 8
Same name and namespace in other branches
- 2.x tests/src/Functional/PreviewLinkTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkTest::testReset()
- 2.0.x tests/src/Functional/PreviewLinkTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkTest::testReset()
Test preview link reset.
File
- tests/
src/ Functional/ PreviewLinkTest.php, line 118
Class
- PreviewLinkTest
- Integration test for the preview link.
Namespace
Drupal\Tests\preview_link\FunctionalCode
public function testReset() {
/** @var \Drupal\preview_link_test\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();
$previewLinkStorage = \Drupal::entityTypeManager()
->getStorage('preview_link');
assert($previewLinkStorage instanceof PreviewLinkStorageInterface);
$previewLink = $previewLinkStorage
->createPreviewLinkForEntity($entity);
$token = $previewLink
->getToken();
$previewLink
->save();
$this
->assertEquals($currentTime
->getTimestamp(), $previewLink
->getGeneratedTimestamp());
$url = Url::fromRoute('entity.entity_test_revpub.generate_preview_link', [
'entity_test_revpub' => $entity
->id(),
]);
$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 = $previewLinkStorage
->getPreviewLinkForEntity($entity);
$this
->assertEquals($currentTime
->getTimestamp(), $previewLink
->getGeneratedTimestamp());
// Ensure token was not regenerated.
$this
->assertEquals($token, $previewLink
->getToken());
}