3f565f22cfd611c175397a98ac0e9c400a0e1927
[yaffs-website] / web / modules / contrib / video_embed_field / modules / video_embed_wysiwyg / tests / src / Functional / TextFormatConfigurationTest.php
1 <?php
2
3 namespace Drupal\Tests\video_embed_wysiwyg\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6 use Drupal\Tests\video_embed_field\Functional\AdminUserTrait;
7
8 /**
9  * Test the format configuration form.
10  *
11  * @group video_embed_wysiwyg
12  */
13 class TextFormatConfigurationTest extends BrowserTestBase {
14
15   use AdminUserTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   public static $modules = [
21     'video_embed_field',
22     'video_embed_wysiwyg',
23     'editor',
24     'ckeditor',
25     'field_ui',
26     'node',
27     'image',
28   ];
29
30   /**
31    * The URL for the filter format.
32    *
33    * @var string
34    */
35   protected $formatUrl = 'admin/config/content/formats/manage/plain_text';
36
37   /**
38    * {@inheritdoc}
39    */
40   protected function setUp() {
41     parent::setUp();
42
43     $this->drupalLogin($this->createAdminUser());
44     $this->drupalGet($this->formatUrl);
45
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'));
50   }
51
52   /**
53    * Test both the input filter and button need to be enabled together.
54    */
55   public function testFormatConfiguration() {
56     // Save the settings with the filter enabled, but with no button.
57     $this->drupalGet($this->formatUrl);
58     $this->submitForm([
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.');
63
64     $this->drupalGet($this->formatUrl);
65     $this->submitForm([
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.');
70
71     $this->drupalGet($this->formatUrl);
72     $this->submitForm([
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.');
77
78     // Test the messages aren't triggered if they are in the second row.
79     $this->drupalGet($this->formatUrl);
80     $this->submitForm([
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.');
85   }
86
87   /**
88    * Test the URL filter weight is in the correct order.
89    */
90   public function testUrlWeightOrder() {
91     $this->drupalGet($this->formatUrl);
92     $this->submitForm([
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.');
103
104     // Submit the form with the weights reversed.
105     $this->submitForm([
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.');
110   }
111
112   /**
113    * Test the URL filter weight is in the correct order.
114    */
115   public function testHtmlFilterWeightOrder() {
116     $this->drupalGet($this->formatUrl);
117     $this->submitForm([
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.');
128
129     // Submit the form with the weights reversed.
130     $this->submitForm([
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.');
135   }
136
137   /**
138    * Test the dialog defaults can be set and work correctly.
139    */
140   public function testDialogDefaultValues() {
141     $this->drupalGet($this->formatUrl);
142
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');
149
150     $this->submitForm([
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'));
158
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);
165   }
166
167 }