'filtered_html', 'name' => 'Filtered HTML', 'weight' => 0, 'filters' => array(), )); $filtered_html_format->save(); // Create admin user. $this->adminUser = $this->drupalCreateUser(array('administer filters')); } /** * Tests configuring a text editor for an existing text format. */ 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 = entity_load('editor', 'filtered_html'); $this->assertFalse($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->assertTrue(count($select) === 1, 'The Text Editor select exists.'); $this->assertTrue(count($select_is_disabled) === 0, 'The Text Editor select is not disabled.'); $this->assertTrue(count($options) === 2, 'The Text Editor select has two options.'); $this->assertTrue(((string) $options[0]) === 'None', 'Option 1 in the Text Editor select is "None".'); $this->assertTrue(((string) $options[1]) === 'CKEditor', 'Option 2 in the Text Editor select is "CKEditor".'); $this->assertTrue(((string) $options[0]['selected']) === 'selected', 'Option 1 ("None") is selected.'); // Name our fancy new text format, select the "CKEditor" editor and click // the "Configure" button. $edit = array( 'name' => 'My amazing text format', 'format' => 'amazing_format', 'editor[editor]' => 'ckeditor', ); $this->drupalPostAjaxForm(NULL, $edit, 'editor_configure'); $filter_format = entity_load('filter_format', 'amazing_format'); $this->assertFalse($filter_format, 'No FilterFormat config entity exists yet.'); $editor = entity_load('editor', 'amazing_format'); $this->assertFalse($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->assertFieldByName('editor[settings][toolbar][button_groups]', $expected_buttons_value); // Ensure the styles textarea exists and is initialized empty. $styles_textarea = $this->xpath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]'); $this->assertFieldByXPath('//textarea[@name="editor[settings][plugins][stylescombo][styles]"]', '', 'The styles textarea exists and is empty.'); $this->assertTrue(count($styles_textarea) === 1, '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 = entity_load('filter_format', 'amazing_format'); $this->assertTrue($filter_format instanceof FilterFormatInterface, 'A FilterFormat config entity exists now.'); // Ensure an Editor object exists now, with the proper settings. $expected_settings = $default_settings; $expected_settings['plugins']['stylescombo']['styles'] = ''; $editor = entity_load('editor', 'amazing_format'); $this->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.'); $this->assertIdentical($this->castSafeStrings($expected_settings), $this->castSafeStrings($editor->getSettings()), 'The Editor config entity has the correct settings.'); } }