Skip to content

Commit

Permalink
signalReceived: convert value to a correct type
Browse files Browse the repository at this point in the history
  • Loading branch information
matej21 committed Sep 12, 2016
1 parent 1b5681b commit 39fe1b1
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/SecuredLinksControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
68 changes: 68 additions & 0 deletions tests/cases/SecuredLinksTest.php7.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* @phpVersion >= 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();

0 comments on commit 39fe1b1

Please sign in to comment.