function CKEditorAdminTest::testNewFormat in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/ckeditor/src/Tests/CKEditorAdminTest.php \Drupal\ckeditor\Tests\CKEditorAdminTest::testNewFormat()
Tests configuring a text editor for a new text format.
This test only needs to ensure that the basics of the CKEditor configuration form work; details are tested in testExistingFormat().
File
- core/
modules/ ckeditor/ src/ Tests/ CKEditorAdminTest.php, line 229 - Contains \Drupal\ckeditor\Tests\CKEditorAdminTest.
Class
- CKEditorAdminTest
- Tests administration of CKEditor.
Namespace
Drupal\ckeditor\TestsCode
function testNewFormat() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/content/formats/add');
// Verify the "Text Editor" <select> 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);
// Regression test for https://www.drupal.org/node/2606460.
$this
->assertTrue(strpos($this->drupalSettings['ckeditor']['toolbarAdmin'], '<li data-drupal-ckeditor-button-name="Bold" class="ckeditor-button"><a href="#" class="cke-icon-only cke_ltr" role="button" title="bold" aria-label="bold"><span class="cke_button_icon cke_button__bold_icon">bold</span></a></li>') !== FALSE);
// 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.');
}