1

I am able to save a sample webform in Simpletest if I only use title and body:

  $edit = array();
  $edit['title'] = 'Sample webform';
  $edit["body[$langcode][0][value]"] = $this->randomName();
  $this->drupalPost('node/add/webform', $edit, t('Save'));

But when it comes to add the additional fields,

$edit['customfield_xxx'] = '0053416';

the test fails:

Failed to set field customfield_xxx to 0053416

Is any nesting necessary to make it work?

UPDATE It seems like after submitting the form as describe above I need to access the components page: $this->drupalGet('node/1/webform/components'); where I build an array with all components. However I have been able to fill in the specific component form with 1 single field.

1 Answer 1

1

You need to mimics the user's behaviour.

You need to submit individually each form in multiple steps.

You must write correctly the field names (look for input names in the DOM with Firebug or Developer Tools)

  $edit = array();
  $edit['title'] = 'Sample webform';
  $edit["body[$langcode][0][value]"] = $this->randomName();
  $this->drupalPost('node/add/webform', $edit, t('Save'));

then submit the fields individually:

  $edit = array();
  $edit['add[name]'] = 'Sample webform';
  $edit['add[type]'] = 'textfield';//or whatever, optional
  $this->drupalPost('node/webforms/components', $edit, t('Add'));

Rinse and repeat.

You can create a custom function to perform that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.