Security update for Core, with self-updated composer
[yaffs-website] / web / core / modules / ckeditor / tests / src / Functional / CKEditorStylesComboAdminTest.php
1 <?php
2
3 namespace Drupal\Tests\ckeditor\Functional;
4
5 use Drupal\editor\Entity\Editor;
6 use Drupal\filter\Entity\FilterFormat;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Tests administration of the CKEditor StylesCombo plugin.
11  *
12  * @group ckeditor
13  */
14 class CKEditorStylesComboAdminTest extends BrowserTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = ['filter', 'editor', 'ckeditor'];
22
23   /**
24    * A user with the 'administer filters' permission.
25    *
26    * @var \Drupal\user\UserInterface
27    */
28   protected $adminUser;
29
30   /**
31    * A random generated format machine name.
32    *
33    * @var string
34    */
35   protected $format;
36
37   /**
38    * {@inheritdoc}
39    */
40   protected function setUp() {
41     parent::setUp();
42
43     $this->format = strtolower($this->randomMachineName());
44     $filter_format = FilterFormat::create([
45       'format' => $this->format,
46       'name' => $this->randomString(),
47       'filters' => [],
48     ]);
49     $filter_format->save();
50     $editor = Editor::create([
51       'format' => $this->format,
52       'editor' => 'ckeditor',
53     ]);
54     $editor->save();
55
56     $this->adminUser = $this->drupalCreateUser(['administer filters']);
57   }
58
59   /**
60    * Tests StylesCombo settings for an existing text format.
61    */
62   public function testExistingFormat() {
63     $ckeditor = $this->container->get('plugin.manager.editor')->createInstance('ckeditor');
64     $default_settings = $ckeditor->getDefaultSettings();
65
66     $this->drupalLogin($this->adminUser);
67     $this->drupalGet('admin/config/content/formats/manage/' . $this->format);
68
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.');
73
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);
77     $edit = [
78       'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Callout\n\n",
79     ];
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.');
84
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
87     // saved.
88     $this->drupalGet('admin/config/content/formats/manage/' . $this->format);
89     $edit = [
90       'editor[settings][plugins][stylescombo][styles]' => "h1.title|Title\np.callout|Title\n\n",
91     ];
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.');
97   }
98
99 }