NodePreviewLinkTest.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace Drupal\Tests\node\FunctionalJavascript;
  3. use Drupal\filter\Entity\FilterFormat;
  4. use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
  5. /**
  6. * Tests the JavaScript prevention of navigation away from node previews.
  7. *
  8. * @group node
  9. */
  10. class NodePreviewLinkTest extends WebDriverTestBase {
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public static $modules = ['node', 'filter'];
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function setUp() {
  19. parent::setUp();
  20. $filtered_html_format = FilterFormat::create([
  21. 'format' => 'filtered_html',
  22. 'name' => 'Filtered HTML',
  23. ]);
  24. $filtered_html_format->save();
  25. $this->drupalCreateContentType(['type' => 'test']);
  26. $user = $this->drupalCreateUser([
  27. 'access content',
  28. 'edit own test content',
  29. 'create test content',
  30. $filtered_html_format->getPermissionName(),
  31. ]);
  32. $this->drupalLogin($user);
  33. }
  34. /**
  35. * Test the behavior of clicking preview links.
  36. */
  37. public function testPreviewLinks() {
  38. $assertSession = $this->assertSession();
  39. $this->drupalPostForm('node/add/test', [
  40. 'title[0][value]' => 'Test node',
  41. 'body[0][value]' => '<a href="#foo">Anchor link</a><a href="/foo">Normal link</a>',
  42. ], t('Preview'));
  43. $this->clickLink('Anchor link');
  44. $assertSession->pageTextNotContains('Leave preview?');
  45. $this->clickLink('Normal link');
  46. $assertSession->pageTextContains('Leave preview?');
  47. $this->click('button:contains("Leave preview")');
  48. $this->assertStringEndsWith('/foo', $this->getUrl());
  49. }
  50. }