11
11
12
12
namespace Symfony \Component \Form \Tests \Extension \Core \Type ;
13
<
8000
/td>13
14
+ use Symfony \Bridge \PhpUnit \ExpectDeprecationTrait ;
14
15
use Symfony \Component \OptionsResolver \Exception \InvalidOptionsException ;
15
16
16
17
class UrlTypeTest extends TextTypeTest
17
18
{
19
+ use ExpectDeprecationTrait;
20
+
18
21
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\UrlType ' ;
19
22
23
+ /**
24
+ * @group legacy
25
+ */
20
26
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded ()
21
27
{
28
+ $ this ->expectDeprecation ('Since symfony/form 6.4: Not configuring the "default_protocol" option is deprecated. It will default to "null" in 7.0. ' );
22
29
$ form = $ this ->factory ->create (static ::TESTED_TYPE , 'name ' );
23
30
24
31
$ form ->submit ('www.domain.com ' );
@@ -86,6 +93,7 @@ public function testThrowExceptionIfDefaultProtocolIsInvalid()
86
93
public function testSubmitNullUsesDefaultEmptyData ($ emptyData = 'empty ' , $ expectedData = 'http://empty ' )
87
94
{
88
95
$ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
96
+ 'default_protocol ' => 'http ' , // TODO: remove in 7.0
89
97
'empty_data ' => $ emptyData ,
90
98
]);
91
99
$ form ->submit (null );
@@ -95,4 +103,47 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expect
95
103
$ this ->assertSame ($ expectedData , $ form ->getNormData ());
96
104
$ this ->assertSame ($ expectedData , $ form ->getData ());
97
105
}
106
+
107
+ /**
108
+ * @todo remove in 7.0
109
+ */
110
+ public function testSubmitNullReturnsNullWithEmptyDataAsString ()
111
+ {
112
+ $ form = $ this ->factory ->create (static ::TESTED_TYPE , 'name ' , [
113
+ 'default_protocol ' => 'http ' ,
114
+ 'empty_data ' => '' ,
115
+ ]);
116
+
117
+ $ form ->submit (null );
118
+ $ this ->assertSame ('' , $ form ->getData ());
119
+ $ this ->assertSame ('' , $ form ->getNormData ());
120
+ $ this ->assertSame ('' , $ form ->getViewData ());
121
+ }
122
+
123
+ /**
124
+ * @dataProvider provideZeros
125
+ *
126
+ * @todo remove in 7.0
127
+ */
128
+ public function testSetDataThroughParamsWithZero ($ data , $ dataAsString )
129
+ {
130
+ $ form = $ this ->factory ->create (static ::TESTED_TYPE , null , [
131
+ 'data ' => $ data ,
132
+ 'default_protocol ' => 'http ' ,
133
+ ]);
134
+ $ view = $ form ->createView ();
135
+
136
+ $ this ->assertFalse ($ form ->isEmpty ());
137
+
138
+ $ this ->assertSame ($ dataAsString , $ view ->vars ['value ' ]);
139
+ $ this ->assertSame ($ dataAsString , $ form ->getData ());
140
+ }
141
+
142
+ /**
143
+ * @todo remove in 7.0
144
+ */
145
+ protected function getTestOptions (): array
146
+ {
147
+ return ['default_protocol ' => 'http ' ];
148
+ }
98
149
}
0 commit comments