public function PreviewLinkTest::testPreviewLinkPage in Preview Link 8
Same name and namespace in other branches
- 2.x tests/src/Functional/PreviewLinkTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkTest::testPreviewLinkPage()
- 2.0.x tests/src/Functional/PreviewLinkTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkTest::testPreviewLinkPage()
Test the preview link page.
File
- tests/
src/ Functional/ PreviewLinkTest.php, line 69
Class
- PreviewLinkTest
- Integration test for the preview link.
Namespace
Drupal\Tests\preview_link\FunctionalCode
public function testPreviewLinkPage() {
/** @var \Drupal\preview_link_test\TimeMachine $timeMachine */
$timeMachine = \Drupal::service('datetime.time');
$timeMachine
->setTime(new \DateTime('14 May 2014 14:00:00'));
$assert = $this
->assertSession();
// Can only be visited by users with correct permission.
$url = Url::fromRoute('entity.node.generate_preview_link', [
'node' => $this->node
->id(),
]);
$this
->drupalGet($url);
$assert
->statusCodeEquals(403);
$this
->drupalLogin($this->admin);
$this
->drupalGet($url);
$assert
->statusCodeEquals(200);
// Grab the link from the page and ensure it works.
$link = $this
->cssSelect('.preview-link__link')[0]
->getText();
$this
->assertSession()
->pageTextContains('Expiry: 1 week');
$this
->drupalGet($link);
$assert
->statusCodeEquals(200);
$assert
->responseContains($this->node
->getTitle());
// Submitting form re-generates the link.
$this
->drupalPostForm($url, [], 'Regenerate preview link');
$new_link = $this
->cssSelect('.preview-link__link')[0]
->getText();
$this
->assertNotEquals($link, $new_link);
// Old link doesn't work.
$this
->drupalGet($link);
$assert
->statusCodeEquals(403);
$assert
->responseNotContains($this->node
->getTitle());
// New link does work.
$this
->drupalGet($new_link);
$assert
->statusCodeEquals(200);
$assert
->responseContains($this->node
->getTitle());
// Logout, new link works for anonymous user.
$this
->drupalLogout();
$this
->drupalGet($new_link);
$assert
->statusCodeEquals(200);
$assert
->responseContains($this->node
->getTitle());
}