File
- drupal/core/modules/ckeditor/lib/Drupal/ckeditor/Tests/CKEditorAdminTest.php, line 49
- Definition of \Drupal\ckeditor\Tests\CKEditorAdminTest.
Class
- CKEditorAdminTest
- Tests administration of CKEditor.
Namespace
Drupal\ckeditor\Tests
Code
function testAdmin() {
$manager = drupal_container()
->get('plugin.manager.editor');
$ckeditor = $manager
->createInstance('ckeditor');
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('admin/config/content/formats/filtered_html');
$editor = entity_load('editor', 'filtered_html');
$this
->assertFalse($editor, 'No Editor config entity exists yet.');
$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.');
$edit = array(
'editor[editor]' => 'ckeditor',
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$this
->assertRaw(t('You must configure the selected text editor.'));
$expected_default_settings = array(
'toolbar' => array(
'buttons' => array(
array(
'Bold',
'Italic',
'|',
'Link',
'Unlink',
'|',
'BulletedList',
'NumberedList',
'|',
'Blockquote',
'Image',
'|',
'Source',
),
),
),
'plugins' => array(),
);
$this
->assertIdentical($ckeditor
->getDefaultSettings(), $expected_default_settings);
$this
->drupalPostAjax(NULL, $edit, 'editor_configure');
$editor = entity_load('editor', 'filtered_html');
$this
->assertFalse($editor, 'No Editor config entity exists yet.');
$expected_buttons_value = json_encode($expected_default_settings['toolbar']['buttons']);
$this
->assertFieldByName('editor[settings][toolbar][buttons]', $expected_buttons_value);
$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.');
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$expected_settings = $expected_default_settings;
$expected_settings['plugins']['stylescombo']['styles'] = '';
$editor = entity_load('editor', 'filtered_html');
$this
->assertTrue($editor instanceof Editor, 'An Editor config entity exists now.');
$this
->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.');
$this
->drupalGet('admin/config/content/formats/filtered_html');
$edit = array(
'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n",
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
$editor = entity_load('editor', 'filtered_html');
$this
->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this
->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.');
$this
->drupalGet('admin/config/content/formats/filtered_html');
$expected_settings['toolbar']['buttons'] = array(
array(
'Undo',
'|',
'Redo',
),
array(
'JustifyCenter',
),
);
$edit = array(
'editor[settings][toolbar][buttons]' => json_encode($expected_settings['toolbar']['buttons']),
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$editor = entity_load('editor', 'filtered_html');
$this
->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this
->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.');
module_enable(array(
'ckeditor_test',
));
drupal_container()
->get('plugin.manager.ckeditor.plugin')
->clearCachedDefinitions();
$this
->drupalGet('admin/config/content/formats/filtered_html');
$ultra_llama_mode_checkbox = $this
->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and not(@checked)]');
$this
->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is not checked.');
$editor = entity_load('editor', 'filtered_html');
$this
->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this
->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.');
$this
->drupalGet('admin/config/content/formats/filtered_html');
$edit = array(
'editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]' => '1',
);
$this
->drupalPost(NULL, $edit, t('Save configuration'));
$this
->drupalGet('admin/config/content/formats/filtered_html');
$ultra_llama_mode_checkbox = $this
->xpath('//input[@type="checkbox" and @name="editor[settings][plugins][llama_contextual_and_button][ultra_llama_mode]" and @checked="checked"]');
$this
->assertTrue(count($ultra_llama_mode_checkbox) === 1, 'The "Ultra llama mode" checkbox exists and is checked.');
$expected_settings['plugins']['llama_contextual_and_button']['ultra_llama_mode'] = '1';
$editor = entity_load('editor', 'filtered_html');
$this
->assertTrue($editor instanceof Editor, 'An Editor config entity exists.');
$this
->assertIdentical($expected_settings, $editor->settings, 'The Editor config entity has the correct settings.');
}