Skip to content

Commit 1a28ba2

Browse files
Merge branch '4.1' into 4.2
* 4.1: [HttpFoundation] Check file exists before unlink [Console] Fixed #29835: ConfirmationQuestion with default true for answer '0' [Translation] Concatenated translation messages [Form] ensure compatibility with older PHPUnit mocks [Serializer] Docblock about throwing exceptions on serializer [Debug][ErrorHandler] Preserve our error handler when a logger set another one [Form] Changed UrlType input type to text when default_protocol is not null [Bugfix] MemcachedSessionHandler::close() must close connection
2 parents 26ae128 + 7f793d9 commit 1a28ba2

16 files changed

+280
-300
lines changed

Extension/Core/Type/UrlType.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\Form\AbstractType;
1515
use Symfony\Component\Form\Extension\Core\EventListener\FixUrlProtocolListener;
1616
use Symfony\Component\Form\FormBuilderInterface;
17+
use Symfony\Component\Form\FormInterface;
18+
use Symfony\Component\Form\FormView;
1719
use Symfony\Component\OptionsResolver\OptionsResolver;
1820

1921
class UrlType extends AbstractType
@@ -28,6 +30,17 @@ public function buildForm(FormBuilderInterface $builder, array $options)
2830
}
2931
}
3032

33+
/**
34+
* {@inheritdoc}
35+
*/
36+
public function buildView(FormView $view, FormInterface $form, array $options)
37+
{
38+
if ($options['default_protocol']) {
39+
$view->vars['attr']['inputmode'] = 'url';
40+
$view->vars['type'] = 'text';
41+
}
42+
}
43+
3144
/**
3245
* {@inheritdoc}
3346
*/

Form.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -532,9 +532,11 @@ 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') && $this->config->getRequestHandler()->isFileUpload($submittedData)) {
536-
$submittedData = null;
537-
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');
535+
} elseif ($this->config->getRequestHandler()->isFileUpload($submittedData)) {
536+
if (!$this->config->getOption('allow_file_upload')) {
537+
$submittedData = null;
538+
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, file upload given.');
539+
}
538540
} elseif (\is_array($submittedData) && !$this->config->getCompound() && !$this->config->hasOption('multiple')) {
539541
$submittedData = null;
540542
$this->transformationFailure = new TransformationFailedException('Submitted data was expected to be text or number, array given.');

Tests/AbstractFormTest.php

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,26 +65,6 @@ protected function getBuilder($name = 'name', EventDispatcherInterface $dispatch
6565
return new FormBuilder($name, $dataClass, $dispatcher ?: $this->dispatcher, $this->factory, $options);
6666
}
6767

68-
/**
69-
* @param string $name
70-
*
71-
* @return \PHPUnit_Framework_MockObject_MockObject
72-
*/
73-
protected function getMockForm($name = 'name')
74-
{
75-
$form = $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')->getMock();
76-
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')->getMock();
77-
78-
$form->expects($this->any())
79-
->method('getName')
80-
->will($this->returnValue($name));
81-
$form->expects($this->any())
82-
->method('getConfig')
83-
->will($this->returnValue($config));
84-
85-
return $form;
86-
}
87-
8868
/**
8969
* @return \PHPUnit_Framework_MockObject_MockObject
9070
*/

Tests/AbstractLayoutTest.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2236,10 +2236,25 @@ public function testTimezoneWithPlaceholder()
22362236
);
22372237
}
22382238

2239-
public function testUrl()
2239+
public function testUrlWithDefaultProtocol()
22402240
{
22412241
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
2242-
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url);
2242+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => 'http']);
2243+
2244+
$this->assertWidgetMatchesXpath($form->createView(), [],
2245+
'/input
2246+
[@type="text"]
2247+
[@name="name"]
2248+
[@value="http://www.google.com?foo1=bar1&foo2=bar2"]
2249+
[@inputmode="url"]
2250+
'
2251+
);
2252+
}
2253+
2254+
public function testUrlWithoutDefaultProtocol()
2255+
{
2256+
$url = 'http://www.google.com?foo1=bar1&foo2=bar2';
2257+
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\UrlType', $url, ['default_protocol' => null]);
22432258

22442259
$this->assertWidgetMatchesXpath($form->createView(), [],
22452260
'/input

0 commit comments

Comments
 (0)