| 7 common.test | DrupalGotoTest::testDrupalGoto() |
Test drupal_goto().
File
- modules/
simpletest/ tests/ common.test, line 1121 - Tests for common.inc functionality.
Code
function testDrupalGoto() {
$this->drupalGet('common-test/drupal_goto/redirect');
$headers = $this->drupalGetHeaders(TRUE);
list(, $status) = explode(' ', $headers[0][':status'], 3);
$this->assertEqual($status, 302, t('Expected response code was sent.'));
$this->assertText('drupal_goto', t('Drupal goto redirect succeeded.'));
$this->assertEqual($this->getUrl(), url('common-test/drupal_goto', array('absolute' => TRUE)), t('Drupal goto redirected to expected URL.'));
$this->drupalGet('common-test/drupal_goto/redirect_advanced');
$headers = $this->drupalGetHeaders(TRUE);
list(, $status) = explode(' ', $headers[0][':status'], 3);
$this->assertEqual($status, 301, t('Expected response code was sent.'));
$this->assertText('drupal_goto', t('Drupal goto redirect succeeded.'));
$this->assertEqual($this->getUrl(), url('common-test/drupal_goto', array('query' => array('foo' => '123'), 'absolute' => TRUE)), t('Drupal goto redirected to expected URL.'));
// Test that drupal_goto() respects ?destination=xxx. Use an complicated URL
// to test that the path is encoded and decoded properly.
$destination = 'common-test/drupal_goto/destination?foo=%2525&bar=123';
$this->drupalGet('common-test/drupal_goto/redirect', array('query' => array('destination' => $destination)));
$this->assertText('drupal_goto', t('Drupal goto redirect with destination succeeded.'));
$this->assertEqual($this->getUrl(), url('common-test/drupal_goto/destination', array('query' => array('foo' => '%25', 'bar' => '123'), 'absolute' => TRUE)), t('Drupal goto redirected to given query string destination.'));
}
Login or register to post comments