Tests StylesCombo::getConfig().
function testStylesComboGetConfig() {
$editor = entity_load('editor', 'filtered_html');
$manager = drupal_container()
->get('plugin.manager.ckeditor.plugin');
$stylescombo_plugin = $manager
->createInstance('stylescombo');
// Styles dropdown/button enabled: new setting should be present.
$editor->settings['toolbar']['buttons'][0][] = 'Styles';
$editor->settings['plugins']['stylescombo']['styles'] = '';
$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.
$editor->settings['plugins']['stylescombo']['styles'] = " \n";
$editor
->save();
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor));
$editor->settings['plugins']['stylescombo']['styles'] = "\r\n \n \r \n ";
$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.
$editor->settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.mAgical.Callout|Callout";
$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.
$editor->settings['plugins']['stylescombo']['styles'] = " h1 .title | Title \r \n\r \np.mAgical .Callout|Callout\r";
$editor
->save();
$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.
$editor->settings['plugins']['stylescombo']['styles'] = "h1|Title";
$editor
->save();
$expected['stylesSet'] = FALSE;
$this
->assertIdentical($expected, $stylescombo_plugin
->getConfig($editor), '"StylesCombo" plugin configuration built correctly for customized toolbar.');
}