3 namespace Drupal\diff\Tests;
4 use Drupal\Tests\diff\Functional\CoreVersionUiTestTrait;
7 * Tests the Diff admin forms.
11 class DiffAdminFormsTest extends DiffTestBase {
13 use CoreVersionUiTestTrait;
20 public static $modules = [
28 protected function setUp() {
31 $this->drupalLogin($this->rootUser);
35 * Run all independent tests.
37 public function testAll() {
38 $this->doTestSettingsUi();
39 $this->doTestSettingsTab();
40 $this->doTestRequirements();
41 $this->doTestConfigurableFieldsTab();
42 $this->doTestPluginWeight();
46 * Tests the descriptions in the Settings UI.
48 public function doTestSettingsUi() {
49 // Enable the help block.
50 $this->drupalPlaceBlock('help_block', ['region' => 'help']);
52 $this->drupalGet('admin/config/content/diff/general');
53 // Check the settings introduction text.
54 $this->assertText('Configurations for the revision comparison functionality and diff layout plugins.');
55 // Check the layout plugins descriptions.
56 $this->assertText('Field based layout, displays revision comparison side by side.');
57 $this->assertText('Field based layout, displays revision comparison line by line.');
61 * Tests the Settings tab.
63 public function doTestSettingsTab() {
65 'radio_behavior' => 'linear',
66 'context_lines_leading' => 10,
67 'context_lines_trailing' => 5,
69 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
70 $this->assertText('The configuration options have been saved.');
74 * Tests the module requirements.
76 public function doTestRequirements() {
77 module_load_install('diff');
78 $requirements = diff_requirements('runtime');
79 $this->assertEqual($requirements['html_diff_advanced']['title'], 'Diff');
81 $has_htmlDiffAdvanced = class_exists('\HtmlDiffAdvanced');
82 if (!$has_htmlDiffAdvanced) {
83 // The plugin is disabled dependencies are missing.
84 $this->assertEqual($requirements['html_diff_advanced']['value'], 'Visual inline layout');
87 // The plugin is enabled by default if dependencies are met.
88 $this->assertEqual($requirements['html_diff_advanced']['value'], 'Installed correctly');
93 * Tests the Configurable Fields tab.
95 public function doTestConfigurableFieldsTab() {
96 $this->drupalGet('admin/config/content/diff/fields');
98 // Test changing type without changing settings.
100 'fields[node.body][plugin][type]' => 'text_summary_field_diff_builder',
102 $this->drupalPostForm(NULL, $edit, t('Save'));
103 $this->assertFieldByName('fields[node.body][plugin][type]', 'text_summary_field_diff_builder');
105 'fields[node.body][plugin][type]' => 'text_field_diff_builder',
107 $this->drupalPostForm(NULL, $edit, t('Save'));
108 $this->assertFieldByName('fields[node.body][plugin][type]', 'text_field_diff_builder');
110 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
111 $this->assertText('Plugin settings: Text');
113 'fields[node.body][settings_edit_form][settings][show_header]' => TRUE,
114 'fields[node.body][settings_edit_form][settings][compare_format]' => FALSE,
115 'fields[node.body][settings_edit_form][settings][markdown]' => 'filter_xss_all',
117 $this->drupalPostAjaxForm(NULL, $edit, 'node.body_plugin_settings_update');
118 $this->drupalPostForm(NULL, [], t('Save'));
119 $this->assertText('Your settings have been saved.');
121 // Check the values were saved.
122 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
123 $this->assertFieldByName('fields[node.body][settings_edit_form][settings][markdown]', 'filter_xss_all');
125 // Edit another field.
126 $this->drupalPostAjaxForm(NULL, [], 'node.title_settings_edit');
128 'fields[node.title][settings_edit_form][settings][markdown]' => 'filter_xss_all',
130 $this->drupalPostAjaxForm(NULL, $edit, 'node.title_plugin_settings_update');
131 $this->drupalPostForm(NULL, [], t('Save'));
133 // Check both fields and their config values.
134 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
135 $this->assertFieldByName('fields[node.body][settings_edit_form][settings][markdown]', 'filter_xss_all');
136 $this->drupalPostAjaxForm(NULL, [], 'node.title_settings_edit');
137 $this->assertFieldByName('fields[node.title][settings_edit_form][settings][markdown]', 'filter_xss_all');
139 // Save field settings without changing anything and assert the config.
140 $this->drupalPostForm(NULL, [], t('Save'));
141 $this->drupalPostAjaxForm(NULL, [], 'node.body_settings_edit');
142 $this->assertFieldByName('fields[node.body][settings_edit_form][settings][markdown]', 'filter_xss_all');
143 $this->drupalPostAjaxForm(NULL, [], 'node.title_settings_edit');
144 $this->assertFieldByName('fields[node.title][settings_edit_form][settings][markdown]', 'filter_xss_all');
147 'fields[node.sticky][plugin][type]' => 'hidden',
149 $this->drupalPostForm(NULL, $edit, t('Save'));
150 $this->assertFieldByName('fields[node.sticky][plugin][type]', 'hidden');
154 * Tests the Compare Revisions vertical tab.
156 public function doTestPluginWeight() {
157 // Create a node with a revision.
159 'title[0][value]' => 'great_title',
160 'body[0][value]' => '<p>great_body</p>',
162 $this->drupalPostNodeForm('node/add/article', $edit, t('Save and publish'));
163 $this->clickLink('Edit');
165 'title[0][value]' => 'greater_title',
166 'body[0][value]' => '<p>greater_body</p>',
168 $this->drupalPostNodeForm(NULL, $edit, t('Save and keep published'));
170 // Assert the diff display uses the classic layout.
171 $node = $this->getNodeByTitle('greater_title');
172 $this->drupalGet('node/' . $node->id() . '/revisions');
173 $this->drupalPostForm(NULL, [], t('Compare selected revisions'));
174 $this->assertLink('Unified fields');
175 $this->assertLink('Split fields');
176 $this->assertLink('Raw');
177 $this->assertLink('Strip tags');
178 $text = $this->xpath('//tbody/tr[4]/td[3]');
179 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), '<p>great_body</p>');
181 // Change the settings of the layouts, disable the single column.
183 'layout_plugins[split_fields][weight]' => '11',
184 'layout_plugins[unified_fields][enabled]' => FALSE,
186 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
188 // Assert the diff display uses the markdown layout.
189 $this->drupalGet('node/' . $node->id() . '/revisions');
190 $this->drupalPostForm(NULL, [], t('Compare selected revisions'));
191 $this->assertResponse(200);
192 $this->assertNoLink('Unified fields');
193 $this->assertLink('Split fields');
194 $this->clickLink('Split fields');
195 $this->assertLink('Raw');
196 $this->assertLink('Strip tags');
197 $this->clickLink('Strip tags');
198 $text = $this->xpath('//tbody/tr[4]/td[2]');
199 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), 'great_body');
201 // Change the settings of the layouts, enable single column.
203 'layout_plugins[unified_fields][enabled]' => TRUE,
204 'layout_plugins[split_fields][enabled]' => FALSE,
206 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
208 // Test the validation of form.
210 'layout_plugins[unified_fields][enabled]' => FALSE,
211 'layout_plugins[split_fields][enabled]' => FALSE,
213 $this->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
214 $this->assertText('At least one layout plugin needs to be enabled.');
216 // Assert the diff display uses the single column layout.
217 $this->drupalGet('node/' . $node->id() . '/revisions');
218 $this->drupalPostForm(NULL, [], t('Compare selected revisions'));
219 $this->assertResponse(200);
220 $this->assertLink('Unified fields');
221 $this->assertNoLink('Split fields');
222 $this->assertLink('Raw');
223 $this->assertLink('Strip tags');
224 $text = $this->xpath('//tbody/tr[5]/td[4]');
225 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), '<p>great_body</p>');
226 $this->clickLink('Strip tags');
227 $text = $this->xpath('//tbody/tr[5]/td[2]');
228 $this->assertEqual(htmlspecialchars_decode(strip_tags($text[0]->asXML())), 'great_body');