'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => [], ]); $filtered_html_format->save(); // Create admin user. $this->adminUser = $this->drupalCreateUser(['administer filters']); } /** * Tests configuring a text editor for an existing text format. */ public function testExistingFormat() { $ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor'); $this->drupalLogin($this->adminUser); $this->drupalGet('admin/config/content/formats/manage/filtered_html'); // Ensure no Editor config entity exists yet. $editor = Editor::load('filtered_html'); $this->assertNull($editor, 'No Editor config entity exists yet.'); // Verify the "Text Editor" when a text editor is available. $select = $this->xpath('//select[@name="editor[editor]"]'); $select_is_disabled = $this->xpath('//select[@name="editor[editor]" and @disabled="disabled"]'); $options = $this->xpath('//select[@name="editor[editor]"]/option'); $this->assertCount(1, $select, 'The Text Editor select exists.'); $this->assertCount(0, $select_is_disabled, 'The Text Editor select is not disabled.'); $this->assertCount(2, $options, 'The Text Editor select has two options.'); $this->assertSame('None', $options[0]->getText(), 'Option 1 in the Text Editor select is "None".'); $this->assertSame('CKEditor', $options[1]->getText(), 'Option 2 in the Text Editor select is "CKEditor".'); $this->assertSame('selected', $options[0]->getAttribute('selected'), 'Option 1 ("None") is selected.'); // Name our fancy new text format, select the "CKEditor" editor and click // the "Configure" button. $edit = [ 'name' => 'My amazing text format', 'format' => 'amazing_format', 'editor[editor]' => 'ckeditor', ]; $this->drupalPostForm(NULL, $edit, 'editor_configure'); $filter_format = FilterFormat::load('amazing_format'); $this->assertNull($filter_format, 'No FilterFormat config entity exists yet.'); $editor = Editor::load('amazing_format'); $this->assertNull($editor, 'No Editor config entity exists yet.'); // Ensure the toolbar buttons configuration value is initialized to the // default value. $ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor'); $default_settings = $ckeditor->getDefaultSettings(); $expected_buttons_value = json_encode($default_settings['toolbar']['rows']); $this->assertSession()->fieldValueEquals('editor[settings][toolbar][button_groups]', $expected_buttons_value); // Regression test for https://www.drupal.org/node/2606460. $settings = $this->getDrupalSettings(); $expected = $settings['ckeditor']['toolbarAdmin']; $this->assertStringContainsString('
  • bold
  • ', $expected); // Ensure the styles textarea exists and is initialized empty. $styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]'); $this->assertSession()->fieldValueEquals('editor[settings][plugins][stylescombo][styles]', ''); $this->assertCount(1, $styles_textarea, 'The "styles" textarea exists.'); // Submit the form to create both a new text format and an associated text // editor. $this->drupalPostForm(NULL, $edit, t('Save configuration')); // Ensure a FilterFormat object exists now. $filter_format = FilterFormat::load('amazing_format'); $this->assertInstanceOf(FilterFormatInterface::class, $filter_format); // Ensure an Editor object exists now, with the proper settings. $expected_settings = $default_settings; $expected_settings['plugins']['stylescombo']['styles'] = ''; $editor = Editor::load('amazing_format'); $this->assertInstanceOf(Editor::class, $editor); $this->assertEquals($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.'); } }