1 form.test FormsRedirectTestCase::testRedirect()

Tests form redirection.

File

core/modules/simpletest/tests/form.test, line 1827
Unit tests for the Backdrop Form API.

Class

FormsRedirectTestCase
Tests form redirection.

Code

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->backdropPost($path, $edit, t('Submit'));
  $this->assertUrl($edit['destination'], array(), 'Basic redirection works.');


  // Test without redirection.
  $edit = array(
    'redirection' => FALSE,
  );
  $this->backdropPost($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->backdropPost($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->backdropPost($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->backdropPost($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->backdropPost($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.');
}