From 39fe1b12fc737c584974bd8c4667fa4745aa561b Mon Sep 17 00:00:00 2001 From: David Matejka Date: Mon, 12 Sep 2016 10:55:36 +0200 Subject: [PATCH] signalReceived: convert value to a correct type --- src/SecuredLinksControlTrait.php | 2 + tests/cases/SecuredLinksTest.php7.phpt | 68 ++++++++++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 tests/cases/SecuredLinksTest.php7.phpt diff --git a/src/SecuredLinksControlTrait.php b/src/SecuredLinksControlTrait.php index 5a127df..3ca9a2f 100644 --- a/src/SecuredLinksControlTrait.php +++ b/src/SecuredLinksControlTrait.php @@ -53,6 +53,8 @@ public function signalReceived($signal) } if (isset($this->params[$param->name])) { $params[$param->name] = $this->params[$param->name]; + list($type, $isClass) = Nette\Application\UI\ComponentReflection::getParameterType($param); + Nette\Application\UI\ComponentReflection::convertType($params[$param->name], $type, $isClass); } } } diff --git a/tests/cases/SecuredLinksTest.php7.phpt b/tests/cases/SecuredLinksTest.php7.phpt new file mode 100644 index 0000000..dee4246 --- /dev/null +++ b/tests/cases/SecuredLinksTest.php7.phpt @@ -0,0 +1,68 @@ += 7.0.0 + */ + +use Nette\Application\Request; +use Nette\Application\Routers\SimpleRouter; +use Nette\Application\UI\Presenter; +use Nette\Http\Request as HttpRequest; +use Nette\Http\Response; +use Nette\Http\UrlScript; +use Nextras\Application\UI\SecuredLinksPresenterTrait; +use Tester\Assert; + +require __DIR__ . '/../bootstrap.php'; + + +class TestPresenter extends Presenter +{ + use SecuredLinksPresenterTrait; + + + public function renderDefault() + { + $this->terminate(); + } + + + /** @secured */ + public function handlePay(bool $value) + { + $this->redirect('this'); + } + +} + + +$url = new UrlScript('http://localhost/index.php'); +$url->setScriptPath('/index.php'); + +$httpRequest = new HttpRequest($url); +$httpResponse = new Response(); + +$router = new SimpleRouter(); +$request = new Request('Test', HttpRequest::GET, []); + +$sessionSection = Mockery::mock('alias:Nette\Http\SessionSection'); +$sessionSection->token = 'abcd'; + +$session = Mockery::mock('Nette\Http\Session'); +$session->shouldReceive('getSection')->with('Nextras.Application.UI.SecuredLinksPresenterTrait')->andReturn($sessionSection); +$session->shouldReceive('getId')->andReturn('session_id_1'); + +$presenter = new TestPresenter(); +$presenter->autoCanonicalize = FALSE; +$presenter->injectPrimary(NULL, NULL, $router, $httpRequest, $httpResponse, $session, NULL); +$presenter->run($request); + +Assert::same('/index.php?value=0&action=default&do=pay&presenter=Test&_sec=JqCasYHU', $presenter->link('pay!', [FALSE])); + +$presenter->run(new Request('Test', 'GET', [ + 'action' => 'default', + 'do' => 'pay', + 'value' => '0', + '_sec' => 'JqCasYHU', +])); + +Mockery::close();