ignore _method forms in NativeRequestHandler
This commit is contained in:
parent
205b0ba2cc
commit
bc4b0913b4
@ -115,6 +115,10 @@ class NativeRequestHandler implements RequestHandlerInterface
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (\is_array($data) && array_key_exists('_method', $data) && $method === $data['_method'] && !$form->has('_method')) {
|
||||||
|
unset($data['_method']);
|
||||||
|
}
|
||||||
|
|
||||||
$form->submit($data, 'PATCH' !== $method);
|
$form->submit($data, 'PATCH' !== $method);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,6 +179,59 @@ class NativeRequestHandlerTest extends AbstractRequestHandlerTest
|
|||||||
$this->assertFalse($form->isSubmitted());
|
$this->assertFalse($form->isSubmitted());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testFormIgnoresMethodFieldIfRequestMethodIsMatched()
|
||||||
|
{
|
||||||
|
$form = $this->createForm('foo', 'PUT', true);
|
||||||
|
$form->add($this->createForm('bar'));
|
||||||
|
|
||||||
|
$this->setRequestData('PUT', [
|
||||||
|
'foo' => [
|
||||||
|
'_method' => 'PUT',
|
||||||
|
'bar' => 'baz',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->requestHandler->handleRequest($form, $this->request);
|
||||||
|
|
||||||
|
$this->assertSame([], $form->getExtraData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormDoesNotIgnoreMethodFieldIfRequestMethodIsNotMatched()
|
||||||
|
{
|
||||||
|
$form = $this->createForm('foo', 'PUT', true);
|
||||||
|
$form->add($this->createForm('bar'));
|
||||||
|
|
||||||
|
$this->setRequestData('PUT', [
|
||||||
|
'foo' => [
|
||||||
|
'_method' => 'DELETE',
|
||||||
|
'bar' => 'baz',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->requestHandler->handleRequest($form, $this->request);
|
||||||
|
|
||||||
|
$this->assertSame(['_method' => 'DELETE'], $form->getExtraData());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testMethodSubFormIsSubmitted()
|
||||||
|
{
|
||||||
|
$form = $this->createForm('foo', 'PUT', true);
|
||||||
|
$form->add($this->createForm('_method'));
|
||||||
|
$form->add($this->createForm('bar'));
|
||||||
|
|
||||||
|
$this->setRequestData('PUT', [
|
||||||
|
'foo' => [
|
||||||
|
'_method' => 'PUT',
|
||||||
|
'bar' => 'baz',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->requestHandler->handleRequest($form, $this->request);
|
||||||
|
|
||||||
|
$this->assertTrue($form->get('_method')->isSubmitted());
|
||||||
|
$this->assertSame('PUT', $form->get('_method')->getData());
|
||||||
|
}
|
||||||
|
|
||||||
protected function setRequestData($method, $data, $files = [])
|
protected function setRequestData($method, $data, $files = [])
|
||||||
{
|
{
|
||||||
if ('GET' === $method) {
|
if ('GET' === $method) {
|
||||||
|
Reference in New Issue
Block a user