You are here

public function CKEditorIntegrationTest::testFragmentLink in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php \Drupal\Tests\ckeditor\FunctionalJavascript\CKEditorIntegrationTest::testFragmentLink()

Tests if the fragment link to a textarea works with CKEditor enabled.

File

core/modules/ckeditor/tests/src/FunctionalJavascript/CKEditorIntegrationTest.php, line 100

Class

CKEditorIntegrationTest
Tests the integration of CKEditor.

Namespace

Drupal\Tests\ckeditor\FunctionalJavascript

Code

public function testFragmentLink() {
  $session = $this
    ->getSession();
  $web_assert = $this
    ->assertSession();
  $ckeditor_id = '#cke_edit-body-0-value';
  $this
    ->drupalGet('node/add/page');
  $session
    ->getPage();

  // Add a bottom margin to the title field to be sure the body field is not
  // visible.
  $session
    ->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = window.innerHeight*2 +'px';");
  $this
    ->assertSession()
    ->waitForElementVisible('css', $ckeditor_id);

  // Check that the CKEditor-enabled body field is currently not visible in
  // the viewport.
  $web_assert
    ->assertNotVisibleInViewport('css', $ckeditor_id, 'topLeft', 'CKEditor-enabled body field is visible.');
  $before_url = $session
    ->getCurrentUrl();

  // Trigger a hash change with as target the hidden textarea.
  $session
    ->executeScript("location.hash = '#edit-body-0-value';");

  // Check that the CKEditor-enabled body field is visible in the viewport.
  $web_assert
    ->assertVisibleInViewport('css', $ckeditor_id, 'topLeft', 'CKEditor-enabled body field is not visible.');

  // Use JavaScript to go back in the history instead of
  // \Behat\Mink\Session::back() because that function doesn't work after a
  // hash change.
  $session
    ->executeScript("history.back();");
  $after_url = $session
    ->getCurrentUrl();

  // Check that going back in the history worked.
  self::assertEquals($before_url, $after_url, 'History back works.');
}