public function WidgetTestTrait::testWidgetEditor in The CodeMirror Editor 8
Test callback.
File
- tests/
src/ FunctionalJavascript/ WidgetTestTrait.php, line 18
Class
- WidgetTestTrait
- Provides a helper methods to for testing widgets.
Namespace
Drupal\Tests\codemirror_editor\FunctionalJavascriptCode
public function testWidgetEditor() {
$page = $this
->getSession()
->getPage();
$permissions = [
'administer node fields',
'administer node form display',
'create ' . $this->contentTypeName . ' content',
'edit any ' . $this->contentTypeName . ' content',
];
$user = $this
->drupalCreateUser($permissions);
$this
->drupalLogin($user);
// Default widget settings.
$widget_settings = [
'rows' => 5,
'placeholder' => '',
'mode' => 'text/html',
'toolbar' => TRUE,
'buttons' => $this
->getAvailableButtons(),
'lineWrapping' => FALSE,
'lineNumbers' => FALSE,
'foldGutter' => FALSE,
'autoCloseTags' => TRUE,
'styleActiveLine' => FALSE,
];
$this
->drupalGet('node/add/' . $this->contentTypeName);
$this
->assertWidgetForm($widget_settings);
$this
->drupalGet('admin/structure/types/manage/' . $this->contentTypeName . '/form-display');
$this
->assertWidgetSettingsSummary($widget_settings);
$this
->click('//input[@name = "' . $this->fieldName . '_settings_edit"]');
$this
->assertWidgetSettingsForm($widget_settings);
$widget_settings = [
'rows' => 10,
'placeholder' => 'Example',
'mode' => 'application/xml',
'toolbar' => FALSE,
'buttons' => [],
'lineWrapping' => TRUE,
'lineNumbers' => TRUE,
'foldGutter' => TRUE,
'autoCloseTags' => FALSE,
'styleActiveLine' => TRUE,
];
$this
->updateWidgetSettingField('rows', $widget_settings['rows']);
$this
->updateWidgetSettingField('placeholder', $widget_settings['placeholder']);
$this
->updateWidgetSettingField('mode', $widget_settings['mode']);
// Verify buttons select field is visible.
$element = $page
->find('xpath', "//select[@name='fields[{$this->fieldName}][settings_edit_form][settings][buttons][]']");
$this
->assertTrue($element
->isVisible());
$this
->updateWidgetSettingField('toolbar', $widget_settings['toolbar']);
// Verify buttons select is not longer visible.
$this
->assertFalse($element
->isVisible());
$this
->updateWidgetSettingField('lineWrapping', $widget_settings['lineWrapping']);
$this
->updateWidgetSettingField('lineNumbers', $widget_settings['lineNumbers']);
$this
->updateWidgetSettingField('foldGutter', $widget_settings['foldGutter']);
$this
->updateWidgetSettingField('autoCloseTags', $widget_settings['autoCloseTags']);
$this
->updateWidgetSettingField('styleActiveLine', $widget_settings['styleActiveLine']);
$page = $this
->getSession()
->getPage();
$page
->pressButton($this->fieldName . '_plugin_settings_update');
$this
->assertSession()
->waitForElementVisible('xpath', '//select[@name = "fields[' . $this->fieldName . '][type]"]');
$page
->pressButton('Save');
$this
->assertSession()
->pageTextContains('Your settings have been saved.');
$this
->assertWidgetSettingsSummary($widget_settings);
$this
->drupalGet('node/add/' . $this->contentTypeName);
$this
->assertWidgetForm($widget_settings);
$page
->fillField('Title', 'Example');
$this
->editorSetValue('It works!');
$page
->pressButton('Save');
$this
->assertSession()
->pageTextContains('It works!');
$this
->drupalGet('node/1/edit');
$this
->assertEditorValue('It works!');
}