summaryrefslogtreecommitdiff
path: root/modules/simpletest/tests/form.test
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-04-22 09:12:44 +0000
committerDries Buytaert <dries@buytaert.net>2009-04-22 09:12:44 +0000
commit2bc19555bfca04551333e361509c2f51841e16c2 (patch)
tree2548445f39fe4e4ffc0910d4446f8c3fdaf46093 /modules/simpletest/tests/form.test
parent920babfe6ea1c929d7df16631e4de52f0646e518 (diff)
downloadbrdo-2bc19555bfca04551333e361509c2f51841e16c2.tar.gz
brdo-2bc19555bfca04551333e361509c2f51841e16c2.tar.bz2
- Patch #302240 by fago: fixed various problems with form storage and added tests. Yay.
Diffstat (limited to 'modules/simpletest/tests/form.test')
-rw-r--r--modules/simpletest/tests/form.test66
1 files changed, 66 insertions, 0 deletions
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 88b2614b9..d787a850f 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -383,3 +383,69 @@ class FormAPITestCase extends DrupalWebTestCase {
}
}
+
+/**
+ * Test the form storage on a multistep form.
+ *
+ * The tested form puts data into the storage during the initial form
+ * construction. These tests verify that there are no duplicate form
+ * constructions, with and without manual form caching activiated. Furthermore
+ * when a validation error occurs, it makes sure that changed form element
+ * values aren't lost due to a wrong form rebuild.
+ */
+class FormsFormStorageTestCase extends DrupalWebTestCase {
+
+ 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'),
+ );
+ }
+
+ function setUp() {
+ parent::setUp('form_test');
+ }
+
+ /**
+ * Tests using the form in a usual way.
+ */
+ function testForm() {
+
+ $user = $this->drupalCreateUser(array('access content'));
+ $this->drupalLogin($user);
+
+ $this->drupalPost('form_test/form-storage', array('title' => 'new', 'value' => 'value_is_set'), 'Continue');
+ $this->assertText('Form constructions: 2', t('The form has been constructed two times till now.'));
+
+ $this->drupalPost(NULL, array(), 'Save');
+ $this->assertText('Form constructions: 3', t('The form has been constructed three times till now.'));
+ $this->assertText('Title: new', t('The form storage has stored the values.'));
+ }
+
+ /**
+ * Tests using the form with an activated #cache property.
+ */
+ function testFormCached() {
+ $user = $this->drupalCreateUser(array('access content'));
+ $this->drupalLogin($user);
+
+ $this->drupalPost('form_test/form-storage', array('title' => 'new', 'value' => 'value_is_set'), 'Continue', array('query' => 'cache=1'));
+ $this->assertText('Form constructions: 1', t('The form has been constructed one time till now.'));
+
+ $this->drupalPost(NULL, array(), 'Save', array('query' => 'cache=1'));
+ $this->assertText('Form constructions: 2', t('The form has been constructed two times till now.'));
+ $this->assertText('Title: new', t('The form storage has stored the values.'));
+ }
+
+ /**
+ * Tests validation when form storage is used.
+ */
+ function testValidation() {
+ $user = $this->drupalCreateUser(array('access content'));
+ $this->drupalLogin($user);
+
+ $this->drupalPost('form_test/form-storage', array('title' => '', 'value' => 'value_is_set'), 'Continue');
+ $this->assertPattern('/value_is_set/', t("The input values have been kept."));
+ }
+}