Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Form] Add upgrade path for empty_data option in TextType#41516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
peter-gribanov wants to merge10 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
frompeter-gribanov:form_text_type_stringable_upgrade
Open
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
fix tests
  • Loading branch information
Peter Gribanov committedSep 27, 2022
commitfa0328d2f94ff11e664a25eea0876872cf80516c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2805,6 +2805,7 @@ public function trans(TranslatorInterface $translator, string $locale = null): s
};

$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, [
'empty_data' => null,
'help' => $message,
]);
$html = $this->renderHelp($form->createView());
Expand Down
20 changes: 15 additions & 5 deletionssrc/Symfony/Component/Form/Tests/CompoundFormTest.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -205,7 +205,9 @@ public function testAdd()

public function testAddUsingNameAndType()
{
$this->form->add('foo', TextType::class);
$this->form->add('foo', TextType::class, [
'empty_data' => null,
]);

$this->assertTrue($this->form->has('foo'));

Expand All@@ -218,7 +220,9 @@ public function testAddUsingNameAndType()
public function testAddUsingIntegerNameAndType()
{
// in order to make casting unnecessary
$this->form->add(0, TextType::class);
$this->form->add(0, TextType::class, [
'empty_data' => null,
]);

$this->assertTrue($this->form->has(0));

Expand All@@ -230,7 +234,9 @@ public function testAddUsingIntegerNameAndType()

public function testAddWithoutType()
{
$this->form->add('foo');
$this->form->add('foo', null, [
'empty_data' => null,
]);

$this->assertTrue($this->form->has('foo'));

Expand All@@ -247,7 +253,9 @@ public function testAddUsingNameButNoType()
->setDataMapper(new DataMapper())
->getForm();

$this->form->add('foo');
$this->form->add('foo', null, [
'empty_data' => null,
]);

$this->assertTrue($this->form->has('foo'));

Expand All@@ -264,7 +272,9 @@ public function testAddUsingNameButNoTypeAndOptions()
->setDataMapper(new DataMapper())
->getForm();

$this->form->add('foo');
$this->form->add('foo', null, [
'empty_data' => null,
]);

$this->assertTrue($this->form->has('foo'));

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -424,6 +424,7 @@ public function testPrototypeOptionsOverrideEntryOptions()
],
'prototype_options' => [
'help' => 'foo',
'empty_data' => null,
],
]);

Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -45,15 +45,22 @@ protected function getExtensions()
public function testSanitizer()
{
$form = $this->factory->createBuilder(FormType::class, ['data' => null])
->add('data', TextType::class, ['sanitize_html' => true])
->add('data', TextType::class, [
'empty_data' => null,
'sanitize_html' => true,
])
->getForm()
;
$form->submit(['data' => 'foobar']);

$this->assertSame(['data' => 'foo'], $form->getData());

$form = $this->factory->createBuilder(FormType::class, ['data' => null])
->add('data', TextType::class, ['sanitize_html' => true, 'sanitizer' => 'bar'])
->add('data', TextType::class, [
'empty_data' => null,
'sanitize_html' => true,
'sanitizer' => 'bar',
])
->getForm()
;
$form->submit(['data' => 'foobar']);
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -347,7 +347,9 @@ public function testCascadeValidationToArrayChildForm()
$form = $this->formFactory->create(FormType::class, null, [
'data_class' => Review::class,
])
->add('title')
->add('title', null, [
'empty_data' => null,
])
->add('customers', CollectionType::class, [
'mapped' => false,
'entry_type' => CustomerType::class,
Expand Down
12 changes: 9 additions & 3 deletionssrc/Symfony/Component/Form/Tests/FormBuilderTest.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -142,7 +142,9 @@ public function testRemoveAndGetForm()

public function testCreateNoTypeNo()
{
$builder = $this->builder->create('foo');
$builder = $this->builder->create('foo', null, [
'empty_data' => null,
]);

$this->assertInstanceOf(TextType::class, $builder->getType()->getInnerType());
}
Expand All@@ -165,7 +167,9 @@ public function testGetUnknown()

public function testGetExplicitType()
{
$this->builder->add('foo', 'Symfony\Component\Form\Extension\Core\Type\TextType');
$this->builder->add('foo', 'Symfony\Component\Form\Extension\Core\Type\TextType', [
'empty_data' => null,
]);
$builder = $this->builder->get('foo');

$this->assertNotSame($builder, $this->builder);
Expand All@@ -174,7 +178,9 @@ public function testGetExplicitType()
public function testGetGuessedType()
{
$rootFormBuilder = new FormBuilder('name', 'stdClass', new EventDispatcher(), $this->factory);
$rootFormBuilder->add('foo');
$rootFormBuilder->add('foo', null, [
'empty_data' => null,
]);
$fooBuilder = $rootFormBuilder->get('foo');

$this->assertNotSame($fooBuilder, $rootFormBuilder);
Expand Down
34 changes: 26 additions & 8 deletionssrc/Symfony/Component/Form/Tests/FormFactoryTest.php
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -102,7 +102,9 @@ public function testCreateNamed()

public function testCreateBuilderForPropertyWithoutTypeGuesser()
{
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
]);

$this->assertSame('firstName', $builder->getName());
}
Expand All@@ -112,7 +114,9 @@ public function testCreateBuilderForPropertyCreatesFormWithHighestConfidence()
$this->guesser1->configureTypeGuess(TextType::class, ['attr' => ['maxlength' => 10]], Guess::MEDIUM_CONFIDENCE);
$this->guesser2->configureTypeGuess(PasswordType::class, ['attr' => ['maxlength' => 7]], Guess::HIGH_CONFIDENCE);

$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
]);

$this->assertSame('firstName', $builder->getName());
$this->assertSame(['maxlength' => 7], $builder->getOption('attr'));
Expand All@@ -121,7 +125,9 @@ public function testCreateBuilderForPropertyCreatesFormWithHighestConfidence()

public function testCreateBuilderCreatesTextFormIfNoGuess()
{
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
]);

