1 common.test | CommonBackdropGotoTestCase::testBackdropGoto() |
Test backdrop_goto().
File
- core/
modules/ simpletest/ tests/ common.test, line 1292 - Tests for common.inc functionality.
Class
- CommonBackdropGotoTestCase
- Tests backdrop_goto() and hook_backdrop_goto_alter().
Code
function testBackdropGoto() {
$this->backdropGet('common-test/backdrop_goto/redirect');
$headers = $this->backdropGetHeaders(TRUE);
list(, $status) = explode(' ', $headers[0][':status'], 3);
$this->assertEqual($status, 302, 'Expected response code was sent.');
$this->assertText('backdrop_goto', 'Backdrop goto redirect succeeded.');
$this->assertEqual($this->getUrl(), url('common-test/backdrop_goto', array('absolute' => TRUE)), 'Backdrop goto redirected to expected URL.');
// Test that calling backdrop_goto() on the current path is not dangerous.
state_set('common_test_redirect_current_path', TRUE);
$this->backdropGet('', array('query' => array('q' => 'http://www.example.com/')));
$headers = $this->backdropGetHeaders(TRUE);
list(, $status) = explode(' ', $headers[0][':status'], 3);
$this->assertEqual($status, 302, 'Expected response code was sent.');
$this->assertNotEqual($this->getUrl(), 'http://www.example.com/', 'Backdrop goto did not redirect to external URL.');
$this->assertTrue(strpos($this->getUrl(), url('<front>', array('absolute' => TRUE))) === 0, 'Backdrop redirected to itself.');
state_del('common_test_redirect_current_path');
$this->backdropGet('common-test/backdrop_goto/redirect_advanced');
$headers = $this->backdropGetHeaders(TRUE);
list(, $status) = explode(' ', $headers[0][':status'], 3);
$this->assertEqual($status, 301, 'Expected response code was sent.');
$this->assertText('backdrop_goto', 'Backdrop goto redirect succeeded.');
$this->assertEqual($this->getUrl(), url('common-test/backdrop_goto', array('query' => array('foo' => '123'), 'absolute' => TRUE)), 'Backdrop goto redirected to expected URL.');
// Test that backdrop_goto() respects ?destination=xxx. Use an complicated URL
// to test that the path is encoded and decoded properly.
$destination = 'common-test/backdrop_goto/destination?foo=%2525&bar=123';
$this->backdropGet('common-test/backdrop_goto/redirect', array('query' => array('destination' => $destination)));
$this->assertText('backdrop_goto', 'Backdrop goto redirect with destination succeeded.');
$this->assertEqual($this->getUrl(), url('common-test/backdrop_goto/destination', array('query' => array('foo' => '%25', 'bar' => '123'), 'absolute' => TRUE)), 'Backdrop goto redirected to given query string destination.');
}