public function DiffAdminFormsTest::testPluginWeight in Diff 8
Tests the Compare Revisions vertical tab.
File
- tests/
src/ Functional/ DiffAdminFormsTest.php, line 142
Class
- DiffAdminFormsTest
- Tests the Diff admin forms.
Namespace
Drupal\Tests\diff\FunctionalCode
public function testPluginWeight() {
// Create a node with a revision.
$edit = [
'title[0][value]' => 'great_title',
'body[0][value]' => '<p>great_body</p>',
];
$this
->drupalPostNodeForm('node/add/article', $edit, t('Save and publish'));
$this
->clickLink('Edit');
$edit = [
'title[0][value]' => 'greater_title',
'body[0][value]' => '<p>greater_body</p>',
];
$this
->drupalPostNodeForm(NULL, $edit, t('Save and keep published'));
// Assert the diff display uses the classic layout.
$node = $this
->getNodeByTitle('greater_title');
$this
->drupalGet('node/' . $node
->id() . '/revisions');
$this
->drupalPostForm(NULL, [], t('Compare selected revisions'));
$this
->assertLink('Unified fields');
$this
->assertLink('Split fields');
$this
->assertLink('Raw');
$this
->assertLink('Strip tags');
$text = $this
->xpath('//tbody/tr[4]/td[3]');
$this
->assertEqual(htmlspecialchars_decode(strip_tags($text[0]
->getHtml())), '<p>great_body</p>');
// Change the settings of the layouts, disable the single column.
$edit = [
'layout_plugins[split_fields][weight]' => '11',
'layout_plugins[unified_fields][enabled]' => FALSE,
];
$this
->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
// Assert the diff display uses the markdown layout.
$this
->drupalGet('node/' . $node
->id() . '/revisions');
$this
->drupalPostForm(NULL, [], t('Compare selected revisions'));
$this
->assertResponse(200);
$this
->assertNoLink('Unified fields');
$this
->assertLink('Split fields');
$this
->clickLink('Split fields');
$this
->assertLink('Raw');
$this
->assertLink('Strip tags');
$this
->clickLink('Strip tags');
$assert_session = $this
->assertSession();
$assert_session
->elementContains('css', 'tr:nth-child(4) td:nth-child(2)', 'great_body');
// Change the settings of the layouts, enable single column.
$edit = [
'layout_plugins[unified_fields][enabled]' => TRUE,
'layout_plugins[split_fields][enabled]' => FALSE,
];
$this
->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
// Test the validation of form.
$edit = [
'layout_plugins[unified_fields][enabled]' => FALSE,
'layout_plugins[split_fields][enabled]' => FALSE,
];
$this
->drupalPostForm('admin/config/content/diff/general', $edit, t('Save configuration'));
$this
->assertText('At least one layout plugin needs to be enabled.');
// Assert the diff display uses the single column layout.
$this
->drupalGet('node/' . $node
->id() . '/revisions');
$this
->drupalPostForm(NULL, [], t('Compare selected revisions'));
$this
->assertResponse(200);
$this
->assertLink('Unified fields');
$this
->assertNoLink('Split fields');
$this
->assertLink('Raw');
$this
->assertLink('Strip tags');
$assert_session
->elementTextContains('css', 'tr:nth-child(5) td:nth-child(4)', '<p>great_body</p>');
$this
->clickLink('Strip tags');
$assert_session
->elementContains('css', 'tr:nth-child(5) td:nth-child(2)', 'great_body');
$assert_session
->elementTextNotContains('css', 'tr:nth-child(5) td:nth-child(2)', '<p>');
}