You are here

public function CKEditorStylesComboAdminTest::testExistingFormat in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboAdminTest.php \Drupal\Tests\ckeditor\Functional\CKEditorStylesComboAdminTest::testExistingFormat()

Tests StylesCombo settings for an existing text format.

File

core/modules/ckeditor/tests/src/Functional/CKEditorStylesComboAdminTest.php, line 67

Class

CKEditorStylesComboAdminTest
Tests administration of the CKEditor StylesCombo plugin.

Namespace

Drupal\Tests\ckeditor\Functional

Code

public function testExistingFormat() {
  $ckeditor = $this->container
    ->get('plugin.manager.editor')
    ->createInstance('ckeditor');
  $default_settings = $ckeditor
    ->getDefaultSettings();
  $this
    ->drupalLogin($this->adminUser);
  $this
    ->drupalGet('admin/config/content/formats/manage/' . $this->format);

  // Ensure an Editor config entity exists, with the proper settings.
  $expected_settings = $default_settings;
  $editor = Editor::load($this->format);
  $this
    ->assertEqual($expected_settings, $editor
    ->getSettings(), 'The Editor config entity has the correct settings.');

  // Case 1: Configure the Styles plugin with different labels for each style,
  // and ensure the updated settings are saved.
  $this
    ->drupalGet('admin/config/content/formats/manage/' . $this->format);
  $edit = [
    'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n",
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save configuration'));
  $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
  $editor = Editor::load($this->format);
  $this
    ->assertEqual($expected_settings, $editor
    ->getSettings(), 'The Editor config entity has the correct settings.');

  // Case 2: Configure the Styles plugin with same labels for each style, and
  // ensure that an error is displayed and that the updated settings are not
  // saved.
  $this
    ->drupalGet('admin/config/content/formats/manage/' . $this->format);
  $edit = [
    'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Title\n\n",
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save configuration'));
  $this
    ->assertRaw(t('Each style must have a unique label.'));
  $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
  $editor = Editor::load($this->format);
  $this
    ->assertEqual($expected_settings, $editor
    ->getSettings(), 'The Editor config entity has the correct settings.');
}