@@ -10,24 +10,26 @@ use Tester\Assert;
1010require __DIR__ . '/../bootstrap.php ' ;
1111
1212
13- $ _COOKIE [Nette \Http \Helpers::StrictCookieName] = '1 ' ;
14- $ _POST = [
15- 'title ' => 'sent title ' ,
16- 'first ' => [
17- 'age ' => '999 ' ,
18- 'second ' => [
19- 'city ' => 'sent city ' ,
13+ setUp (function () {
14+ $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
15+ $ _POST = [
16+ 'title ' => 'sent title ' ,
17+ 'first ' => [
18+ 'age ' => '999 ' ,
19+ 'second ' => [
20+ 'city ' => 'sent city ' ,
21+ ],
2022 ],
21- ],
22- ];
23+ ];
24+ ob_start ();
25+ Form::initialize (true );
26+ });
2327
2428
2529function createForm (): Form
2630{
27- ob_start ();
28- Form::initialize (true );
29-
3031 $ form = new Form ;
32+ $ form ->allowCrossOrigin ();
3133 $ form ->addText ('title ' );
3234
3335 $ first = $ form ->addContainer ('first ' );
@@ -41,6 +43,8 @@ function createForm(): Form
4143
4244
4345test ('setting form defaults and retrieving array values ' , function () {
46+ $ _SERVER ['REQUEST_METHOD ' ] = 'GET ' ;
47+
4448 $ form = createForm ();
4549 Assert::false ($ form ->isSubmitted ());
4650
@@ -70,8 +74,6 @@ test('setting form defaults and retrieving array values', function () {
7074
7175
7276test ('handles POST submission with nested data ' , function () {
73- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
74-
7577 $ form = createForm ();
7678 Assert::truthy ($ form ->isSubmitted ());
7779 Assert::equal ([
@@ -88,8 +90,6 @@ test('handles POST submission with nested data', function () {
8890
8991
9092test ('resetting form clears submitted values ' , function () {
91- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
92-
9393 $ form = createForm ();
9494 Assert::truthy ($ form ->isSubmitted ());
9595
@@ -110,8 +110,6 @@ test('resetting form clears submitted values', function () {
110110
111111
112112test ('setting form values with erase option ' , function () {
113- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
114-
115113 $ form = createForm ();
116114 Assert::truthy ($ form ->isSubmitted ());
117115
@@ -155,8 +153,6 @@ test('setting form values with erase option', function () {
155153
156154
157155test ('updating form values without erasing ' , function () {
158- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
159-
160156 $ form = createForm ();
161157
162158 Assert::truthy ($ form ->isSubmitted ());
@@ -182,8 +178,6 @@ test('updating form values without erasing', function () {
182178
183179
184180test ('using array as mapped type for form values ' , function () {
185- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
186-
187181 $ form = createForm ();
188182 $ form ->setMappedType ('array ' );
189183
@@ -210,8 +204,6 @@ test('using array as mapped type for form values', function () {
210204
211205
212206test ('triggering onSuccess with correct value types ' , function () {
213- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
214-
215207 $ form = createForm ();
216208 $ form ->onSuccess [] = function (Form $ form , array $ values ) {
217209 Assert::same ([
@@ -263,7 +255,6 @@ test('triggering onSuccess with correct value types', function () {
263255
264256
265257test ('validation scope limits submitted data ' , function () {
266- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
267258 $ _POST ['send ' ] = '' ;
268259
269260 $ form = createForm ();
@@ -281,7 +272,6 @@ test('validation scope limits submitted data', function () {
281272
282273
283274test ('validation scope applied to container ' , function () {
284- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
285275 $ _POST ['send ' ] = '' ;
286276
287277 $ form = createForm ();
@@ -298,7 +288,6 @@ test('validation scope applied to container', function () {
298288});
299289
300290test ('validation scope on nested container fields ' , function () {
301- $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
302291 $ _POST ['send ' ] = '' ;
303292
304293 $ form = createForm ();
0 commit comments