3 namespace Drupal\Tests\inline_form_errors\FunctionalJavascript;
5 use Drupal\Core\Entity\Entity\EntityFormDisplay;
6 use Drupal\editor\Entity\Editor;
7 use Drupal\field\Entity\FieldConfig;
8 use Drupal\field\Entity\FieldStorageConfig;
9 use Drupal\filter\Entity\FilterFormat;
10 use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
11 use Drupal\node\Entity\NodeType;
14 * Tests the inline errors fragment link to a CKEditor-enabled textarea.
18 class FormErrorHandlerCKEditorTest extends WebDriverTestBase {
23 public static $modules = ['node', 'ckeditor', 'inline_form_errors', 'filter'];
28 protected function setUp() {
31 // Create a text format and associate CKEditor.
32 $filtered_html_format = FilterFormat::create([
33 'format' => 'filtered_html',
34 'name' => 'Filtered HTML',
37 $filtered_html_format->save();
40 'format' => 'filtered_html',
41 'editor' => 'ckeditor',
44 // Create a node type for testing.
45 NodeType::create(['type' => 'page', 'name' => 'page'])->save();
47 $field_storage = FieldStorageConfig::loadByName('node', 'body');
49 // Create a body field instance for the 'page' node type.
51 'field_storage' => $field_storage,
54 'settings' => ['display_summary' => TRUE],
58 // Assign widget settings for the 'default' form mode.
59 EntityFormDisplay::create([
60 'targetEntityType' => 'node',
64 ])->setComponent('body', ['type' => 'text_textarea_with_summary'])
67 $account = $this->drupalCreateUser([
69 'create page content',
70 'use text format filtered_html',
72 $this->drupalLogin($account);
76 * Tests if the fragment link to a textarea works with CKEditor enabled.
78 public function testFragmentLink() {
79 $session = $this->getSession();
80 $web_assert = $this->assertSession();
81 $ckeditor_id = '#cke_edit-body-0-value';
83 $this->drupalGet('node/add/page');
85 // Only enter a title in the node add form and leave the body field empty.
86 $edit = ['edit-title-0-value' => 'Test inline form error with CKEditor'];
88 $this->submitForm($edit, 'Save');
90 $this->assertSession()->waitForElement('css', '#cke_edit-body-0-value');
91 // Add a bottom margin to the title field to be sure the body field is not
93 $session->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = window.innerHeight*2 + 'px';");
95 // Check that the CKEditor-enabled body field is currently not visible in
97 $web_assert->assertNotVisibleInViewport('css', $ckeditor_id, 'topLeft', 'CKEditor-enabled body field is not visible.');
99 // Check if we can find the error fragment link within the errors summary
101 $errors_link = $this->assertSession()->waitForElementVisible('css', '.messages--error a[href="#edit-body-0-value"]');
102 $this->assertNotEmpty($errors_link, 'Error fragment link is visible.');
104 $errors_link->click();
106 // Check that the CKEditor-enabled body field is visible in the viewport.
107 $web_assert->assertVisibleInViewport('css', $ckeditor_id, 'topLeft', 'CKEditor-enabled body field is visible.');