1 field_ui.test FieldUIAlterTestCase::testDefaultWidgetPropertiesAlter()

Tests hook_field_widget_properties_alter() on the default field widget.

See also

field_test_field_widget_properties_alter()

field_test_field_widget_properties_user_alter()

field_test_field_widget_form_alter()

File

core/modules/field_ui/tests/field_ui.test, line 792
Tests for field_ui.module.

Class

FieldUIAlterTestCase
Tests custom widget hooks and callbacks on the field administration pages.

Code

function testDefaultWidgetPropertiesAlter() {
  // Create the alter_test_text field and an instance on post nodes.
  field_create_field(array(
    'field_name' => 'alter_test_text',
    'type' => 'text',
  ));
  field_create_instance(array(
    'field_name' => 'alter_test_text',
    'entity_type' => 'node',
    'bundle' => 'post',
    'widget' => array(
      'type' => 'text_textfield',
      'size' => 60,
    ),
  ));

  // Test that field_test_field_widget_properties_alter() sets the size to
  // 42 and that field_test_field_widget_form_alter() reports the correct
  // size when the form is displayed.
  $this->backdropGet('admin/structure/types/manage/post/fields/alter_test_text');
  $this->assertText('Field size: 42', 'Altered field size is found in hook_field_widget_form_alter().');

  // Create the alter_test_options field.
  field_create_field(array(
    'field_name' => 'alter_test_options',
    'type' => 'list_text'
  ));
  // Create instances on users and page nodes.
  field_create_instance(array(
    'field_name' => 'alter_test_options',
    'entity_type' => 'user',
    'bundle' => 'user',
    'widget' => array(
      'type' => 'options_select',
    )
  ));
  field_create_instance(array(
    'field_name' => 'alter_test_options',
    'entity_type' => 'node',
    'bundle' => 'page',
    'widget' => array(
      'type' => 'options_select',
    )
  ));

  // Test that field_test_field_widget_properties_user_alter() replaces
  // the widget and that field_test_field_widget_form_alter() reports the
  // correct widget name when the form is displayed.
  $this->backdropGet('admin/config/people/manage/fields/alter_test_options');
  $this->assertText('Widget type: options_buttons', 'Widget type is altered for users in hook_field_widget_form_alter().');

  // Test that the widget is not altered on page nodes.
  $this->backdropGet('admin/structure/types/manage/page/fields/alter_test_options');
  $this->assertText('Widget type: options_select', 'Widget type is not altered for pages in hook_field_widget_form_alter().');
}