Skip to content

Commit 321e314

Browse files
davidkrmeladg
authored andcommitted
LinkGenerator: throws exception, when try to pass non-associative parameters to missing action (#142)
1 parent 8cc895d commit 321e314

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/Application/LinkGenerator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public function link($dest, array $params = [])
6262
|| method_exists($class, $method = $class::formatRenderMethod($action))
6363
) {
6464
UI\Presenter::argsToParams($class, $method, $params);
65+
} elseif (array_key_exists(0, $params)) {
66+
throw new UI\InvalidLinkException("Unable to pass parameters to action '$presenter:$action', missing corresponding method.");
6567
}
6668
}
6769

tests/Routers/LinkGenerator.phpt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ namespace {
5454
Assert::same('http://nette.org/en/?a=10&action=default&presenter=Homepage', $generator->link('Homepage:', [10]));
5555
Assert::same('http://nette.org/en/?id=20&b=10&action=detail&presenter=Homepage', $generator->link('Homepage:detail', [10, 'id' => 20]));
5656
Assert::same('http://nette.org/en/?action=default&presenter=Homepage#frag:ment', $generator->link('Homepage:#frag:ment'));
57+
Assert::same('http://nette.org/en/?id=10&action=missing&presenter=Homepage', $generator->link('Homepage:missing', ['id' => 10]));
5758
});
5859

5960

@@ -69,6 +70,12 @@ namespace {
6970
}, Nette\Application\UI\InvalidLinkException::class, 'No route for Homepage:default(id=10)');
7071

7172

73+
Assert::exception(function () use ($pf) {
74+
$generator = new LinkGenerator(new Routers\Route('/', 'Homepage:'), new Http\Url('http://nette.org/en/'), $pf);
75+
$generator->link('Homepage:missing', [10]);
76+
}, Nette\Application\UI\InvalidLinkException::class, "Unable to pass parameters to action 'Homepage:missing', missing corresponding method.");
77+
78+
7279
test(function () {
7380
$generator = new LinkGenerator(new Routers\SimpleRouter, new Http\Url('http://nette.org/en/'));
7481
Assert::same('http://nette.org/en/?action=default&presenter=Homepage', $generator->link('Homepage:default'));

0 commit comments

Comments
 (0)