Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7f8fc8d

Browse files
ondrejmirtesdg
authored andcommitted
tests: added tests for PresenterComponent:isLinkCurrent()
1 parent 37da191 commit 7f8fc8d

2 files changed

Lines changed: 196 additions & 0 deletions

File tree

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Application\UI\PresenterComponent::isLinkCurrent()
5+
*/
6+
7+
use Nette\Application;
8+
use Nette\Http;
9+
use Tester\Assert;
10+
11+
function callIsLinkCurrent(Application\Request $request, $destination, array $args)
12+
{
13+
$presenter = new TestPresenter;
14+
15+
$url = new Http\UrlScript('http://localhost/index.php');
16+
$url->setScriptPath('/index.php');
17+
18+
$presenter->injectPrimary(
19+
NULL,
20+
new MockPresenterFactory,
21+
new Application\Routers\SimpleRouter,
22+
new Http\Request($url),
23+
new Http\Response
24+
);
25+
$presenter->run($request);
26+
27+
return $presenter->isLinkCurrent($destination, $args);
28+
}
29+
30+
Assert::true(callIsLinkCurrent(
31+
new Application\Request('Test', Http\Request::GET, array()),
32+
'Test:default',
33+
array()
34+
));
35+
36+
Assert::true(callIsLinkCurrent(
37+
new Application\Request('Test', Http\Request::GET, array('int' => 1)),
38+
'Test:default',
39+
array()
40+
));
41+
42+
Assert::false(callIsLinkCurrent(
43+
new Application\Request('Test', Http\Request::GET, array('int' => 1)),
44+
'Test:default',
45+
array('int' => 2)
46+
));
47+
48+
Assert::false(callIsLinkCurrent(
49+
new Application\Request('Test', Http\Request::GET, array(Application\UI\Presenter::ACTION_KEY => 'otherAction')),
50+
'Test:default',
51+
array()
52+
));
53+
54+
Assert::true(callIsLinkCurrent(
55+
new Application\Request('Test', Http\Request::GET, array(Application\UI\Presenter::ACTION_KEY => 'otherAction')),
56+
'Test:otherAction',
57+
array()
58+
));
59+
60+
Assert::true(callIsLinkCurrent(
61+
new Application\Request('Test', Http\Request::GET, array('int' => 1, 'bool' => TRUE)),
62+
'Test:default',
63+
array()
64+
));
65+
66+
Assert::true(callIsLinkCurrent(
67+
new Application\Request('Test', Http\Request::GET, array('int' => 1, 'bool' => TRUE)),
68+
'Test:default',
69+
array('bool' => TRUE)
70+
));
71+
72+
Assert::true(callIsLinkCurrent(
73+
new Application\Request('Test', Http\Request::GET, array('int' => 1, 'bool' => TRUE)),
74+
'Test:default',
75+
array(
76+
'bool' => TRUE,
77+
'int' => 1,
78+
)
79+
));
80+
81+
Assert::false(callIsLinkCurrent(
82+
new Application\Request('Test', Http\Request::GET, array('int' => 1, 'bool' => TRUE)),
83+
'Test:default',
84+
array(
85+
'bool' => FALSE,
86+
'int' => 1,
87+
)
88+
));
89+
90+
Assert::false(callIsLinkCurrent(
91+
new Application\Request('Test', Http\Request::GET, array('int' => 1, 'bool' => TRUE)),
92+
'Test:default',
93+
array(
94+
'bool' => FALSE,
95+
'int' => 2,
96+
)
97+
));
98+
99+
Assert::false(callIsLinkCurrent(
100+
new Application\Request('Test', Http\Request::GET, array('int' => 1, 'bool' => TRUE, Application\UI\Presenter::ACTION_KEY => 'otherAction')),
101+
'Test:default',
102+
array(
103+
'bool' => TRUE,
104+
'int' => 1,
105+
)
106+
));
107+
108+
Assert::true(callIsLinkCurrent(
109+
new Application\Request('Test', Http\Request::GET, array('int' => 1, 'bool' => TRUE, Application\UI\Presenter::ACTION_KEY => 'otherAction')),
110+
'Test:otherAction',
111+
array(
112+
'bool' => TRUE,
113+
'int' => 1,
114+
)
115+
));
116+
117+
Assert::true(callIsLinkCurrent(
118+
new Application\Request('Test', Http\Request::GET, array()),
119+
'Test:*',
120+
array()
121+
));
122+
123+
Assert::true(callIsLinkCurrent(
124+
new Application\Request('Test', Http\Request::GET, array('int' => 1)),
125+
'Test:*',
126+
array()
127+
));
128+
129+
Assert::false(callIsLinkCurrent(
130+
new Application\Request('Test', Http\Request::GET),
131+
'Test:*',
132+
array('int' => 1)
133+
));
134+
135+
Assert::true(callIsLinkCurrent(
136+
new Application\Request('Test', Http\Request::GET, array('int' => 1, Application\UI\Presenter::ACTION_KEY => 'otherAction')),
137+
'Test:*',
138+
array(
139+
'int' => 1,
140+
)
141+
));
142+
143+
Assert::false(callIsLinkCurrent(
144+
new Application\Request('Test', Http\Request::GET, array('int' => 2, Application\UI\Presenter::ACTION_KEY => 'otherAction')),
145+
'Test:*',
146+
array(
147+
'int' => 1,
148+
)
149+
));
150+
151+
Assert::true(callIsLinkCurrent(
152+
new Application\Request('Test', Http\Request::GET, array(Application\UI\Presenter::SIGNAL_KEY => 'signal')),
153+
'Test:default',
154+
array()
155+
));
156+
157+
Assert::true(callIsLinkCurrent(
158+
new Application\Request('Test', Http\Request::GET, array(Application\UI\Presenter::SIGNAL_KEY => 'signal')),
159+
'signal!',
160+
array()
161+
));
162+
163+
Assert::false(callIsLinkCurrent(
164+
new Application\Request('Test', Http\Request::GET, array(Application\UI\Presenter::SIGNAL_KEY => 'signal')),
165+
'otherSignal!',
166+
array()
167+
));
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Application\UI\PresenterComponent::isLinkCurrent()
5+
*/
6+
7+
use Nette\Application;
8+
9+
require __DIR__ . '/../bootstrap.php';
10+
require __DIR__ . '/MockPresenterFactory.php';
11+
12+
class TestPresenter extends Application\UI\Presenter
13+
{
14+
15+
public function actionDefault($int, $bool)
16+
{
17+
}
18+
19+
public function handleSignal()
20+
{
21+
}
22+
23+
public function handleOtherSignal()
24+
{
25+
}
26+
27+
}
28+
29+
require __DIR__ . '/PresenterComponent.isLinkCurrent().asserts.php';

0 commit comments

Comments
 (0)