function ManageFieldsTest::testWidgetChange

Tests changing the widget used by a field.

File

drupal/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php, line 473
Contains \Drupal\field_ui\Tests\ManageFieldsTest.

Class

ManageFieldsTest
Tests the functionality of the 'Manage fields' screen.

Namespace

Drupal\field_ui\Tests

Code

function testWidgetChange() {
  $url_fields = 'admin/structure/types/manage/article/fields';
  $url_tags_widget = $url_fields . '/node.article.field_tags/widget-type';

  // Check that the field_tags field currently uses the 'options_select'
  // widget.
  $entity_form_display = entity_get_form_display('node', 'article', 'default')
    ->getComponent('field_tags');
  $this
    ->assertEqual($entity_form_display['type'], 'options_select');

  // Check that the "Manage fields" page shows the correct widget type.
  $this
    ->drupalGet($url_fields);
  $link = current($this
    ->xpath('//a[contains(@href, :href)]', array(
    ':href' => $url_tags_widget,
  )));
  $this
    ->assertEqual((string) $link, 'Select list');

  // Go to the 'Widget type' form and check that the correct widget is
  // selected.
  $this
    ->drupalGet($url_tags_widget);
  $this
    ->assertFieldByXPath("//select[@name='widget_type']", 'options_select');

  // Change the widget type.
  $edit = array(
    'widget_type' => 'options_buttons',
  );
  $this
    ->drupalPost(NULL, $edit, t('Continue'));

  // Check that the "Manage fields" page shows the correct widget type.
  $link = current($this
    ->xpath('//a[contains(@href, :href)]', array(
    ':href' => $url_tags_widget,
  )));
  $this
    ->assertEqual((string) $link, 'Check boxes/radio buttons');

  // Check that the field uses the newly set widget.
  field_cache_clear();
  $widget_configuration = entity_get_form_display('node', 'article', 'default')
    ->getComponent('field_tags');
  $this
    ->assertEqual($widget_configuration['type'], 'options_buttons');

  // Go to the 'Widget type' form and check that the correct widget is
  // selected.
  $this
    ->drupalGet($url_tags_widget);
  $this
    ->assertFieldByXPath("//select[@name='widget_type']", 'options_buttons');
}