public function testRenderDefaultView()
 {
     Config::set('hyperframework.web.error_view.root_path', 'invalid');
     $this->expectOutputString('404 not found');
     $engine = $this->getMock('Hyperframework\\Web\\ResponseEngine');
     $engine->expects($this->once())->method('setHeader')->with('Content-Type: text/plain; charset=utf-8');
     Response::setEngine($engine);
     $view = new ErrorView();
     $view->render(404, 'not found', null);
 }
 /**
  * @expectedException Hyperframework\Web\ForbiddenException
  */
 public function testInvalidToken()
 {
     $engine2 = $this->getMock('Hyperframework\\Web\\ResponseEngine');
     $engine2->expects($this->once())->method('setCookie');
     Response::setEngine($engine2);
     $engine = new CsrfProtectionEngine();
     $_SERVER['REQUEST_METHOD'] = 'POST';
     Request::setBody(['_csrf_token' => 'invalid']);
     $_COOKIE['_csrf_token'] = 'token';
     $engine->run();
 }
 private function mockEngineMethod($method)
 {
     $engine = $this->getMock('Hyperframework\\Web\\ResponseEngine');
     Response::setEngine($engine);
     return $engine->expects($this->once())->method($method);
 }
 public function testRedirect()
 {
     $engine = $this->getMock('Hyperframework\\Web\\ResponseEngine');
     $engine->expects($this->once())->method('setHeader')->with('Location: /', true, 302);
     $app = $this->getMockBuilder('Hyperframework\\Web\\App')->setConstructorArgs([dirname(__DIR__)])->getMock();
     $app->expects($this->once())->method('quit');
     Response::setEngine($engine);
     $this->router = $this->getMockBuilder('Hyperframework\\Web\\Test\\Router')->setMethods(['getApp'])->setConstructorArgs([$app])->disableOriginalConstructor()->getMock();
     $this->router->expects($this->once())->method('getApp')->willReturn($app);
     $this->callProtectedMethod($this->router, 'redirect', ['/']);
 }
 public function testRedirect()
 {
     $app = new App(dirname(__DIR__));
     $router = $app->getRouter();
     $router->setAction('index');
     $controller = $this->getMockBuilder('Hyperframework\\Web\\Test\\IndexController')->setConstructorArgs([$app])->setMethods(['handleAction', 'quit'])->getMock();
     $controller->expects($this->once())->method('quit');
     $engine = $this->getMock('Hyperframework\\Web\\ResponseEngine');
     $engine->expects($this->once())->method('setHeader')->with('Location: /', true, 302);
     Response::setEngine($engine);
     $controller->redirect('/');
 }
 public function testRewriteHttpHeadersForHttpException()
 {
     $engine = $this->getMock('Hyperframework\\Web\\ResponseEngine');
     $engine->expects($this->once())->method('removeHeaders');
     $engine->expects($this->once())->method('setHeader')->with('HTTP/1.1 404 Not Found');
     $engine->method('headersSent')->willReturn(false);
     Response::setEngine($engine);
     $handler = $this->getMockBuilder('Hyperframework\\Web\\ErrorHandler')->setMethods(['renderErrorView', 'getError'])->getMock();
     $handler->method('getError')->willReturn(new NotFoundException());
     $this->callProtectedMethod($handler, 'handle');
 }