Index: modules/simpletest/tests/form_storage_test.module
===================================================================
RCS file: modules/simpletest/tests/form_storage_test.module
diff -N modules/simpletest/tests/form_storage_test.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/form_storage_test.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,82 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_menu().
+ */
+function form_storage_test_menu() {
+  $items['tests/form_storage'] = array(
+    'title' => 'Form storage test',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('form_storage_test_form'),
+    'access callback' => 'user_access',
+    'access arguments' => array('access content'),
+    'type' => MENU_CALLBACK,
+  );
+  return $items;
+}
+
+
+function form_storage_test_form(&$form_state) {
+  // Initialize
+  if (!isset($form_state['storage'])) {
+    if (!$form_state['post']) {
+      $_SESSION['builds'] = 0;
+    }
+    $form_state['storage'] = array(
+      'thing' => array(
+        'title' => 'none',
+        'value' => '',
+      ),
+    );
+    $form_state['storage'] += array('step' => 1);
+  }
+
+  // Count how often the form is built
+  $_SESSION['builds']++;
+
+  if ($form_state['storage']['step'] == 1) {
+    $form['title'] = array(
+      '#type' => 'textfield',
+      '#title' => 'title',
+      '#default_value' => $form_state['storage']['thing']['title'],
+      '#required' => TRUE,
+    );
+    $form['value'] = array(
+      '#type' => 'textfield',
+      '#title' => 'value',
+      '#default_value' => $form_state['storage']['thing']['value'],
+    );
+    $form['submit'] = array(
+      '#type' => 'submit',
+      '#value' => 'Continue',
+    );
+  }
+  else {
+    $form['step'] = array('#value' => 'This is the second step.');
+    $form['submit'] = array(
+      '#type' => 'submit',
+      '#value' => 'Save',
+    );
+  }
+
+  if (isset($_REQUEST['cache'])) {
+    // Manually activate caching, so we can test that the storage keeps working when
+    // it's enabled.
+    $form['#cache'] = TRUE;
+  }
+
+  return $form;
+}
+
+function form_storage_test_form_submit($form, &$form_state) {
+  if ($form_state['storage']['step'] == 1) {
+    $form_state['storage']['thing']['title'] = $form_state['values']['title'];
+    $form_state['storage']['thing']['value'] = $form_state['values']['value'];
+  }
+  else {
+    drupal_set_message("The things title has been set to ". $form_state['storage']['thing']['title']);
+  }
+  $form_state['storage']['step']++;
+  drupal_set_message("The form built ". $_SESSION['builds'] ." times so far.");
+}
Index: modules/simpletest/tests/form_storage_test.info
===================================================================
RCS file: modules/simpletest/tests/form_storage_test.info
diff -N modules/simpletest/tests/form_storage_test.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/form_storage_test.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,8 @@
+; $Id$
+name = "Form Storage Test"
+description = "Support module for testing a form making use of the storage."
+package = Testing
+version = VERSION
+core = 7.x
+files[] = form_storage_test.module
+hidden = TRUE
Index: modules/simpletest/tests/form_storage.test
===================================================================
RCS file: modules/simpletest/tests/form_storage.test
diff -N modules/simpletest/tests/form_storage.test
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ modules/simpletest/tests/form_storage.test	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,67 @@
+<?php
+// $Id: xmlrpc.test,v 1.1 2008/08/09 12:41:22 dries Exp $
+
+class FormStorageTestCase extends DrupalWebTestCase {
+  /**
+   * Implementation of getInfo().
+   */
+  function getInfo() {
+    return array(
+      'name'  => t('Multistep form using form storage'),
+      'description'  => t('Tests a multistep form using form storage and makes sure validation and caching works right.'),
+      'group' => t('Form API'),
+    );
+  }
+
+  /**
+   * Implementation of setUp().
+   */
+  function setUp() {
+    parent::setUp('form_storage_test');
+  }
+
+  /**
+   * Tests using the form in a usual way.
+   */
+  function testForm() {
+    $user = $this->drupalCreateUser(array('access content'));
+    $this->drupalLogin($user);
+
+    $this->drupalPost('tests/form_storage', array('title' => 'new', 'value' => 'value_is_set'), 'Continue');
+    $this->assertText('The form built 2 times so far.', t("The number of past form builds is correct."));
+
+    $this->drupalPost(NULL, array(), 'Save');
+    watchdog('test', $this->drupalGetContent());
+
+    $this->assertText('The form built 3 times so far.', t("The number of past form builds is correct."));
+    $this->assertText('The things title has been set to new', t('The form storage has correctly stored our values.'));
+  }
+
+  /**
+   * Tests using the form with an activated #cache property.
+   */
+  function testFormCached() {
+    $user = $this->drupalCreateUser(array('access content'));
+    $this->drupalLogin($user);
+
+    $this->drupalPost('tests/form_storage', array('title' => 'new', 'value' => 'value_is_set'), 'Continue', array('query' => 'cache=1'));
+    $this->assertText('The form built 1 times so far.', t("The number of past form builds is correct."));
+
+    $this->drupalPost(NULL, array(), 'Save');
+    watchdog('test', $this->drupalGetContent());
+
+    $this->assertText('The form built 2 times so far.', t("The number of past form builds is correct."));
+    $this->assertText('The things title has been set to new', t('The form storage has correctly stored our values.'));
+  }
+
+  /**
+   * Tests validation when form storage is used.
+   */
+  function testValidation() {
+    $user = $this->drupalCreateUser(array('access content'));
+    $this->drupalLogin($user);
+
+    $this->drupalPost('tests/form_storage', array('title' => '', 'value' => 'value_is_set'), 'Continue');
+    $this->assertPattern('/value_is_set/', t("The set value is still there."));
+  }
+}
