3 namespace Drupal\diff\Tests;
6 * Tests the Diff admin forms.
10 class DiffAdminFormsTest extends DiffTestBase {
17 public static $modules = [
25 protected function setUp() {
28 $this->drupalLogin($this->rootUser);
32 * Run all independent tests.
34 public function testAll() {
35 $this->doTestSettingsUi();
36 $this->doTestSettingsTab();
37 $this->doTestRequirements();
38 $this->doTestConfigurableFieldsTab();
39 $this->doTestPluginWeight();
43 * Tests the descriptions in the Settings UI.
45 public function doTestSettingsUi() {
46 // Enable the help block.
47 $this->drupalPlaceBlock('help_block', ['region' => 'help']);
49 $this->drupalGet('admin/config/content/diff/general');
50 // Check the settings introduction text.
51 $this->assertText('Configurations for the revision comparison functionality and diff layout plugins.');
52 // Check the layout plugins descriptions.
53 $this->assertText('Field based layout, displays revision comparison side by side.');
54 $this->assertText('Field based layout, displays revision comparison line by line.');
58 * Tests the Settings tab.
60 public function doTestSettingsTab() {
62 'radio_behavior' => 'linear',
63 'context_lines_leading' => 10,
64 'context_lines_trailing' => 5,
66 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
67 $this->assertText('The configuration options have been saved.');
71 * Tests the module requirements.
73 public function doTestRequirements() {
74 module_load_install('diff');
75 $requirements = diff_requirements('runtime');
76 $this->assertEqual($requirements['html_diff_advanced']['title'], 'Diff');
78 $has_htmlDiffAdvanced = class_exists('\HtmlDiffAdvanced');
79 if (!$has_htmlDiffAdvanced) {
80 // The plugin is disabled dependencies are missing.
81 $this->assertEqual($requirements['html_diff_advanced']['value'], 'Visual inline layout');
84 // The plugin is enabled by default if dependencies are met.
85 $this->assertEqual($requirements['html_diff_advanced']['value'], 'Installed correctly');
90 * Tests the Configurable Fields tab.
92 public function doTestConfigurableFieldsTab() {
93 $this->drupalGet('admin/config/content/diff/fields');
95 // Test changing type without changing settings.
97 'fields[node.body][plugin][type]' => 'text_summary_field_diff_builder',
99 $this->drupalPostForm(NULL, $edit, t('Save'));
100 $this->assertFieldByName('fields[node.body][plugin][type]', 'text_summary_field_diff_builder');
102 'fields[node.body][plugin][type]' => 'text_field_diff_builder',
104 $this->drupalPostForm(NULL, $edit, t('Save'));
105 $this->assertFieldByName('fields[node.body][plugin][type]', 'text_field_diff_builder');
107 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
108 $this->assertText('Plugin settings: Text');
110 'fields[node.body][settings_edit_form][settings][show_header]' => TRUE,
111 'fields[node.body][settings_edit_form][settings][compare_format]' => FALSE,
112 'fields[node.body][settings_edit_form][settings][markdown]' => 'filter_xss_all',
114 $this->drupalPostAjaxForm(NULL, $edit, 'node.body_plugin_settings_update');
115 $this->drupalPostForm(NULL, [], t('Save'));
116 $this->assertText('Your settings have been saved.');
118 // Check the values were saved.
119 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
120 $this->assertFieldByName('fields[node.body][settings_edit_form][settings][markdown]', 'filter_xss_all');
122 // Edit another field.
123 $this->drupalPostAjaxForm(NULL, [], 'node.title_settings_edit');
125 'fields[node.title][settings_edit_form][settings][markdown]' => 'filter_xss_all',
127 $this->drupalPostAjaxForm(NULL, $edit, 'node.title_plugin_settings_update');
128 $this->drupalPostForm(NULL, [], t('Save'));
130 // Check both fields and their config values.
131 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
132 $this->assertFieldByName('fields[node.body][settings_edit_form][settings][markdown]', 'filter_xss_all');
133 $this->drupalPostAjaxForm(NULL, [], 'node.title_settings_edit');
134 $this->assertFieldByName('fields[node.title][settings_edit_form][settings][markdown]', 'filter_xss_all');
136 // Save field settings without changing anything and assert the config.
137 $this->drupalPostForm(NULL, [], t('Save'));
138 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
139 $this->assertFieldByName('fields[node.body][settings_edit_form][settings][markdown]', 'filter_xss_all');
140 $this->drupalPostAjaxForm(NULL, [], 'node.title_settings_edit');
141 $this->assertFieldByName('fields[node.title][settings_edit_form][settings][markdown]', 'filter_xss_all');
144 'fields[node.sticky][plugin][type]' => 'hidden',
146 $this->drupalPostForm(NULL, $edit, t('Save'));
147 $this->assertFieldByName('fields[node.sticky][plugin][type]', 'hidden');
151 * Tests the Compare Revisions vertical tab.
153 public function doTestPluginWeight() {
154 // Create a node with a revision.
156 'title[0][value]' => 'great_title',
157 'body[0][value]' => '<p>great_body</p>',
159 $this->drupalPostForm('node/add/article', $edit, t('Save and publish'));
160 $this->clickLink('Edit');
162 'title[0][value]' => 'greater_title',
163 'body[0][value]' => '<p>greater_body</p>',
165 $this->drupalPostForm(NULL, $edit, t('Save and keep published'));
167 // Assert the diff display uses the classic layout.
168 $node = $this->getNodeByTitle('greater_title');
169 $this->drupalGet('node/' . $node->id() . '/revisions');
170 $this->drupalPostForm(NULL, [], t('Compare selected revisions'));
171 $this->assertLink('Unified fields');
172 $this->assertLink('Split fields');
173 $this->assertLink('Raw');
174 $this->assertLink('Strip tags');
175 $text = $this->xpath('//tbody/tr[4]/td[3]');
176 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), '<p>great_body</p>');
178 // Change the settings of the layouts, disable the single column.
180 'layout_plugins[split_fields][weight]' => '11',
181 'layout_plugins[unified_fields][enabled]' => FALSE,
183 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
185 // Assert the diff display uses the markdown layout.
186 $this->drupalGet('node/' . $node->id() . '/revisions');
187 $this->drupalPostForm(NULL, [], t('Compare selected revisions'));
188 $this->assertResponse(200);
189 $this->assertNoLink('Unified fields');
190 $this->assertLink('Split fields');
191 $this->clickLink('Split fields');
192 $this->assertLink('Raw');
193 $this->assertLink('Strip tags');
194 $this->clickLink('Strip tags');
195 $text = $this->xpath('//tbody/tr[4]/td[2]');
196 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), 'great_body');
198 // Change the settings of the layouts, enable single column.
200 'layout_plugins[unified_fields][enabled]' => TRUE,
201 'layout_plugins[split_fields][enabled]' => FALSE,
203 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
205 // Test the validation of form.
207 'layout_plugins[unified_fields][enabled]' => FALSE,
208 'layout_plugins[split_fields][enabled]' => FALSE,
210 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
211 $this->assertText('At least one layout plugin needs to be enabled.');
213 // Assert the diff display uses the single column layout.
214 $this->drupalGet('node/' . $node->id() . '/revisions');
215 $this->drupalPostForm(NULL, [], t('Compare selected revisions'));
216 $this->assertResponse(200);
217 $this->assertLink('Unified fields');
218 $this->assertNoLink('Split fields');
219 $this->assertLink('Raw');
220 $this->assertLink('Strip tags');
221 $text = $this->xpath('//tbody/tr[5]/td[4]');
222 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), '<p>great_body</p>');
223 $this->clickLink('Strip tags');
224 $text = $this->xpath('//tbody/tr[5]/td[2]');
225 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), 'great_body');