Skip to content

Commit d47468f

Browse files
committed
tests: improvements
1 parent b4b2647 commit d47468f

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

tests/UI/Presenter.link().php7.phpt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class TestPresenter extends Application\UI\Presenter
1818
/** @persistent */
1919
public $var1 = 10;
2020

21+
/** @persistent */
22+
public $var2;
23+
2124

2225
protected function createTemplate($class = NULL)
2326
{
@@ -33,7 +36,8 @@ class TestPresenter extends Application\UI\Presenter
3336
Assert::same('/index.php?var1=20&action=default&do=hint&presenter=Test', $this->link('hint!', ['var1' => $this->var1 * 2]));
3437
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', 1, 2));
3538
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', TRUE, TRUE));
36-
Assert::same('/index.php?y=2&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', FALSE, FALSE));
39+
Assert::same('/index.php?y=0&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', 0, FALSE, FALSE));
40+
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', ['str' => '', 'var2' => '']));
3741
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', [1]));
3842
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, array given.', $this->link('hint!', [1], (object) [1]));
3943
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', [1, 'y' => 2]));
@@ -43,19 +47,38 @@ class TestPresenter extends Application\UI\Presenter
4347
Assert::same('/index.php?action=default&presenter=Test', $this->link('this!', ['var1' => $this->var1]));
4448
Assert::same('/index.php?sort%5By%5D%5Basc%5D=1&action=default&presenter=Test', $this->link('this', ['sort' => ['y' => ['asc' => TRUE]]]));
4549

46-
// Presenter & signal link type checking
50+
// type checking
4751
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, string given.', $this->link('hint!', 'x'));
4852
Assert::same('#error: Argument $bool passed to TestPresenter::handleHint() must be bool, integer given.', $this->link('hint!', 1, 2, 3));
4953
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, array given.', $this->link('hint!', [[]]));
5054
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!'));
5155
Assert::same('#error: Argument $x passed to TestPresenter::handleHint() must be int, stdClass given.', $this->link('hint!', [new stdClass]));
56+
57+
// optional arguments
58+
Assert::same('/index.php?y=2&action=default&do=null&presenter=Test', $this->link('null!', 1, 2));
59+
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=null&presenter=Test', $this->link('null!', '1', '2', TRUE, TRUE));
60+
Assert::same('/index.php?y=0&str=0&action=default&do=null&presenter=Test', $this->link('null!', '1', 0, FALSE, FALSE));
61+
Assert::same('/index.php?action=default&do=null&presenter=Test', $this->link('null!', ['str' => '', 'var2' => '']));
62+
Assert::same('/index.php?action=default&do=null&presenter=Test', $this->link('null!', [1]));
63+
Assert::same('#error: Argument $x passed to TestPresenter::handleNull() must be int, array given.', $this->link('null!', [1], (object) [1]));
64+
Assert::same('/index.php?y=2&action=default&do=null&presenter=Test', $this->link('null!', [1, 'y' => 2]));
65+
Assert::same('/index.php?y=2&action=default&do=null&presenter=Test', $this->link('null!', ['x' => 1, 'y' => 2, 'var1' => $this->var1]));
66+
Assert::same('#error: Argument $bool passed to TestPresenter::handleNull() must be bool, integer given.', $this->link('null!', 1, 2, 3));
67+
Assert::same('#error: Argument $x passed to TestPresenter::handleNull() must be int, array given.', $this->link('null!', [[]]));
68+
Assert::same('/index.php?action=default&do=null&presenter=Test', $this->link('null!'));
69+
Assert::same('#error: Argument $x passed to TestPresenter::handleNull() must be int, stdClass given.', $this->link('null!', [new stdClass]));
5270
}
5371

5472

5573
public function handleHint(int $x = 1, int $y, bool $bool, string $str)
5674
{
5775
}
5876

77+
78+
public function handleNull(int $x = 1, int $y = NULL, bool $bool = NULL, string $str = NULL)
79+
{
80+
}
81+
5982
}
6083

6184

tests/UI/Presenter.link().phpt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class TestPresenter extends Application\UI\Presenter
6161
/** @persistent */
6262
public $var1 = 10;
6363

64-
/** @persistent @var bool */
64+
/** @persistent */
6565
public $ok = TRUE;
6666

67-
/** @persistent @var bool */
68-
public $var2 = FALSE;
67+
/** @persistent */
68+
public $var2;
6969

7070

7171
protected function createTemplate($class = NULL)
@@ -83,6 +83,7 @@ class TestPresenter extends Application\UI\Presenter
8383
Assert::same('/index.php?action=product&presenter=Test', $this->link('product', ['var1' => $this->var1]));
8484
Assert::same('/index.php?var1=20&action=product&presenter=Test', $this->link('product', ['var1' => $this->var1 * 2, 'ok' => TRUE]));
8585
Assert::same('/index.php?var1=1&ok=0&action=product&presenter=Test', $this->link('product', ['var1' => TRUE, 'ok' => '0']));
86+
Assert::same('/index.php?var1=0&ok=0&action=product&presenter=Test', $this->link('product', ['var1' => FALSE, 'ok' => FALSE, 'var2' => FALSE]));
8687
Assert::same("#error: Value passed to persistent parameter 'ok' in presenter Test must be boolean, string given.", $this->link('product', ['var1' => NULL, 'ok' => 'a']));
8788
Assert::same("#error: Value passed to persistent parameter 'var1' in presenter Test must be integer, array given.", $this->link('product', ['var1' => [1], 'ok' => FALSE]));
8889
Assert::same("#error: Unable to pass parameters to action 'Test:product', missing corresponding method.", $this->link('product', 1, 2));
@@ -103,7 +104,8 @@ class TestPresenter extends Application\UI\Presenter
103104
Assert::same('/index.php?var1=20&action=default&do=buy&presenter=Test', $this->link('buy!', ['var1' => $this->var1 * 2]));
104105
Assert::same('/index.php?y=2&action=default&do=buy&presenter=Test', $this->link('buy!', 1, 2));
105106
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=buy&presenter=Test', $this->link('buy!', '1', '2', TRUE, TRUE));
106-
Assert::same('/index.php?y=2&str=0&action=default&do=buy&presenter=Test', $this->link('buy!', '1', '2', FALSE, FALSE));
107+
Assert::same('/index.php?y=0&str=0&action=default&do=buy&presenter=Test', $this->link('buy!', '1', 0, FALSE, FALSE));
108+
Assert::same('/index.php?action=default&do=buy&presenter=Test', $this->link('buy!', ['str' => '', 'var2' => '']));
107109
Assert::same('/index.php?action=default&do=buy&presenter=Test', $this->link('buy!', [1]));
108110
Assert::same('#error: Argument $x passed to TestPresenter::handleBuy() must be integer, array given.', $this->link('buy!', [1], (object) [1]));
109111
Assert::same('/index.php?y=2&action=default&do=buy&presenter=Test', $this->link('buy!', [1, 'y' => 2]));

0 commit comments

Comments
 (0)