/**
  * Test whether we have a mapping for every (core) webform component.
  */
 function testElementMappings()
 {
     $components = webform_webform_component_info();
     $element_info = FormBuilderLoader::instance()->getElementTypeInfo('webform', NULL);
     foreach (array_keys($components) as $type) {
         $map = _form_builder_webform_property_map($type);
         $this->assertTrue(!empty($map['form_builder_type']), "Unmapped component type '{$type}'.");
         $t = $map['form_builder_type'];
         $this->assertTrue(!empty($element_info[$t]), "Component type '{$type}' maps to undefined element_type {$t}");
     }
 }
 public function testOptionsConfiguration()
 {
     module_load_include('inc', 'form_builder', 'includes/form_builder.admin');
     $loader = FormBuilderLoader::instance();
     $form = $loader->getForm('example', 'test', 'testsid');
     $form->save();
     $data = _form_builder_add_element('example', 'test', 'select', NULL, 'testsid', TRUE);
     $options_id = $data['elementId'];
     $form = $loader->fromCache('example', 'test', 'testsid');
     $e = $form->getElement($options_id);
     $form_state = array();
     $form = $e->configurationForm(array(), $form_state);
     $this->assertEqual(array(1 => 'one', 2 => 'two', 3 => 'three'), $form['options']['#options']);
 }
Exemplo n.º 3
0
 /**
  * Integration test _form_builder_add_element().
  *
  * @covers ::_form_builder_add_element
  * @covers ::form_builder_field_render
  * @covers FormBuilderFormNode::formParents
  * @covers FormBuilderFormBase::load
  * @covers FormBuilderFormBase::save
  * @covers FormBuilderFormBase::serialize
  * @covers FormBuilderFormBase::unserialize
  */
 public function test_form_builder_add_element()
 {
     module_load_include('inc', 'form_builder', 'includes/form_builder.admin');
     $loader = FormBuilderLoader::instance();
     $form = $loader->getForm('webform', 'test', 'test', array());
     $form->save();
     $data = _form_builder_add_element('webform', 'test', 'email', NULL, 'test', TRUE);
     $this->assertNotEmpty($data);
     $this->assertNotEmpty($data['html']);
 }
 /**
  * Integration test: Render textfield inside fieldset.
  *
  * @covers ::_form_builder_add_element
  * @covers ::form_builder_field_render
  * @covers FormBuilderFormBase::load
  * @covers FormBuilderFormBase::fromArray
  * @covers FormBuilderFormBase::setElementArray
  */
 public function test_render_fieldset()
 {
     module_load_include('inc', 'form_builder', 'includes/form_builder.admin');
     $loader = FormBuilderLoader::instance();
     $form = $loader->getForm('webform', 'test', 'test', array());
     $form->save();
     drupal_static_reset('drupal_html_id');
     $data = _form_builder_add_element('webform', 'test', 'fieldset', NULL, 'test', TRUE);
     $wrapper = simplexml_load_string($data['html']);
     // Test if element is properly wrapped.
     $this->assertEqual('form-builder-wrapper', (string) $wrapper['class']);
     $this->assertEqual('form-builder-title-bar', (string) $wrapper->div[0]['class']);
     $element = $wrapper->div[1];
     $this->assertEqual('form-builder-element form-builder-element-fieldset', (string) $element['class']);
     $this->assertNotEmpty($element->fieldset);
     $fieldset_id = $data['elementId'];
     $data = _form_builder_add_element('webform', 'test', 'textfield', NULL, 'test', TRUE);
     $this->assertNotEquals($fieldset_id, $data['elementId']);
     $textfield_id = $data['elementId'];
     $form = $loader->fromCache('webform', 'test', 'test');
     $element = $form->getElementArray($textfield_id);
     $element['#weight'] = 1;
     $element['#form_builder']['parent_id'] = $fieldset_id;
     $form->setElementArray($element);
     $form_array = $form->getFormArray();
     $this->assertEqual(array($fieldset_id), element_children($form_array));
     $this->assertEqual(array($textfield_id), element_children($form_array[$fieldset_id]));
 }