8000 Update tests · symfony/symfony@cb28233 · GitHub
[go: up one dir, main page]

Skip to content

Commit cb28233

Browse files
committed
Update tests
1 parent 881d0d9 commit cb28233

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

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

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

1212
namespace Symfony\Component\Form\Test 8000 s\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< 8000 div class="diff-text-inner">
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,44 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expect
95106
$this->assertSame($expectedData, $form->getNormData());
96107
$this->assertSame($expectedData, $form->getData());
97108
}
109+
110+
public function testSubmitNullReturnsNullWithEmptyDataAsString()
111+
{
112+
$form = $this->factory->create(static::TESTED_TYPE, 'name', [
113+
'default_protocol' => 'http', // TODO: remove in 7.0
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+
}
98149
}

src/Symfony/Component/Form/Tests/Extension/Validator/Type/UrlTypeValidatorExtensionTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class UrlTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
2020

2121
protected function createForm(array $options = [])
2222
{
23-
return $this->factory->create(UrlType::class, null, $options);
23+
// TODO: remove default_protocol option in 7.0
24+
return $this->factory->create(UrlType::class, null, $options + ['default_protocol' => 'http']);
2425
}
2526

2627
public function testInvalidMessage()

0 commit comments

Comments
 (0)
0