Skip to content

Commit cbe7ab3

Browse files
committed
Update tests
1 parent df4dc28 commit cbe7ab3

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/Symfony/Component/Form/Tests/Extension/Core/Type/UrlTypeTest.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,21 @@
1111

1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

14+
use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait;
1415
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
1516

1617
class UrlTypeTest extends TextTypeTest
1718
{
19+
use ExpectDeprecationTrait;
20+
1821
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\UrlType';
1922

23+
/**
24+
* @group legacy
25+
*/
2026
public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
2127
{
28+
$this->expectDeprecation('Since symfony/form 6.4: Not configuring the "default_protocol" option is deprecated. It will default to "null" in 7.0.');
2229
$form = $this->factory->create(static::TESTED_TYPE, 'name');
2330

2431
$form->submit('www.domain.com');
@@ -83,9 +90,13 @@ public function testThrowExceptionIfDefaultProtocolIsInvalid()
8390
]);
8491
}
8592

93+
/**
94+
* @todo remove in 7.0
95+
*/
8696
public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = 'http://empty')
8797
{
8898
$form = $this->factory->create(static::TESTED_TYPE, null, [
99+
'default_protocol' => 'http',
89100
'empty_data' => $emptyData,
90101
]);
91102
$form->submit(null);
@@ -95,4 +106,48 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expect
95106
$this->assertSame($expectedData, $form->getNormData());
96107
$this->assertSame($expectedData, $form->getData());
97108
}
109+
110+
/**
111+
* @todo remove in 7.0
112+
*/
113+
public function testSubmitNullReturnsNullWithEmptyDataAsString()
114+
{
115+
$form = $this->factory->create(static::TESTED_TYPE, 'name', [
116+
'default_protocol' => 'http',
117+
'empty_data' => '',
118+
]);
119+
120+
$form->submit(null);
121+
$this->assertSame('', $form->getData());
122+
$this->assertSame('', $form->getNormData());
123+
$this->assertSame('', $form->getViewData());
124+
}
125+
126+
/**
127+
* @dataProvider provideZeros
128+
*
129+
* @todo remove in 7.0
130+
*/
131+
public function testSetDataThroughParamsWithZero($data, $dataAsString)
132+
{
133+
$form = $this->factory->create(static::TESTED_TYPE, null, [
134+
'data' => $data,
135+
'default_protocol' => 'http',
136+
]);
137+
$view = $form->createView();
138+
139+
$this->assertFalse($form->isEmpty());
140+
141+
$this->assertSame($dataAsString, $view->vars['value']);
142+
$this->assertSame($dataAsString, $form->getData());
143+
}
144+
145+
146+
/**
147+
* @todo remove in 7.0
148+
*/
149+
protected function getTestOptions(): array
150+
{
151+
return ['default_protocol' => 'http'];
152+
}
98153
}

0 commit comments

Comments
 (0)