View source
<?php
namespace Drupal\Tests\inline_form_errors\FunctionalJavascript;
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\editor\Entity\Editor;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
use Drupal\user\RoleInterface;
class FormErrorHandlerCKEditor5Test extends WebDriverTestBase {
protected static $modules = [
'node',
'ckeditor5',
'inline_form_errors',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
FilterFormat::create([
'format' => 'ckeditor5',
'name' => 'CKEditor 5 with image upload',
'roles' => [
RoleInterface::AUTHENTICATED_ID,
],
])
->save();
Editor::create([
'format' => 'ckeditor5',
'editor' => 'ckeditor5',
])
->save();
NodeType::create([
'type' => 'page',
'name' => 'page',
])
->save();
$field_storage = FieldStorageConfig::loadByName('node', 'body');
FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'page',
'label' => 'Body',
'settings' => [
'display_summary' => TRUE,
],
'required' => TRUE,
])
->save();
EntityFormDisplay::create([
'targetEntityType' => 'node',
'bundle' => 'page',
'mode' => 'default',
'status' => TRUE,
])
->setComponent('body', [
'type' => 'text_textarea_with_summary',
])
->save();
$account = $this
->drupalCreateUser([
'administer nodes',
'create page content',
]);
$this
->drupalLogin($account);
}
public function testFragmentLink() {
$session = $this
->getSession();
$web_assert = $this
->assertSession();
$ckeditor_class = '.ck-editor';
$ckeditor_id = '#cke_edit-body-0-value';
$this
->drupalGet('node/add/page');
$edit = [
'edit-title-0-value' => 'Test inline form error with CKEditor 5',
];
$this
->submitForm($edit, 'Save');
$this
->assertSession()
->waitForElement('css', '#cke_edit-body-0-value');
$session
->executeScript("document.getElementById('edit-title-0-value').style.marginBottom = window.innerHeight*2 + 'px';");
$web_assert
->assertNotVisibleInViewport('css', $ckeditor_class, 'topLeft', 'CKEditor5-enabled body field is not visible.');
$errors_link = $this
->assertSession()
->waitForElementVisible('css', 'a[href$="#edit-body-0-value"]');
$this
->assertNotEmpty($errors_link, 'Error fragment link is visible.');
$errors_link
->click();
$web_assert
->assertVisibleInViewport('css', $ckeditor_id, 'topLeft', 'CKEditor5-enabled body field is visible.');
}
}