You are here

public function DoubleFieldWidgetsTestCase::testWidgets in Double Field 7.2

Test widgets.

File

tests/double_field_widgets.test, line 31
Widgets tests for double field module.

Class

DoubleFieldWidgetsTestCase
Tests double field widgets.

Code

public function testWidgets() {

  // Iterate through all widget types.
  foreach (DoubleFieldWidget::getAllWidgetTypes() as $widget_type => $widget_label) {
    $widget = new DoubleFieldWidget($widget_type, $this->field['settings']);

    // Change widget type.
    $this->instance['widget']['type'] = $widget_type;
    field_update_instance($this->instance);

    // Update widget settings.
    $input = $widget
      ->getSettingsFormInput();
    $this
      ->drupalPost($this->field_settings_page, $input, t('Save settings'));

    // Test widget settings form.
    $this
      ->drupalGet($this->field_settings_page);
    $validators = $widget
      ->getSettingsFormValidators();
    $this
      ->validate($validators, 'Widget settings form is valid');

    // Test widget form.
    $input = $widget
      ->getFormInput($this->field_name);
    $input['title'] = $this
      ->randomName(8);
    $this
      ->drupalPost('node/add/' . $this->type_name, $input, t('Save'));

    // Check that the node exists in the database.
    $node = $this
      ->drupalGetNodeByTitle($input['title']);
    $this
      ->assertTrue($node, 'Node found in database.');
    $this
      ->drupalGet("node/{$node->nid}/edit");

    // Confirm that the widget settings form is being displayed
    // with actual widget settings values.
    $validators = $widget
      ->getFormValidators($this->field_name);
    $this
      ->validate($validators, 'Widget form is valid');
  }
}