44
55use Codeception \TestCase \Test ;
66use Nette \Application \Application ;
7+ use Nette \Application \UI \Presenter ;
78use Tests \Functional \Fixtures \Article ;
89
910/**
@@ -17,36 +18,127 @@ class RequestEntityLoaderTest extends Test
1718 */
1819 public function testUntyped ()
1920 {
20- $ this ->tester ->amOnPage ('/untyped/5 ' );
21+ $ this ->tester ->amOnPage ('/untyped?parameter=5 ' );
22+ }
23+
24+ public function testEntity ()
25+ {
26+ $ this ->tester ->amOnPage ('/entity?parameter=5 ' );
27+ $ presenter = $ this ->tester ->grabService (Application::class)->getPresenter ();
28+ self ::assertInstanceOf (Presenter::class, $ presenter );
29+ $ request = $ presenter ->getRequest ();
30+ self ::assertEquals (
31+ [
32+ 'action ' => 'entity ' ,
33+ 'parameter ' => new Article (5 ),
34+ ],
35+ $ request ->getParameters ()
36+ );
2137 }
2238
2339 public function testInt ()
2440 {
25- $ this ->tester ->amOnPage ('/int/5 ' );
26- $ request = $ this ->tester ->grabService (Application::class)->getPresenter ()->getRequest ();
27- $ this ->assertSame ([
28- 'action ' => 'int ' ,
29- 'parameter ' => 5 ,
30- ], $ request ->getParameters ());
41+ $ this ->tester ->amOnPage ('/int?parameter=5 ' );
42+ $ presenter = $ this ->tester ->grabService (Application::class)->getPresenter ();
43+ self ::assertInstanceOf (Presenter::class, $ presenter );
44+ $ request = $ presenter ->getRequest ();
45+ self ::assertSame (
46+ [
47+ 'action ' => 'int ' ,
48+ 'parameter ' => 5 ,
49+ ],
50+ $ request ->getParameters ()
51+ );
3152 }
3253
3354 public function testIntWithDefault ()
3455 {
3556 $ this ->tester ->amOnPage ('/int ' );
36- $ request = $ this ->tester ->grabService (Application::class)->getPresenter ()->getRequest ();
37- $ this ->assertSame ([
38- 'action ' => 'int ' ,
39- 'parameter ' => null ,
40- ], $ request ->getParameters ());
57+ $ presenter = $ this ->tester ->grabService (Application::class)->getPresenter ();
58+ self ::assertInstanceOf (Presenter::class, $ presenter );
59+ $ request = $ presenter ->getRequest ();
60+ self ::assertSame (
61+ [
62+ 'action ' => 'int ' ,
63+ ],
64+ $ request ->getParameters ()
65+ );
4166 }
4267
43- public function testEntity ()
68+ /**
69+ * @expectedException Nette\Application\BadRequestException
70+ */
71+ public function testIntError ()
72+ {
73+ $ this ->tester ->amOnPage ('/int?parameter[]=0 ' );
74+ }
75+
76+ public function testBool ()
77+ {
78+ $ this ->tester ->amOnPage ('/bool?parameter=1 ' );
79+ $ presenter = $ this ->tester ->grabService (Application::class)->getPresenter ();
80+ self ::assertInstanceOf (Presenter::class, $ presenter );
81+ $ request = $ presenter ->getRequest ();
82+ self ::assertSame (
83+ [
84+ 'action ' => 'bool ' ,
85+ 'parameter ' => true ,
86+ ],
87+ $ request ->getParameters ()
88+ );
89+ }
90+
91+ /**
92+ * @expectedException Nette\Application\BadRequestException
93+ */
94+ public function testBoolError ()
95+ {
96+ $ this ->tester ->amOnPage ('/bool?parameter[]=0 ' );
97+ }
98+
99+ public function testFloat ()
100+ {
101+ $ this ->tester ->amOnPage ('/float?parameter=1 ' );
102+ $ presenter = $ this ->tester ->grabService (Application::class)->getPresenter ();
103+ self ::assertInstanceOf (Presenter::class, $ presenter );
104+ $ request = $ presenter ->getRequest ();
105+ self ::assertSame (
106+ [
107+ 'action ' => 'float ' ,
108+ 'parameter ' => 1.0 ,
109+ ],
110+ $ request ->getParameters ()
111+ );
112+ }
113+
114+ /**
115+ * @expectedException Nette\Application\BadRequestException
116+ */
117+ public function testFloatError ()
118+ {
119+ $ this ->tester ->amOnPage ('/float?parameter[]=0 ' );
120+ }
121+
122+ public function testString ()
123+ {
124+ $ this ->tester ->amOnPage ('/string?parameter=1 ' );
125+ $ presenter = $ this ->tester ->grabService (Application::class)->getPresenter ();
126+ self ::assertInstanceOf (Presenter::class, $ presenter );
127+ $ request = $ presenter ->getRequest ();
128+ self ::assertSame (
129+ [
130+ 'action ' => 'string ' ,
131+ 'parameter ' => '1 ' ,
132+ ],
133+ $ request ->getParameters ()
134+ );
135+ }
136+
137+ /**
138+ * @expectedException Nette\Application\BadRequestException
139+ */
140+ public function testStringError ()
44141 {
45- $ this ->tester ->amOnPage ('/entity/5 ' );
46- $ request = $ this ->tester ->grabService (Application::class)->getPresenter ()->getRequest ();
47- $ this ->assertEquals ([
48- 'action ' => 'entity ' ,
49- 'parameter ' => new Article (5 ),
50- ], $ request ->getParameters ());
142+ $ this ->tester ->amOnPage ('/string?parameter[]=0 ' );
51143 }
52144}
0 commit comments