? 297972_drupal_execute_6.patch
Index: includes/form.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/form.inc,v
retrieving revision 1.320
diff -u -p -r1.320 form.inc
--- includes/form.inc	3 Feb 2009 18:55:29 -0000	1.320
+++ includes/form.inc	4 Feb 2009 08:48:39 -0000
@@ -761,7 +761,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.3
diff -u -p -r1.3 form.test
--- modules/simpletest/tests/form.test	28 Jan 2009 07:43:26 -0000	1.3
+++ modules/simpletest/tests/form.test	4 Feb 2009 08:48:40 -0000
@@ -313,3 +313,33 @@ class FormsElementsTableSelectFunctional
 
 }
 
+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 testDrupalExecuteInBatch() {
+    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.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/form_test.module,v
retrieving revision 1.1
diff -u -p -r1.1 form_test.module
--- modules/simpletest/tests/form_test.module	28 Jan 2009 07:43:26 -0000	1.1
+++ modules/simpletest/tests/form_test.module	4 Feb 2009 08:48:40 -0000
@@ -44,6 +44,13 @@ function form_test_menu() {
     'type' => MENU_CALLBACK,
   );
 
+  $items['form_test/drupal_execute_batch_api'] = array(
+    'title' => 'BatchAPI Drupal_execute tests',
+    'page callback' => 'form_test_drupal_execute_batch_api',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+
   return $items;
 }
 
@@ -180,3 +187,48 @@ function _form_test_tableselect_js_selec
 
   return _form_test_tableselect_form_builder($form_state, $options);
 }
+
+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']);
+}
