3 namespace Drupal\Tests\ckeditor\Functional;
5 use Drupal\editor\Entity\Editor;
6 use Drupal\filter\Entity\FilterFormat;
7 use Drupal\Tests\BrowserTestBase;
10 * Tests administration of the CKEditor StylesCombo plugin.
14 class CKEditorStylesComboAdminTest extends BrowserTestBase {
21 public static $modules = ['filter', 'editor', 'ckeditor'];
24 * A user with the 'administer filters' permission.
26 * @var \Drupal\user\UserInterface
31 * A random generated format machine name.
40 protected function setUp() {
43 $this->format = strtolower($this->randomMachineName());
44 $filter_format = FilterFormat::create([
45 'format' => $this->format,
46 'name' => $this->randomString(),
49 $filter_format->save();
50 $editor = Editor::create([
51 'format' => $this->format,
52 'editor' => 'ckeditor',
56 $this->adminUser = $this->drupalCreateUser(['administer filters']);
60 * Tests StylesCombo settings for an existing text format.
62 public function testExistingFormat() {
63 $ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
64 $default_settings = $ckeditor->getDefaultSettings();
66 $this->drupalLogin($this->adminUser);
67 $this->drupalGet('admin/config/content/formats/manage/' . $this->format);
69 // Ensure an Editor config entity exists, with the proper settings.
70 $expected_settings = $default_settings;
71 $editor = Editor::load($this->format);
72 $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
74 // Case 1: Configure the Styles plugin with different labels for each style,
75 // and ensure the updated settings are saved.
76 $this->drupalGet('admin/config/content/formats/manage/' . $this->format);
78 'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n",
80 $this->drupalPostForm(NULL, $edit, t('Save configuration'));
81 $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
82 $editor = Editor::load($this->format);
83 $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');
85 // Case 2: Configure the Styles plugin with same labels for each style, and
86 // ensure that an error is displayed and that the updated settings are not
88 $this->drupalGet('admin/config/content/formats/manage/' . $this->format);
90 'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Title\n\n",
92 $this->drupalPostForm(NULL, $edit, t('Save configuration'));
93 $this->assertRaw(t('Each style must have a unique label.'));
94 $expected_settings['plugins']['stylescombo']['styles'] = "h1.title|Title\np.callout|Callout\n\n";
95 $editor = Editor::load($this->format);
96 $this->assertEqual($expected_settings, $editor->getSettings(), 'The Editor config entity has the correct settings.');