public function PreviewLinkTest::testPreviewLinkPage in Preview Link 2.0.x
Same name and namespace in other branches
- 8 tests/src/Functional/PreviewLinkTest.php \Drupal\Tests\preview_link\Functional\PreviewLinkTest::testPreviewLinkPage()
- 2.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 80
Class
- PreviewLinkTest
- Integration test for the preview link.
Namespace
Drupal\Tests\preview_link\FunctionalCode
public function testPreviewLinkPage() : void {
/** @var \Drupal\preview_link_test_time\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 = $this->node
->toUrl('preview-link-generate');
$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, [], 'Save and 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());
}