/** * Tests, that the redirect function throws an exception and correctly * passes the parameters. */ public function testRedirect() { $this->createCleanResponse(); try { $this->response->redirect('http://www.example.com/', 301); $this->fail('HttpResponse::redirect should throw a RedirectException'); } catch (\YapepBase\Exception\RedirectException $e) { } $this->response->send(); $this->assertEquals(301, $this->output->responseCode); $this->assertEquals(array('http://www.example.com/'), $this->output->headers['Location']); }
function testRedirectToRoute() { $previousLevel = ob_get_level(); $router = new RouterMock(); Application::getInstance()->setRouter($router); $request = new HttpRequest(array(), array(), array(), array('REQUEST_URI' => '/'), array(), array()); $out = new OutputMock(); $response = new HttpResponse($out); $o = new HttpMockController($request, $response); try { $o->testRedirectToRoute(); $this->resetObToLevel($previousLevel); $this->fail('RedirectToRoute test should result in a RedirectException'); } catch (RedirectException $e) { $this->assertEquals(RedirectException::TYPE_EXTERNAL, $e->getCode()); } $response->send(); $this->assertEquals(303, $out->responseCode); $this->assertEquals(array('/?test=test&test2%5B0%5D=test1&test2%5B1%5D=test2#test'), $out->headers['Location']); $this->resetObToLevel($previousLevel); }