@@ -66,11 +66,30 @@ class ErrorPresenter implements Nette\Application\IPresenter
6666}
6767
6868
69+ class UIPresenter extends Nette \Application \UI \Presenter
70+ {
71+ public function actionDefault ()
72+ {
73+ $ this ->sendResponse (new TextResponse ('' ));
74+ }
75+ }
76+
77+
78+ class UIErrorPresenter extends Nette \Application \UI \Presenter
79+ {
80+ public function actionDefault ()
81+ {
82+ $ this ->sendResponse (new TextResponse ('' ));
83+ }
84+ }
85+
86+
6987$ httpRequest = Mockery::mock (Nette \Http \IRequest::class);
7088$ httpRequest ->shouldReceive ('getMethod ' )->andReturn ('GET ' );
7189$ httpRequest ->shouldReceive ('getPost ' )->andReturn ([]);
7290$ httpRequest ->shouldReceive ('getFiles ' )->andReturn ([]);
7391$ httpRequest ->shouldReceive ('isSecured ' )->andReturn (false );
92+ $ httpRequest ->shouldReceive ('isAjax ' )->andReturn (false );
7493
7594$ httpResponse = Mockery::mock (Nette \Http \IResponse::class);
7695$ httpResponse ->shouldIgnoreMissing ();
@@ -308,6 +327,58 @@ Assert::noError(function () use ($httpRequest, $httpResponse) {
308327});
309328
310329
330+ // error during onPresenter with catchException + errorPresenter
331+ Assert::noError (function () use ($ httpRequest , $ httpResponse ) {
332+ $ presenter = new UIPresenter ;
333+ $ errorPresenter = new UIErrorPresenter ;
334+
335+ $ presenterFactory = Mockery::mock (IPresenterFactory::class);
336+ $ presenterFactory ->shouldReceive ('createPresenter ' )->with ('UI ' )->andReturn ($ presenter );
337+ $ presenterFactory ->shouldReceive ('createPresenter ' )->with ('UIError ' )->andReturn ($ errorPresenter );
338+ $ presenterFactory ->shouldReceive ('getPresenterClass ' )->with ('UIError ' )->andReturn (UIErrorPresenter::class);
339+
340+ $ router = Mockery::mock (Router::class);
341+ $ router ->shouldReceive ('match ' )->andReturn (['presenter ' => 'UI ' ]);
342+
343+ $ errors = [];
344+
345+ $ presenter ->injectPrimary (null , $ presenterFactory , $ router , $ httpRequest , $ httpResponse );
346+ $ errorPresenter ->injectPrimary (null , $ presenterFactory , $ router , $ httpRequest , $ httpResponse );
347+
348+ $ app = new Application ($ presenterFactory , $ router , $ httpRequest , $ httpResponse );
349+ $ app ->catchExceptions = true ;
350+ $ app ->errorPresenter = 'UIError ' ;
351+
352+ $ app ->onPresenter [] = function (Application $ application , Nette \Application \IPresenter $ presenter ) use ($ errorPresenter ) {
353+ if (!$ presenter instanceof UIErrorPresenter) {
354+ throw new RuntimeException ('Error on presenter ' );
355+ }
356+ };
357+
358+ $ app ->onError [] = function ($ app , $ e ) use (&$ errors ) {
359+ $ errors [] = $ e ;
360+ };
361+
362+ Assert::noError (function () use ($ app ) {
363+ $ app ->run ();
364+ });
365+
366+ Assert::count (1 , $ errors );
367+ Assert::same ('Error on presenter ' , $ errors [0 ]->getMessage ());
368+
369+ $ requests = $ app ->getRequests ();
370+ Assert::count (2 , $ requests );
371+
372+ Assert::same ('GET ' , $ requests [0 ]->getMethod ());
373+ Assert::same ('UI ' , $ requests [0 ]->getPresenterName ());
374+ Assert::null ($ presenter ->getRequest ()); // Good presenter did not run
375+
376+ Assert::same ('FORWARD ' , $ requests [1 ]->getMethod ());
377+ Assert::same ('UIError ' , $ requests [1 ]->getPresenterName ());
378+ Assert::equal ($ requests [1 ], $ errorPresenter ->getRequest ());
379+ });
380+
381+
311382// check maxLoop
312383Assert::noError (function () use ($ httpRequest , $ httpResponse ) {
313384 $ presenter = new InfinityForwardingPresenter ;
0 commit comments