You are here

public function DiffAdminFormsTest::testConfigurableFieldsTab in Diff 8

Tests the Configurable Fields tab.

File

tests/src/Functional/DiffAdminFormsTest.php, line 81

Class

DiffAdminFormsTest
Tests the Diff admin forms.

Namespace

Drupal\Tests\diff\Functional

Code

public function testConfigurableFieldsTab() {
  $this
    ->drupalGet('admin/config/content/diff/fields');

  // Test changing type without changing settings.
  $edit = [
    'fields[node__body][plugin][type]' => 'text_summary_field_diff_builder',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertFieldByName('fields[node__body][plugin][type]', 'text_summary_field_diff_builder');
  $edit = [
    'fields[node__body][plugin][type]' => 'text_field_diff_builder',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertFieldByName('fields[node__body][plugin][type]', 'text_field_diff_builder');
  $this
    ->drupalPostForm(NULL, [], 'node__body_settings_edit');
  $this
    ->assertText('Plugin settings: Text');
  $edit = [
    'fields[node__body][settings_edit_form][settings][show_header]' => TRUE,
    'fields[node__body][settings_edit_form][settings][compare_format]' => FALSE,
    'fields[node__body][settings_edit_form][settings][markdown]' => 'filter_xss_all',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'node__body_plugin_settings_update');
  $this
    ->drupalPostForm(NULL, [], t('Save'));
  $this
    ->assertText('Your settings have been saved.');

  // Check the values were saved.
  $this
    ->drupalPostForm(NULL, [], 'node__body_settings_edit');
  $this
    ->assertFieldByName('fields[node__body][settings_edit_form][settings][markdown]', 'filter_xss_all');

  // Edit another field.
  $this
    ->drupalPostForm(NULL, [], 'node__title_settings_edit');
  $edit = [
    'fields[node__title][settings_edit_form][settings][markdown]' => 'filter_xss_all',
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'node__title_plugin_settings_update');
  $this
    ->drupalPostForm(NULL, [], t('Save'));

  // Check both fields and their config values.
  $this
    ->drupalPostForm(NULL, [], 'node__body_settings_edit');
  $this
    ->assertFieldByName('fields[node__body][settings_edit_form][settings][markdown]', 'filter_xss_all');
  $this
    ->drupalPostForm(NULL, [], 'node__title_settings_edit');
  $this
    ->assertFieldByName('fields[node__title][settings_edit_form][settings][markdown]', 'filter_xss_all');

  // Save field settings without changing anything and assert the config.
  $this
    ->drupalPostForm(NULL, [], t('Save'));
  $this
    ->drupalPostForm(NULL, [], 'node__body_settings_edit');
  $this
    ->assertFieldByName('fields[node__body][settings_edit_form][settings][markdown]', 'filter_xss_all');
  $this
    ->drupalPostForm(NULL, [], 'node__title_settings_edit');
  $this
    ->assertFieldByName('fields[node__title][settings_edit_form][settings][markdown]', 'filter_xss_all');
  $edit = [
    'fields[node__sticky][plugin][type]' => 'hidden',
  ];
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->assertFieldByName('fields[node__sticky][plugin][type]', 'hidden');
}