-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PresenterComponentReflection::convertType() support for all PHP typeh…
…ints
- Loading branch information
Showing
5 changed files
with
180 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Application\UI\Presenter::link() | ||
* @phpVersion 7 | ||
*/ | ||
|
||
use Nette\Http; | ||
use Nette\Application; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
class TestPresenter extends Application\UI\Presenter | ||
{ | ||
/** @persistent */ | ||
public $var1 = 10; | ||
|
||
|
||
protected function createTemplate($class = NULL) | ||
{ | ||
} | ||
|
||
|
||
protected function startup() | ||
{ | ||
parent::startup(); | ||
$this->invalidLinkMode = self::INVALID_LINK_TEXTUAL; | ||
|
||
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', ['var1' => $this->var1])); | ||
Assert::same('/index.php?var1=20&action=default&do=hint&presenter=Test', $this->link('hint!', ['var1' => $this->var1 * 2])); | ||
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', 1, 2)); | ||
Assert::same('/index.php?y=2&bool=1&str=1&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', TRUE, TRUE)); | ||
Assert::same('/index.php?y=2&str=0&action=default&do=hint&presenter=Test', $this->link('hint!', '1', '2', FALSE, FALSE)); | ||
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!', [1])); | ||
Assert::same("#error: Invalid value for parameter 'x' in method TestPresenter::handlehint(), expected int.", $this->link('hint!', [1], (object) [1])); | ||
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', [1, 'y' => 2])); | ||
Assert::same('/index.php?y=2&action=default&do=hint&presenter=Test', $this->link('hint!', ['x' => 1, 'y' => 2, 'var1' => $this->var1])); | ||
Assert::same('#error: Signal must be non-empty string.', $this->link('!')); | ||
Assert::same('/index.php?action=default&presenter=Test', $this->link('this', ['var1' => $this->var1])); | ||
Assert::same('/index.php?action=default&presenter=Test', $this->link('this!', ['var1' => $this->var1])); | ||
Assert::same('/index.php?sort%5By%5D%5Basc%5D=1&action=default&presenter=Test', $this->link('this', ['sort' => ['y' => ['asc' => TRUE]]])); | ||
|
||
// Presenter & signal link type checking | ||
Assert::same("#error: Invalid value for parameter 'x' in method TestPresenter::handlehint(), expected int.", $this->link('hint!', 'x')); | ||
Assert::same("#error: Invalid value for parameter 'bool' in method TestPresenter::handlehint(), expected bool.", $this->link('hint!', 1, 2, 3)); | ||
Assert::same("#error: Invalid value for parameter 'x' in method TestPresenter::handlehint(), expected int.", $this->link('hint!', [[]])); | ||
Assert::same('/index.php?action=default&do=hint&presenter=Test', $this->link('hint!')); | ||
Assert::same("#error: Invalid value for parameter 'x' in method TestPresenter::handlehint(), expected int.", $this->link('hint!', [new stdClass])); | ||
} | ||
|
||
|
||
public function handleHint(int $x = 1, int $y, bool $bool, string $str) | ||
{ | ||
} | ||
|
||
} | ||
|
||
|
||
class MockPresenterFactory extends Nette\Object implements Nette\Application\IPresenterFactory | ||
{ | ||
function getPresenterClass(& $name) | ||
{ | ||
return str_replace(':', 'Module\\', $name) . 'Presenter'; | ||
} | ||
|
||
function createPresenter($name) | ||
{} | ||
} | ||
|
||
|
||
$url = new Http\UrlScript('http://localhost/index.php'); | ||
$url->setScriptPath('/index.php'); | ||
|
||
$presenter = new TestPresenter; | ||
$presenter->injectPrimary( | ||
NULL, | ||
new MockPresenterFactory, | ||
new Application\Routers\SimpleRouter, | ||
new Http\Request($url), | ||
new Http\Response | ||
); | ||
|
||
$presenter->invalidLinkMode = TestPresenter::INVALID_LINK_WARNING; | ||
$presenter->autoCanonicalize = FALSE; | ||
|
||
$request = new Application\Request('Test', Http\Request::GET, []); | ||
$presenter->run($request); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters