function CKEditorTest::testStylesComboGetConfig in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/ckeditor/src/Tests/CKEditorTest.php \Drupal\ckeditor\Tests\CKEditorTest::testStylesComboGetConfig()
Tests StylesCombo::getConfig().
File
- core/
modules/ ckeditor/ src/ Tests/ CKEditorTest.php, line 300 - Contains \Drupal\ckeditor\Tests\CKEditorTest.
Class
- CKEditorTest
- Tests for the 'CKEditor' text editor plugin.
Namespace
Drupal\ckeditor\TestsCode
function testStylesComboGetConfig() {
$editor = entity_load('editor', 'filtered_html');
$stylescombo_plugin = $this->container
->get('plugin.manager.ckeditor.plugin')
->createInstance('stylescombo');
// Styles dropdown/button enabled: new setting should be present.
$settings = $editor
->getSettings();
$settings['toolbar']['rows'][0][0]['items'][] = 'Styles';
$settings['plugins']['stylescombo']['styles'] = '';
$editor
->setSettings($settings);
$editor
->save();
$expected['stylesSet'] = array();
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Configure the optional "styles" setting in odd ways that shouldn't affect
// the end result.
$settings['plugins']['stylescombo']['styles'] = " \n";
$editor
->setSettings($settings);
$editor
->save();
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor));
$settings['plugins']['stylescombo']['styles'] = "\r\n \n \r \n ";
$editor
->setSettings($settings);
$editor
->save();
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Now configure it properly, the end result should change.
$settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.mAgical.Callout|Callout";
$editor
->setSettings($settings);
$editor
->save();
$expected['stylesSet'] = array(
array(
'name' => 'Title',
'element' => 'h1',
'attributes' => array(
'class' => 'title',
),
),
array(
'name' => 'Callout',
'element' => 'p',
'attributes' => array(
'class' => 'mAgical Callout',
),
),
);
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Same configuration, but now interspersed with nonsense. Should yield the
// same result.
$settings['plugins']['stylescombo']['styles'] = " h1 .title | Title \r \n\r \np.mAgical .Callout|Callout\r";
$editor
->setSettings($settings);
$editor
->save();
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Slightly different configuration: class names are optional.
$settings['plugins']['stylescombo']['styles'] = " h1 | Title ";
$editor
->setSettings($settings);
$editor
->save();
$expected['stylesSet'] = array(
array(
'name' => 'Title',
'element' => 'h1',
),
);
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
// Invalid syntax should cause stylesSet to be set to FALSE.
$settings['plugins']['stylescombo']['styles'] = "h1";
$editor
->setSettings($settings);
$editor
->save();
$expected['stylesSet'] = FALSE;
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
}