? form.patch Index: includes/form.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/form.inc,v retrieving revision 1.310 diff -u -p -r1.310 form.inc --- includes/form.inc 30 Dec 2008 16:43:14 -0000 1.310 +++ includes/form.inc 8 Jan 2009 10:29:24 -0000 @@ -757,7 +757,7 @@ function form_execute_handlers($type, &$ foreach ($handlers as $function) { if (drupal_function_exists($function)) { - if ($type == 'submit' && ($batch =& batch_get())) { + if ($type == 'submit' && ($batch =& batch_get()) && !isset($batch['current_set'])) { // Some previous _submit handler has set a batch. We store the call // in a special 'control' batch set, for execution at the correct // time during the batch processing workflow. Index: modules/simpletest/tests/form.test =================================================================== RCS file: /cvs/drupal/drupal/modules/simpletest/tests/form.test,v retrieving revision 1.1 diff -u -p -r1.1 form.test --- modules/simpletest/tests/form.test 14 Aug 2008 09:18:28 -0000 1.1 +++ modules/simpletest/tests/form.test 8 Jan 2009 10:29:25 -0000 @@ -72,3 +72,34 @@ class FormsTestCase extends DrupalWebTes drupal_get_messages(); } } + +class FormAPITestCase extends DrupalWebTestCase { + + function getInfo() { + return array( + 'name' => t('Drupal Execute and Batch API'), + 'description' => t('Tests the compatibility of drupal_execute and the Batch API'), + 'group' => t('Form API'), + ); + } + + /** + * Check that we can run drupal_execute during a batch. + */ + function testRequiredFields() { + variable_set('form_test_mock_submit', 0); // This variable gets updated in the call below + + $this->drupalGet('form_test/drupal_execute_batch_api'); + + $this->assertEqual(2, variable_get('form_test_mock_submit', 0), t('Check drupal_execute called submit handlers when running in a batch')); + variable_del('form_test_mock_submit'); + } + + /** + * Implementation of setUp(). + */ + function setUp() { + parent::setUp('form_test'); + } + +} Index: modules/simpletest/tests/form_test.info =================================================================== RCS file: modules/simpletest/tests/form_test.info diff -N modules/simpletest/tests/form_test.info --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/simpletest/tests/form_test.info 8 Jan 2009 10:29:25 -0000 @@ -0,0 +1,8 @@ +; $Id: $ +name = "Form Test" +description = "Support module for Form tests." +package = Testing +version = VERSION +core = 7.x +files[] = form_test.module +hidden = TRUE Index: modules/simpletest/tests/form_test.module =================================================================== RCS file: modules/simpletest/tests/form_test.module diff -N modules/simpletest/tests/form_test.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ modules/simpletest/tests/form_test.module 8 Jan 2009 10:29:25 -0000 @@ -0,0 +1,65 @@ + 'form_test_drupal_execute_batch_api', + 'access callback' => 'form_test_access_callback', + 'type' => MENU_CALLBACK, + ); + + return $items; +} + +function form_test_access_callback() { + return TRUE; +} + +function form_test_drupal_execute_batch_api($arg = '') { + if ($arg == 'done') { + return t('Done'); + } + // Set up the batch:} + //$bacth['title'] = t('drupal_execute Test'); + $batch['operations'] = array( + array('form_test_batch_callback', array(1)), + array('form_test_batch_callback', array(2)), + ); + //$batch['finished'] = 'form_test_batch_finished'; + batch_set($batch); + batch_process('form_test/drupal_execute_batch_api/done'); +} + +function form_test_batch_callback($value) { + $state['values']['test_value'] = $value; + drupal_execute('form_test_mock_form', $state); +} + +function form_test_mock_form($form_state) { + $form = array(); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + $form['test_value'] = array( + '#type' => 'textfield', + '#default_value' => 0, + ); + + return $form; + +} + +function form_test_mock_form_validate($form, &$form_state) { + +} + +function form_test_mock_form_submit($form, &$form_state) { + variable_set('form_test_mock_submit', $form_state['values']['test_value']); +}