0

So have a function that does something like this:

function mymod_init()
{
    $ip = '123.123.123.123';
    $newPath = mymod_redirect_calculate($ip);
    if (!empty($newPath)) drupal_goto($newPath);
}

This completely breaks unit testing. I have tests for the "mymod_redirect_calculate", but if I add the above to my init function as shown, the tests can't run.

From what I have gathered "exit" and "drupal_goto" breaks unit testing.

How do I get around this?

rockstardev
  • 13,479
  • 39
  • 164
  • 296

1 Answers1

0

Actually drupal_goto() ends up calling exit(). Using header() should work :

function mymod_init() {
  $ip = '123.123.123.123';
  $newPath = mymod_redirect_calculate($ip);
  if (!empty($newPath)) {
    $url = url($newPath, array('absolute' => TRUE));
    header('Location: ' . $url, TRUE);
  }
}
EricLavault
  • 12,130
  • 3
  • 23
  • 45