$this->assertSame('firstName', $builder->getName());
$this->assertInstanceOf(TextType::class, $builder->getType()->getInnerType());
Expand All@@ -131,7 +137,10 @@ public function testOptionsCanBeOverridden()
{
$this->guesser1->configureTypeGuess(TextType::class, ['attr' => ['class' => 'foo', 'maxlength' => 10]], Guess::MEDIUM_CONFIDENCE);

$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, ['attr' => ['maxlength' => 11]]);
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
'attr' => ['maxlength' => 11],
]);

$this->assertSame('firstName', $builder->getName());
$this->assertSame(['class' => 'foo', 'maxlength' => 11], $builder->getOption('attr'));
Expand All@@ -143,7 +152,9 @@ public function testCreateBuilderUsesMaxLengthIfFound()
$this->guesser1->configureMaxLengthGuess(15, Guess::MEDIUM_CONFIDENCE);
$this->guesser2->configureMaxLengthGuess(20, Guess::HIGH_CONFIDENCE);

$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
]);

$this->assertSame('firstName', $builder->getName());
$this->assertSame(['maxlength' => 20], $builder->getOption('attr'));
Expand All@@ -155,7 +166,10 @@ public function testCreateBuilderUsesMaxLengthAndPattern()
$this->guesser1->configureMaxLengthGuess(20, Guess::HIGH_CONFIDENCE);
$this->guesser2->configurePatternGuess('.{5,}', Guess::HIGH_CONFIDENCE);

$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, ['attr' => ['class' => 'tinymce']]);
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
'attr' => ['class' => 'tinymce']
]);

$this->assertSame('firstName', $builder->getName());
$this->assertSame(['maxlength' => 20, 'pattern' => '.{5,}', 'class' => 'tinymce'], $builder->getOption('attr'));
Expand All@@ -167,7 +181,9 @@ public function testCreateBuilderUsesRequiredSettingWithHighestConfidence()
$this->guesser1->configureRequiredGuess(true, Guess::MEDIUM_CONFIDENCE);
$this->guesser2->configureRequiredGuess(false, Guess::HIGH_CONFIDENCE);

$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
]);

$this->assertSame('firstName', $builder->getName());
$this->assertFalse($builder->getOption('required'));
Expand All@@ -179,7 +195,9 @@ public function testCreateBuilderUsesPatternIfFound()
$this->guesser1->configurePatternGuess('[a-z]', Guess::MEDIUM_CONFIDENCE);
$this->guesser2->configurePatternGuess('[a-zA-Z]', Guess::HIGH_CONFIDENCE);

$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName');
$builder = $this->factory->createBuilderForProperty('Application\Author', 'firstName', null, [
'empty_data' => null,
]);

$this->assertSame('firstName', $builder->getName());
$this->assertSame(['pattern' => '[a-zA-Z]'], $builder->getOption('attr'));
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp