Skip to content

Commit d9b6a39

Browse files
committed
tests: added test
1 parent ed87b1a commit d9b6a39

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

tests/Application/Presenter.link().phpt

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,21 @@ class TestPresenter extends Application\UI\Presenter
114114
Assert::same('/index.php?sort%5By%5D%5Basc%5D=1&action=default&presenter=Test', $this->link('this', ['sort' => ['y' => ['asc' => TRUE]]]));
115115

116116
// Presenter & signal link type checking
117+
Assert::same("#error: Invalid value for parameter 'x' in method TestPresenter::handlebuy(), expected integer.", $this->link('buy!', 'x'));
118+
Assert::same("#error: Invalid value for parameter 'bool' in method TestPresenter::handlebuy(), expected boolean.", $this->link('buy!', 1, 2, 3));
117119
Assert::same("#error: Invalid value for parameter 'x' in method TestPresenter::handlebuy(), expected integer.", $this->link('buy!', [[]]));
120+
Assert::same('/index.php?action=default&do=buy&presenter=Test', $this->link('buy!'));
118121
Assert::same('/index.php?action=default&do=buy&presenter=Test', $this->link('buy!', [new stdClass]));
119122

123+
Assert::same('/index.php?a=x&action=default&do=obj&presenter=Test', $this->link('obj!', ['x']));
124+
Assert::same('/index.php?action=default&do=obj&presenter=Test', $this->link('obj!', [new stdClass]));
125+
Assert::same('/index.php?action=default&do=obj&presenter=Test', $this->link('obj!', [new Exception]));
126+
Assert::same('/index.php?action=default&do=obj&presenter=Test', $this->link('obj!', [NULL]));
127+
Assert::same('/index.php?b=x&action=default&do=obj&presenter=Test', $this->link('obj!', ['b' => 'x']));
128+
Assert::same('/index.php?action=default&do=obj&presenter=Test', $this->link('obj!', ['b' => new stdClass]));
129+
Assert::same('/index.php?action=default&do=obj&presenter=Test', $this->link('obj!', ['b' => new Exception]));
130+
Assert::same('/index.php?action=default&do=obj&presenter=Test', $this->link('obj!', ['b' => NULL]));
131+
120132
// Component link
121133
Assert::same('#error: Signal must be non-empty string.', $this['mycontrol']->link('', 0, 1));
122134
Assert::same('/index.php?mycontrol-x=0&mycontrol-y=1&action=default&do=mycontrol-click&presenter=Test', $this['mycontrol']->link('click', 0, 1));
@@ -155,16 +167,21 @@ class TestPresenter extends Application\UI\Presenter
155167
Assert::exception(function () {
156168
$this->link('product', ['var1' => NULL, 'ok' => 'a']);
157169
}, Nette\Application\UI\InvalidLinkException::class, "Invalid value for persistent parameter 'ok' in 'Test', expected boolean.");
170+
171+
$this->var1 = NULL; // NULL in persistent parameter means default
172+
Assert::same('/index.php?action=product&presenter=Test', $this->link('product'));
158173
}
159174

160175

161-
/**
162-
* @view: default
163-
*/
164176
public function handleBuy($x = 1, $y = 1, $bool = FALSE, $str = '')
165177
{
166178
}
167179

180+
181+
public function handleObj(stdClass $a, stdClass $b = NULL)
182+
{
183+
}
184+
168185
}
169186

170187

tests/Application/PresenterComponentReflection.convertType.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ use Tester\Assert;
1111
require __DIR__ . '/../bootstrap.php';
1212

1313

14+
// [$type] null scalar array object* callable*
15+
// [$val] ----------------------------------------------------------
16+
// null (not used)
17+
// scalar pass cast/deny deny error error
18+
// array deny deny pass deny deny
19+
// object pass pass error pass/error pass/error
20+
//
21+
// error = E_RECOVERABLE_ERROR * = only as native typehint
22+
23+
1424
function testIt($type, $val, $res = NULL)
1525
{
1626
if (func_num_args() === 3) {

0 commit comments

Comments
 (0)