0

I have a form with AJAX buttons that add items to a list. To SimpleTest the form, I need to make the AJAX post:

$this->drupalPostAJAX(NULL, $edit, array('op' => 'Add Item Button'));

...then POST the resulting $edit object with the Save button.

$this->drupalPost('admin/structure/fms_report/create', $edit, t('Save'));

My question is, how do I get the resulting $edit object after the first AJAX POST happens?

1 Answer 1

3

On subsequent tests of a form that has already been loaded and posted, this call will submit the form to the same URL with the field values resulting from any previous activity:

$this->drupalPost(NULL, NULL, t('Save'));

The $edit argument is only to submit new field values. And, passing NULL for $path uses the currently loaded page. So, to test my AJAX button that adds items to the form:

$this->drupalGet('path/to/my/form');
$this->drupalPostAJAX(NULL, NULL, array('op' => 'Add Item Button'));
$this->drupalPostAJAX(NULL, NULL, array('op' => 'Add Item Button'));
$this->drupalPost(NULL, NULL, t('Save'));

I was able to verify after this that two items had been added to the form as expected.

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.