You are here

public function FormErrorHandlerCKEditorTest::testFragmentLink in Drupal 8

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

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

File

core/modules/inline_form_errors/tests/src/FunctionalJavascript/FormErrorHandlerCKEditorTest.php, line 88

Class

FormErrorHandlerCKEditorTest
Tests the inline errors fragment link to a CKEditor-enabled textarea.

Namespace

Drupal\Tests\inline_form_errors\FunctionalJavascript

Code

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

  // Only enter a title in the node add form and leave the body field empty.
  $edit = [
    'edit-title-0-value' => 'Test inline form error with CKEditor',
  ];
  $this
    ->submitForm($edit, 'Save');
  $this
    ->assertSession()
    ->waitForElement('css', '#cke_edit-body-0-value');

  // 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';");

  // 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 not visible.');

  // Check if we can find the error fragment link within the errors summary
  // message.
  $errors_link = $this
    ->assertSession()
    ->waitForElementVisible('css', '.messages--error a[href="#edit-body-0-value"]');
  $this
    ->assertNotEmpty($errors_link, 'Error fragment link is visible.');
  $errors_link
    ->click();

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