function NodePreviewLinkTest::testPreviewLinks
Tests the behavior of clicking preview links.
File
- 
              core/
modules/ node/ tests/ src/ FunctionalJavascript/ NodePreviewLinkTest.php, line 55  
Class
- NodePreviewLinkTest
 - Tests the JavaScript prevention of navigation away from node previews.
 
Namespace
Drupal\Tests\node\FunctionalJavascriptCode
public function testPreviewLinks() : void {
  $assertSession = $this->assertSession();
  $this->drupalGet('node/add/test');
  $this->submitForm([
    'title[0][value]' => 'Test anchor link',
    'body[0][value]' => '<a href="#foo">Anchor link</a>',
  ], 'Preview');
  $this->clickLink('Anchor link');
  $assertSession->pageTextNotContains('Leave preview?');
  $this->drupalGet('node/add/test');
  $this->submitForm([
    'title[0][value]' => 'Test normal link',
    'body[0][value]' => '<a href="/foo">Normal link</a>',
  ], 'Preview');
  $this->clickLink('Normal link');
  $assertSession->pageTextContains('Leave preview?');
  $this->click('button:contains("Leave preview")');
  $this->assertStringEndsWith('/foo', $this->getUrl());
  $this->drupalGet('node/add/test');
  $this->submitForm([
    'title[0][value]' => 'Test child element link',
    'body[0][value]' => '<a href="/foo" class="preview-child-element"><span>Child element link</span></a>',
  ], 'Preview');
  $this->getSession()
    ->getPage()
    ->find('css', '.preview-child-element span')
    ->click();
  $assertSession->pageTextContains('Leave preview?');
  $this->click('button:contains("Leave preview")');
  $this->assertStringEndsWith('/foo', $this->getUrl());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.