From 8206e8d3277267cf4b6a1909cc628ae23412adec Mon Sep 17 00:00:00 2001 From: sallyx Date: Fri, 6 Nov 2015 13:27:51 +0100 Subject: [PATCH] Added support for request restore with ajax --- src/Application/UI/Presenter.php | 6 +++++- tests/UI/Presenter.storeRequest().phpt | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index db5683159..22f1729ee 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -1092,7 +1092,7 @@ public function storeRequest($expiration = '+ 10 minutes') $key = Nette\Utils\Random::generate(5); } while (isset($session[$key])); - $session[$key] = [$this->getUser()->getId(), $this->request]; + $session[$key] = [$this->getUser()->getId(), $this->request, (string) $this->httpRequest->getUrl()]; $session->setExpiration($expiration, $key); return $key; } @@ -1110,7 +1110,11 @@ public function restoreRequest($key) return; } $request = clone $session[$key][1]; + $url = $session[$key][2]; unset($session[$key]); + if($this->isAjax()) { + $this->redirectUrl($url); + } $request->setFlag(Application\Request::RESTORED, TRUE); $params = $request->getParameters(); $params[self::FLASH_KEY] = $this->getParameter(self::FLASH_KEY); diff --git a/tests/UI/Presenter.storeRequest().phpt b/tests/UI/Presenter.storeRequest().phpt index 8ed0f95ef..45930c7ef 100644 --- a/tests/UI/Presenter.storeRequest().phpt +++ b/tests/UI/Presenter.storeRequest().phpt @@ -83,11 +83,13 @@ class MockUser extends Security\User $presenter = new TestPresenter(); +$url = 'http://www.example.org/foo/bar'; +$urlScript = new Http\UrlScript($url); $presenter->injectPrimary( NULL, NULL, new Application\Routers\SimpleRouter, - new Http\Request(new Http\UrlScript), + new Http\Request($urlScript), new Http\Response, $session = new MockSession, $user = new MockUser @@ -105,4 +107,4 @@ Assert::same($expiration, $section->testExpiration); Assert::same($key, $section->testExpirationVariables); Assert::same($key, $section->testedKeyExistence); Assert::same($key, $section->storedKey); -Assert::same([$user->getId(), $applicationRequest], $section->storedValue); +Assert::same([$user->getId(), $applicationRequest, $url], $section->storedValue);