Skip to content

Commit 49987b6

Browse files
Merge branch '3.4' into 4.1
* 3.4: [Validator] Added IBAN format for Vatican City State filter out invalid Intl values [Validator] Fixed grouped composite constraints [Form] Filter arrays out of scalar form types
2 parents 6995262 + 26d4069 commit 49987b6

File tree

12 files changed

+65
-32
lines changed

12 files changed

+65
-32
lines changed

Extension/Core/Type/CountryType.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ public function loadChoicesForValues(array $values, $value = null)
101101
return array();
102102
}
103103

104-
// If no callable is set, values are the same as choices
105-
if (null === $value) {
106-
return $values;
107-
}
108-
109104
return $this->loadChoiceList($value)->getChoicesForValues($values);
110105
}
111106

Extension/Core/Type/CurrencyType.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ public function loadChoicesForValues(array $values, $value = null)
101101
return array();
102102
}
103103

104-
// If no callable is set, values are the same as choices
105-
if (null === $value) {
106-
return $values;
107-
}
108-
109104
return $this->loadChoiceList($value)->getChoicesForValues($values);
110105
}
111106

Extension/Core/Type/LanguageType.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ public function loadChoicesForValues(array $values, $value = null)
101101
return array();
102102
}
103103

104-
// If no callable is set, values are the same as choices
105-
if (null === $value) {
106-
return $values;
107-
}
108-
109104
return $this->loadChoiceList($value)->getChoicesForValues($values);
110105
}
111106

Extension/Core/Type/LocaleType.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,6 @@ public function loadChoicesForValues(array $values, $value = null)
101101
return array();
102102
}
103103

104-
// If no callable is set, values are the same as choices
105-
if (null === $value) {
106-
return $values;
107-
}
108-
109104
return $this->loadChoiceList($value)->getChoicesForValues($values);
110105
}
111106

Form.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,12 @@ public function submit($submittedData, $clearMissing = true)
532532
$submittedData = null;
533533
} elseif (is_scalar($submittedData)) {
534534
$submittedData = (string) $submittedData;
535-
} elseif ($this->config->getOption('allow_file_upload')) {
536-
// no-op
537-
} elseif ($this->config->getRequestHandler()->isFileUpload($submittedData)) {
535+
} elseif (!$this->config->getOption('allow_file_upload') && $this->config->getRequestHandler()->isFileUpload($submittedData)) {
538536
$submittedData = null;
539537
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');
538+
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) {
539+
$submittedData = null;
540+
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.');
540541
}
541542

542543
$dispatcher = $this->config->getEventDispatcher();

Tests/CompoundFormTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,22 @@ public function testDisabledButtonIsNotSubmitted()
10391039
$this->assertFalse($submit->isSubmitted());
10401040
}
10411041

1042+
public function testArrayTransformationFailureOnSubmit()
1043+
{
1044+
$this->form->add($this->getBuilder('foo')->setCompound(false)->getForm());
1045+
$this->form->add($this->getBuilder('bar', null, null, array('multiple' => false))->setCompound(false)->getForm());
1046+
1047+
$this->form->submit(array(
1048+
'foo' => array('foo'),
1049+
'bar' => array('bar'),
1050+
));
1051+
1052+
$this->assertNull($this->form->get('foo')->getData());
1053+
$this->assertSame('Submitted data was expected to be text or number, array given.', $this->form->get('foo')->getTransformationFailure()->getMessage());
1054+
1055+
$this->assertSame(array('bar'), $this->form->get('bar')->getData());
1056+
}
1057+
10421058
public function testFileUpload()
10431059
{
10441060
$reqHandler = new HttpFoundationRequestHandler();

Tests/Extension/Core/Type/CountryTypeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
15+
use Symfony\Component\Form\Extension\Core\Type\CountryType;
1516
use Symfony\Component\Intl\Util\IntlTestHelper;
1617

1718
class CountryTypeTest extends BaseTypeTest
@@ -80,4 +81,14 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'FR', $expectedD
8081
{
8182
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
8283
}
84+
85+
/**
86+
* @group legacy
87+
*/
88+
public function testInvalidChoiceValuesAreDropped()
89+
{
90+
$type = new CountryType();
91+
92+
$this->assertSame(array(), $type->loadChoicesForValues(array('foo')));
93+
}
8394
}

Tests/Extension/Core/Type/CurrencyTypeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
15+
use Symfony\Component\Form\Extension\Core\Type\CurrencyType;
1516
use Symfony\Component\Intl\Util\IntlTestHelper;
1617

1718
class CurrencyTypeTest extends BaseTypeTest
@@ -61,4 +62,14 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'EUR', $expected
6162
{
6263
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
6364
}
65+
66+
/**
67+
* @group legacy
68+
*/
69+
public function testInvalidChoiceValuesAreDropped()
70+
{
71+
$type = new CurrencyType();
72+
73+
$this->assertSame(array(), $type->loadChoicesForValues(array('foo')));
74+
}
6475
}

Tests/Extension/Core/Type/LanguageTypeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
15+
use Symfony\Component\Form\Extension\Core\Type\LanguageType;
1516
use Symfony\Component\Intl\Util\IntlTestHelper;
1617

1718
class LanguageTypeTest extends BaseTypeTest
@@ -73,4 +74,14 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'en', $expectedD
7374
{
7475
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
7576
}
77+
78+
/**
79+
* @group legacy
80+
*/
81+
public function testInvalidChoiceValuesAreDropped()
82+
{
83+
$type = new LanguageType();
84+
85+
$this->assertSame(array(), $type->loadChoicesForValues(array('foo')));
86+
}
7687
}

Tests/Extension/Core/Type/LocaleTypeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
15+
use Symfony\Component\Form\Extension\Core\Type\LocaleType;
1516
use Symfony\Component\Intl\Util\IntlTestHelper;
1617

1718
class LocaleTypeTest extends BaseTypeTest
@@ -61,4 +62,14 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = 'en', $expectedD
6162
{
6263
parent::testSubmitNullUsesDefaultEmptyData($emptyData, $expectedData);
6364
}
65+
66+
/**
67+
* @group legacy
68+
*/
69+
public function testInvalidChoiceValuesAreDropped()
70+
{
71+
$type = new LocaleType();
72+
73+
$this->assertSame(array(), $type->loadChoicesForValues(array('foo')));
74+
}
6475
}

Tests/Extension/Core/Type/UrlTypeTest.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,6 @@ public function testThrowExceptionIfDefaultProtocolIsInvalid()
8383
));
8484
}
8585

86-
public function testSubmitWithNonStringDataDoesNotBreakTheFixUrlProtocolListener()
87-
{
88-
$form = $this->factory->create(static::TESTED_TYPE);
89-
$form->submit(array('domain.com', 'www.domain.com'));
90-
91-
$this->assertSame(array('domain.com', 'www.domain.com'), $form->getData());
92-
}
93-
9486
public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = 'http://empty')
9587
{
9688
$form = $this->factory->create(static::TESTED_TYPE, null, array(

Tests/Extension/Validator/Constraints/FormValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public function testDontValidateConstraintsIfNoValidationGroups()
220220
->getForm();
221221

222222
// Launch transformer
223-
$form->submit(array());
223+
$form->submit('foo');
224224

225225
$this->expectNoValidate();
226226

0 commit comments

Comments
 (0)