summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rothstein <drothstein@gmail.com>2012-08-29 10:42:39 -0400
committerDavid Rothstein <drothstein@gmail.com>2012-08-29 10:42:39 -0400
commit50fce517e5ac1c6071ee76c82e17d795b6926baf (patch)
tree86afa78c6e96d83b83c6084f149c6a573c61c6f7
parentc6200e83f52bf0aedf5d6fca7a1960ebdc5307be (diff)
downloadbrdo-50fce517e5ac1c6071ee76c82e17d795b6926baf.tar.gz
brdo-50fce517e5ac1c6071ee76c82e17d795b6926baf.tar.bz2
Issue #171267 by tim.plunkett, chx, NROTC_Webmaster, dcam: Fixed form redirects removes get variables like sort and order.
-rw-r--r--includes/form.inc2
-rw-r--r--modules/simpletest/tests/form.test75
-rw-r--r--modules/simpletest/tests/form_test.module45
3 files changed, 121 insertions, 1 deletions
diff --git a/includes/form.inc b/includes/form.inc
index cc7a2c0f7..b6ffc3ca2 100644
--- a/includes/form.inc
+++ b/includes/form.inc
@@ -1258,7 +1258,7 @@ function drupal_redirect_form($form_state) {
$function($form_state['redirect']);
}
}
- drupal_goto($_GET['q']);
+ drupal_goto(current_path(), array('query' => drupal_get_query_parameters()));
}
}
diff --git a/modules/simpletest/tests/form.test b/modules/simpletest/tests/form.test
index 985abe31b..675e8d189 100644
--- a/modules/simpletest/tests/form.test
+++ b/modules/simpletest/tests/form.test
@@ -1309,6 +1309,81 @@ class FormsRebuildTestCase extends DrupalWebTestCase {
}
/**
+ * Tests form redirection.
+ */
+class FormsRedirectTestCase extends DrupalWebTestCase {
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Form redirecting',
+ 'description' => 'Tests functionality of drupal_redirect_form().',
+ 'group' => 'Form API',
+ );
+ }
+
+ function setUp() {
+ parent::setUp(array('form_test'));
+ }
+
+ /**
+ * Tests form redirection.
+ */
+ function testRedirect() {
+ $path = 'form-test/redirect';
+ $options = array('query' => array('foo' => 'bar'));
+ $options['absolute'] = TRUE;
+
+ // Test basic redirection.
+ $edit = array(
+ 'redirection' => TRUE,
+ 'destination' => $this->randomName(),
+ );
+ $this->drupalPost($path, $edit, t('Submit'));
+ $this->assertUrl($edit['destination'], array(), 'Basic redirection works.');
+
+
+ // Test without redirection.
+ $edit = array(
+ 'redirection' => FALSE,
+ );
+ $this->drupalPost($path, $edit, t('Submit'));
+ $this->assertUrl($path, array(), 'When redirect is set to FALSE, there should be no redirection.');
+
+ // Test redirection with query parameters.
+ $edit = array(
+ 'redirection' => TRUE,
+ 'destination' => $this->randomName(),
+ );
+ $this->drupalPost($path, $edit, t('Submit'), $options);
+ $this->assertUrl($edit['destination'], array(), 'Redirection with query parameters works.');
+
+ // Test without redirection but with query parameters.
+ $edit = array(
+ 'redirection' => FALSE,
+ );
+ $this->drupalPost($path, $edit, t('Submit'), $options);
+ $this->assertUrl($path, $options, 'When redirect is set to FALSE, there should be no redirection, and the query parameters should be passed along.');
+
+ // Test redirection back to the original path.
+ $edit = array(
+ 'redirection' => TRUE,
+ 'destination' => '',
+ );
+ $this->drupalPost($path, $edit, t('Submit'));
+ $this->assertUrl($path, array(), 'When using an empty redirection string, there should be no redirection.');
+
+ // Test redirection back to the original path with query parameters.
+ $edit = array(
+ 'redirection' => TRUE,
+ 'destination' => '',
+ );
+ $this->drupalPost($path, $edit, t('Submit'), $options);
+ $this->assertUrl($path, $options, 'When using an empty redirection string, there should be no redirection, and the query parameters should be passed along.');
+ }
+
+}
+
+/**
* Test the programmatic form submission behavior.
*/
class FormsProgrammaticTestCase extends DrupalWebTestCase {
diff --git a/modules/simpletest/tests/form_test.module b/modules/simpletest/tests/form_test.module
index e4ac77b12..5d6527680 100644
--- a/modules/simpletest/tests/form_test.module
+++ b/modules/simpletest/tests/form_test.module
@@ -151,6 +151,14 @@ function form_test_menu() {
'type' => MENU_CALLBACK,
);
+ $items['form-test/redirect'] = array(
+ 'title' => 'Redirect test',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('form_test_redirect'),
+ 'access callback' => TRUE,
+ 'type' => MENU_CALLBACK,
+ );
+
$items['form_test/form-labels'] = array(
'title' => 'Form label test',
'page callback' => 'drupal_get_form',
@@ -1644,6 +1652,43 @@ function form_test_clicked_button_submit($form, &$form_state) {
}
/**
+ * Form builder to detect form redirect.
+ */
+function form_test_redirect($form, &$form_state) {
+ $form['redirection'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use redirection'),
+ );
+ $form['destination'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Redirect destination'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="redirection"]' => array('checked' => TRUE),
+ ),
+ ),
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+
+ return $form;
+}
+
+/**
+ * Form submit handler to test different redirect behaviours.
+ */
+function form_test_redirect_submit(&$form, &$form_state) {
+ if (!empty($form_state['values']['redirection'])) {
+ $form_state['redirect'] = !empty($form_state['values']['destination']) ? $form_state['values']['destination'] : NULL;
+ }
+ else {
+ $form_state['redirect'] = FALSE;
+ }
+}
+
+/**
* Implements hook_form_FORM_ID_alter() for the registration form.
*/
function form_test_form_user_register_form_alter(&$form, &$form_state) {