You are here

function FormTest::testConfigurationForm in Form Builder 7.2

Test the element configuration form.

File

modules/webform/tests/FormTest.php, line 235

Class

FormTest
Integration test for the webform integration.

Namespace

Drupal\form_builder_webform

Code

function testConfigurationForm() {

  // We need a real node because webform_component_edit_form() uses it.
  $node = (object) array(
    'type' => 'webform',
  );
  node_object_prepare($node);
  $node->webform['components'] = $this
    ->components();
  node_save($node);
  $form = Form::loadFromStorage('webform', $node->nid, 'the-sid', array());
  $form_state = array();
  $element = $form
    ->getElement('cid_2');
  $a = $element
    ->configurationForm(array(), $form_state);
  $this
    ->assertEqual(array(
    'size' => array(
      '#form_builder' => array(
        'property_group' => 'display',
      ),
      '#type' => 'textfield',
      '#size' => 6,
      '#title' => 'Size',
      '#default_value' => '4',
      '#weight' => 2,
      '#maxlength' => 5,
      '#element_validate' => array(
        0 => 'form_validate_integer',
      ),
    ),
    'maxlength' => array(
      '#form_builder' => array(
        'property_group' => 'validation',
      ),
      '#type' => 'textfield',
      '#size' => 6,
      '#title' => 'Max length',
      '#default_value' => '',
      '#field_suffix' => ' characters',
      '#weight' => 3,
      '#maxlength' => 7,
      '#element_validate' => array(
        0 => 'form_validate_integer',
      ),
    ),
    'field_prefix' => array(
      '#form_builder' => array(
        'property_group' => 'display',
      ),
      '#type' => 'textfield',
      '#title' => 'Prefix',
      '#default_value' => 'testprefix',
      '#weight' => -2,
    ),
    'field_suffix' => array(
      '#form_builder' => array(
        'property_group' => 'display',
      ),
      '#type' => 'textfield',
      '#title' => 'Suffix',
      '#default_value' => 'testpostfix',
      '#weight' => -1,
    ),
    'disabled' => array(
      '#form_builder' => array(
        'property_group' => 'display',
      ),
      '#title' => 'Disabled (read-only)',
      '#type' => 'checkbox',
      '#default_value' => TRUE,
      '#weight' => 12,
    ),
    'unique' => array(
      '#form_builder' => array(
        'property_group' => 'validation',
      ),
      '#title' => 'Unique',
      '#description' => 'Check that all entered values for this field are unique. The same value is not allowed to be used twice.',
      '#type' => 'checkbox',
      '#default_value' => 0,
      '#return_value' => 1,
      '#weight' => 1,
      '#parents' => [
        'extra',
        'unique',
      ],
    ),
    'title' => array(
      '#title' => 'Title',
      '#type' => 'textfield',
      '#default_value' => 'textfield1',
      '#maxlength' => 255,
      '#required' => TRUE,
      '#weight' => -10,
    ),
    'title_display' => array(
      '#type' => 'select',
      '#title' => 'Label display',
      '#description' => "Determines the placement of the component's label.",
      '#default_value' => 'before',
      '#options' => array(
        'before' => 'Above',
        'inline' => 'Inline',
        'none' => 'None',
      ),
      '#weight' => -10,
      '#form_builder' => array(
        'property_group' => 'display',
      ),
      '#tree' => TRUE,
    ),
    'default_value' => array(
      '#type' => 'textfield',
      '#title' => 'Default value',
      '#default_value' => 'textfield1',
      '#weight' => 1,
    ),
    'description' => array(
      '#title' => 'Description',
      '#type' => 'textarea',
      '#default_value' => '',
      '#weight' => 5,
    ),
    'webform_private' => array(
      '#type' => 'checkbox',
      '#title' => 'Private',
      '#default_value' => FALSE,
      '#description' => 'Private fields are shown only to users with results access.',
      '#weight' => 45,
      '#disabled' => TRUE,
      '#tree' => TRUE,
      '#form_builder' => array(
        'property_group' => 'display',
      ),
    ),
    'required' => array(
      '#form_builder' => array(
        'property_group' => 'validation',
      ),
      '#title' => 'Required',
      '#type' => 'checkbox',
      '#default_value' => '0',
      '#weight' => -1,
    ),
    'key' => array(
      '#title' => 'Form key',
      '#type' => 'machine_name',
      '#default_value' => 'textfield1',
      '#maxlength' => 128,
      '#description' => 'The form key is used in the field "name" attribute. Must be alphanumeric and underscore characters.',
      '#machine_name' => array(
        'source' => array(
          0 => 'title',
        ),
        'label' => 'Form key',
      ),
      '#weight' => -9,
      '#element_validate' => array(
        0 => 'form_builder_webform_property_key_form_validate',
      ),
    ),
    'weight' => array(
      '#form_builder' => array(
        'property_group' => 'hidden',
      ),
      '#type' => 'textfield',
      '#size' => 6,
      '#title' => 'Weight',
      '#default_value' => 0,
    ),
    'placeholder' => array(
      '#type' => 'textfield',
      '#title' => 'Placeholder',
      '#default_value' => '',
      '#description' => 'The placeholder will be shown in the field until the user starts entering a value.',
      '#weight' => 1,
      '#tree' => true,
      '#form_builder' => array(
        'property_group' => 'display',
      ),
    ),
    'css_classes' => array(
      '#type' => 'textfield',
      '#title' => 'CSS classes',
      '#default_value' => '',
      '#description' => 'Apply a class to the field. Separate multiple by spaces.',
      '#weight' => 51,
      '#tree' => true,
      '#form_builder' => array(
        'property_group' => 'display',
      ),
    ),
    'wrapper_classes' => array(
      '#type' => 'textfield',
      '#title' => 'Wrapper CSS classes',
      '#default_value' => '',
      '#description' => 'Apply a class to the wrapper around both the field and its label. Separate multiple by spaces.',
      '#weight' => 50,
      '#tree' => true,
      '#form_builder' => array(
        'property_group' => 'display',
      ),
    ),
  ), $a);

  // Render the configuration form of a grid component.
  $element = $form
    ->getElement('cid_4');
  $config_form = $element
    ->configurationForm([], $form_state);
  $this
    ->assertEqual('Questions', $config_form['grid_questions']['#title']);

  // Render the configuration form of a grid component.
  $element = $form
    ->getElement('cid_5');
  $config_form = $element
    ->configurationForm([], $form_state);
  $this
    ->assertEqual([
    '1' => 'one',
    '2' => 'two',
    '3' => 'three',
  ], $config_form['options']['#options']);
}