3 namespace Drupal\Tests\video_embed_wysiwyg\Functional;
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
9 * Test the format configuration form.
11 * @group video_embed_wysiwyg
13 class TextFormatConfigurationTest extends BrowserTestBase {
20 public static $modules = [
22 'video_embed_wysiwyg',
31 * The URL for the filter format.
35 protected $formatUrl = 'admin/config/content/formats/manage/plain_text';
40 protected function setUp() {
43 $this->drupalLogin($this->createAdminUser());
44 $this->drupalGet($this->formatUrl);
46 // Setup the filter to have an editor.
47 $this->getSession()->getPage()->find('css', '[name="editor[editor]"]')->setValue('ckeditor');
48 $this->getSession()->getPage()->find('css', 'input[name="editor_configure"]')->click();
49 $this->submitForm([], t('Save configuration'));
53 * Test both the input filter and button need to be enabled together.
55 public function testFormatConfiguration() {
56 // Save the settings with the filter enabled, but with no button.
57 $this->drupalGet($this->formatUrl);
59 'filters[video_embed_wysiwyg][status]' => TRUE,
60 'editor[settings][toolbar][button_groups]' => '[]',
61 ], t('Save configuration'));
62 $this->assertSession()->pageTextContains('To embed videos, make sure you have enabled the "Video Embed WYSIWYG" filter and dragged the video icon into the WYSIWYG toolbar.');
64 $this->drupalGet($this->formatUrl);
66 'filters[video_embed_wysiwyg][status]' => FALSE,
67 'editor[settings][toolbar][button_groups]' => '[[{"name":"Group","items":["video_embed"]}]]',
68 ], t('Save configuration'));
69 $this->assertSession()->pageTextContains('To embed videos, make sure you have enabled the "Video Embed WYSIWYG" filter and dragged the video icon into the WYSIWYG toolbar.');
71 $this->drupalGet($this->formatUrl);
73 'filters[video_embed_wysiwyg][status]' => TRUE,
74 'editor[settings][toolbar][button_groups]' => '[[{"name":"Group","items":["video_embed"]}]]',
75 ], t('Save configuration'));
76 $this->assertSession()->pageTextContains('The text format Plain text has been updated.');
78 // Test the messages aren't triggered if they are in the second row.
79 $this->drupalGet($this->formatUrl);
81 'filters[video_embed_wysiwyg][status]' => TRUE,
82 'editor[settings][toolbar][button_groups]' => '[[{"name":"Foo","items":["NumberedList"]}],[{"name":"Bar","items":["video_embed"]}]]',
83 ], t('Save configuration'));
84 $this->assertSession()->pageTextContains('The text format Plain text has been updated.');
88 * Test the URL filter weight is in the correct order.
90 public function testUrlWeightOrder() {
91 $this->drupalGet($this->formatUrl);
93 // Enable the URL filter and the WYSIWYG embed.
94 'filters[filter_url][status]' => TRUE,
95 'filters[filter_html][status]' => FALSE,
96 'filters[video_embed_wysiwyg][status]' => TRUE,
97 'editor[settings][toolbar][button_groups]' => '[[{"name":"Group","items":["video_embed"]}]]',
98 // Setup the weights so the URL filter runs first.
99 'filters[video_embed_wysiwyg][weight]' => '10',
100 'filters[filter_url][weight]' => '-10',
101 ], 'Save configuration');
102 $this->assertSession()->pageTextContains('The "Video Embed WYSIWYG" filter must run before the "Convert URLs into links" filter to function correctly.');
104 // Submit the form with the weights reversed.
106 'filters[video_embed_wysiwyg][weight]' => '-10',
107 'filters[filter_url][weight]' => '10',
108 ], 'Save configuration');
109 $this->assertSession()->pageTextContains('The text format Plain text has been updated.');
113 * Test the URL filter weight is in the correct order.
115 public function testHtmlFilterWeightOrder() {
116 $this->drupalGet($this->formatUrl);
118 // Enable the URL filter and the WYSIWYG embed.
119 'filters[filter_html][status]' => TRUE,
120 'filters[filter_url][status]' => FALSE,
121 'filters[video_embed_wysiwyg][status]' => TRUE,
122 'editor[settings][toolbar][button_groups]' => '[[{"name":"Group","items":["video_embed"]}]]',
123 // Run WYSWIYG first then the HTML filter.
124 'filters[video_embed_wysiwyg][weight]' => '-10',
125 'filters[filter_html][weight]' => '10',
126 ], 'Save configuration');
127 $this->assertSession()->pageTextContains('The "Video Embed WYSIWYG" filter must run after the "Limit allowed HTML tags" filter to function correctly.');
129 // Submit the form with the weights reversed.
131 'filters[video_embed_wysiwyg][weight]' => '10',
132 'filters[filter_html][weight]' => '-10',
133 ], 'Save configuration');
134 $this->assertSession()->pageTextContains('The text format Plain text has been updated.');
138 * Test the dialog defaults can be set and work correctly.
140 public function testDialogDefaultValues() {
141 $this->drupalGet($this->formatUrl);
143 // Assert all the form fields that appear on the modal, appear as
144 // configurable defaults.
145 $this->assertSession()->pageTextContains('Autoplay');
146 $this->assertSession()->pageTextContains('Responsive Video');
147 $this->assertSession()->pageTextContains('Width');
148 $this->assertSession()->pageTextContains('Height');
151 'filters[video_embed_wysiwyg][status]' => TRUE,
152 'editor[settings][toolbar][button_groups]' => '[[{"name":"Group","items":["video_embed"]}]]',
153 'editor[settings][plugins][video_embed][defaults][children][width]' => '123',
154 'editor[settings][plugins][video_embed][defaults][children][height]' => '456',
155 'editor[settings][plugins][video_embed][defaults][children][responsive]' => FALSE,
156 'editor[settings][plugins][video_embed][defaults][children][autoplay]' => FALSE,
157 ], t('Save configuration'));
159 // Ensure the configured defaults show up on the modal window.
160 $this->drupalGet('video-embed-wysiwyg/dialog/plain_text');
161 $this->assertSession()->fieldValueEquals('width', '123');
162 $this->assertSession()->fieldValueEquals('height', '456');
163 $this->assertSession()->fieldValueEquals('autoplay', FALSE);
164 $this->assertSession()->fieldValueEquals('responsive', FALSE);