? form.patch
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.314
diff -u -p -r1.314 form.inc
--- includes/form.inc	19 Jan 2009 10:46:50 -0000	1.314
+++ includes/form.inc	21 Jan 2009 07:41:59 -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.2
diff -u -p -r1.2 form.test
--- modules/simpletest/tests/form.test	17 Jan 2009 19:27:32 -0000	1.2
+++ modules/simpletest/tests/form.test	21 Jan 2009 07:41:59 -0000
@@ -73,6 +73,37 @@ class FormsTestCase extends DrupalWebTes
   }
 }
 
+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');
+  }
+
+}
+
 /**
  * Test form type functions for expected behavior.
  */
@@ -109,4 +140,3 @@ class FormsTestTypeCase extends DrupalWe
     $this->assertNull(form_type_checkbox_value($form, $edit), t('form_type_checkbox_value() returns NULL when $edit is FALSE'));
   }
 }
-
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	21 Jan 2009 07:41:59 -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	21 Jan 2009 07:41:59 -0000
@@ -0,0 +1,65 @@
+<?php
+
+/**
+ * Implementation of hook_menu()
+ */
+function form_test_menu() {
+  $items = array();
+
+  $items['form_test/drupal_execute_batch_api'] = array(
+    'page callback' => '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']);
+}
