2012-12-30 15:38:36 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Symfony\Component\Form\Tests;
|
|
|
|
|
2017-02-08 07:24:27 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2019-01-18 17:22:25 +00:00
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
|
|
|
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
|
|
|
|
use Symfony\Component\Form\Form;
|
|
|
|
use Symfony\Component\Form\FormBuilder;
|
2014-09-15 15:48:43 +01:00
|
|
|
use Symfony\Component\Form\FormError;
|
|
|
|
use Symfony\Component\Form\FormFactory;
|
2014-09-08 09:53:21 +01:00
|
|
|
use Symfony\Component\Form\Forms;
|
2014-09-15 15:48:43 +01:00
|
|
|
use Symfony\Component\Form\RequestHandlerInterface;
|
2014-09-08 09:53:21 +01:00
|
|
|
|
2012-12-30 15:38:36 +00:00
|
|
|
/**
|
|
|
|
* @author Bernhard Schussek <bschussek@gmail.com>
|
|
|
|
*/
|
2017-02-08 07:24:27 +00:00
|
|
|
abstract class AbstractRequestHandlerTest extends TestCase
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
|
|
|
/**
|
2014-09-15 15:48:43 +01:00
|
|
|
* @var RequestHandlerInterface
|
2012-12-30 15:38:36 +00:00
|
|
|
*/
|
2013-04-20 14:56:42 +01:00
|
|
|
protected $requestHandler;
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2014-09-08 09:53:21 +01:00
|
|
|
/**
|
2014-09-15 15:48:43 +01:00
|
|
|
* @var FormFactory
|
2014-09-08 09:53:21 +01:00
|
|
|
*/
|
|
|
|
protected $factory;
|
|
|
|
|
2012-12-30 15:38:36 +00:00
|
|
|
protected $request;
|
|
|
|
|
2014-09-15 15:48:43 +01:00
|
|
|
protected $serverParams;
|
|
|
|
|
2012-12-30 15:38:36 +00:00
|
|
|
protected function setUp()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->serverParams = $this->getMockBuilder('Symfony\Component\Form\Util\ServerParams')->setMethods(['getNormalizedIniPostMaxSize', 'getContentLength'])->getMock();
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler = $this->getRequestHandler();
|
2014-09-08 09:53:21 +01:00
|
|
|
$this->factory = Forms::createFormFactoryBuilder()->getFormFactory();
|
2012-12-30 15:38:36 +00:00
|
|
|
$this->request = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function methodExceptGetProvider()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
return [
|
|
|
|
['POST'],
|
|
|
|
['PUT'],
|
|
|
|
['DELETE'],
|
|
|
|
['PATCH'],
|
|
|
|
];
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function methodProvider()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
return array_merge([
|
|
|
|
['GET'],
|
|
|
|
], $this->methodExceptGetProvider());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodProvider
|
|
|
|
*/
|
2013-04-20 16:32:55 +01:00
|
|
|
public function testSubmitIfNameInRequest($method)
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('param1', $method);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
2012-12-30 15:38:36 +00:00
|
|
|
'param1' => 'DATA',
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
$this->assertSame('DATA', $form->getData());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodProvider
|
|
|
|
*/
|
2013-04-20 16:32:55 +01:00
|
|
|
public function testDoNotSubmitIfWrongRequestMethod($method)
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('param1', $method);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
|
|
|
$otherMethod = 'POST' === $method ? 'PUT' : 'POST';
|
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($otherMethod, [
|
2012-12-30 15:38:36 +00:00
|
|
|
'param1' => 'DATA',
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertFalse($form->isSubmitted());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodExceptGetProvider
|
|
|
|
*/
|
2013-08-01 16:20:43 +01:00
|
|
|
public function testDoNoSubmitSimpleFormIfNameNotInRequestAndNotGetRequest($method)
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('param1', $method, false);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
|
|
|
'paramx' => [],
|
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertFalse($form->isSubmitted());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodExceptGetProvider
|
|
|
|
*/
|
2013-08-01 16:20:43 +01:00
|
|
|
public function testDoNotSubmitCompoundFormIfNameNotInRequestAndNotGetRequest($method)
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('param1', $method, true);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
|
|
|
'paramx' => [],
|
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertFalse($form->isSubmitted());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
2013-04-20 16:32:55 +01:00
|
|
|
public function testDoNotSubmitIfNameNotInRequestAndGetRequest()
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('param1', 'GET');
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData('GET', [
|
|
|
|
'paramx' => [],
|
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertFalse($form->isSubmitted());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodProvider
|
|
|
|
*/
|
2013-04-20 16:32:55 +01:00
|
|
|
public function testSubmitFormWithEmptyNameIfAtLeastOneFieldInRequest($method)
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('', $method, true);
|
|
|
|
$form->add($this->createForm('param1'));
|
|
|
|
$form->add($this->createForm('param2'));
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, $requestData = [
|
2012-12-30 15:38:36 +00:00
|
|
|
'param1' => 'submitted value',
|
|
|
|
'paramx' => 'submitted value',
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
$this->assertTrue($form->get('param1')->isSubmitted());
|
|
|
|
$this->assertSame('submitted value', $form->get('param1')->getData());
|
|
|
|
|
|
|
|
if ('PATCH' === $method) {
|
|
|
|
$this->assertFalse($form->get('param2')->isSubmitted());
|
|
|
|
} else {
|
|
|
|
$this->assertTrue($form->get('param2')->isSubmitted());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->assertNull($form->get('param2')->getData());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodProvider
|
|
|
|
*/
|
2013-04-20 16:32:55 +01:00
|
|
|
public function testDoNotSubmitFormWithEmptyNameIfNoFieldInRequest($method)
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('', $method, true);
|
|
|
|
$form->add($this->createForm('param1'));
|
|
|
|
$form->add($this->createForm('param2'));
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
2012-12-30 15:38:36 +00:00
|
|
|
'paramx' => 'submitted value',
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertFalse($form->isSubmitted());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodExceptGetProvider
|
|
|
|
*/
|
|
|
|
public function testMergeParamsAndFiles($method)
|
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('param1', $method, true);
|
|
|
|
$form->add($this->createForm('field1'));
|
|
|
|
$form->add($this->createBuilder('field2', false, ['allow_file_upload' => true])->getForm());
|
2019-02-06 20:50:10 +00:00
|
|
|
$file = $this->getUploadedFile();
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
|
|
|
'param1' => [
|
2012-12-30 15:38:36 +00:00
|
|
|
'field1' => 'DATA',
|
2019-01-16 09:39:14 +00:00
|
|
|
],
|
|
|
|
], [
|
|
|
|
'param1' => [
|
2012-12-30 15:38:36 +00:00
|
|
|
'field2' => $file,
|
2019-01-16 09:39:14 +00:00
|
|
|
],
|
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
$this->assertSame('DATA', $form->get('field1')->getData());
|
|
|
|
$this->assertSame($file, $form->get('field2')->getData());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodExceptGetProvider
|
|
|
|
*/
|
|
|
|
public function testParamTakesPrecedenceOverFile($method)
|
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createForm('param1', $method);
|
2019-02-06 20:50:10 +00:00
|
|
|
$file = $this->getUploadedFile();
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
2012-12-30 15:38:36 +00:00
|
|
|
'param1' => 'DATA',
|
2019-01-16 09:39:14 +00:00
|
|
|
], [
|
2012-12-30 15:38:36 +00:00
|
|
|
'param1' => $file,
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
$this->assertSame('DATA', $form->getData());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider methodExceptGetProvider
|
|
|
|
*/
|
2013-04-20 16:32:55 +01:00
|
|
|
public function testSubmitFileIfNoParam($method)
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
|
|
|
|
->setMethod($method)
|
|
|
|
->getForm();
|
2019-02-06 20:50:10 +00:00
|
|
|
$file = $this->getUploadedFile();
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
2012-12-30 15:38:36 +00:00
|
|
|
'param1' => null,
|
2019-01-16 09:39:14 +00:00
|
|
|
], [
|
2012-12-30 15:38:36 +00:00
|
|
|
'param1' => $file,
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
2019-01-18 17:22:25 +00:00
|
|
|
|
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
$this->assertSame($file, $form->getData());
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 22:10:57 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider methodExceptGetProvider
|
|
|
|
*/
|
|
|
|
public function testSubmitMultipleFiles($method)
|
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$form = $this->createBuilder('param1', false, ['allow_file_upload' => true])
|
|
|
|
->setMethod($method)
|
|
|
|
->getForm();
|
2019-02-06 20:50:10 +00:00
|
|
|
$file = $this->getUploadedFile();
|
2015-02-23 22:10:57 +00:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData($method, [
|
2015-02-23 22:10:57 +00:00
|
|
|
'param1' => null,
|
2019-01-16 09:39:14 +00:00
|
|
|
], [
|
2019-02-06 20:50:10 +00:00
|
|
|
'param2' => $this->getUploadedFile('2'),
|
2015-02-23 22:10:57 +00:00
|
|
|
'param1' => $file,
|
2019-02-06 20:50:10 +00:00
|
|
|
'param3' => $this->getUploadedFile('3'),
|
2019-01-16 09:39:14 +00:00
|
|
|
]);
|
2015-02-23 22:10:57 +00:00
|
|
|
|
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
|
|
|
|
2019-01-18 17:22:25 +00:00
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
$this->assertSame($file, $form->getData());
|
2015-02-23 22:10:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 15:01:39 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider methodExceptGetProvider
|
|
|
|
*/
|
|
|
|
public function testSubmitFileWithNamelessForm($method)
|
|
|
|
{
|
|
|
|
$form = $this->createForm('', $method, true);
|
|
|
|
$fileForm = $this->createBuilder('document', false, ['allow_file_upload' => true])->getForm();
|
|
|
|
$form->add($fileForm);
|
|
|
|
$file = $this->getUploadedFile();
|
|
|
|
$this->setRequestData($method, [
|
|
|
|
'document' => null,
|
|
|
|
], [
|
|
|
|
'document' => $file,
|
|
|
|
]);
|
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
|
|
|
|
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
$this->assertSame($file, $fileForm->getData());
|
|
|
|
}
|
|
|
|
|
2014-09-15 15:48:43 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider getPostMaxSizeFixtures
|
|
|
|
*/
|
2019-01-16 09:39:14 +00:00
|
|
|
public function testAddFormErrorIfPostMaxSizeExceeded($contentLength, $iniMax, $shouldFail, array $errorParams = [])
|
2014-09-08 09:53:21 +01:00
|
|
|
{
|
2014-09-15 15:48:43 +01:00
|
|
|
$this->serverParams->expects($this->once())
|
|
|
|
->method('getContentLength')
|
|
|
|
->will($this->returnValue($contentLength));
|
|
|
|
$this->serverParams->expects($this->any())
|
|
|
|
->method('getNormalizedIniPostMaxSize')
|
|
|
|
->will($this->returnValue($iniMax));
|
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$options = ['post_max_size_message' => 'Max {{ max }}!'];
|
2015-06-23 17:42:21 +01:00
|
|
|
$form = $this->factory->createNamed('name', 'Symfony\Component\Form\Extension\Core\Type\TextType', null, $options);
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->setRequestData('POST', [], []);
|
2014-09-08 09:53:21 +01:00
|
|
|
|
|
|
|
$this->requestHandler->handleRequest($form, $this->request);
|
|
|
|
|
2014-09-15 15:48:43 +01:00
|
|
|
if ($shouldFail) {
|
2015-05-03 15:08:06 +01:00
|
|
|
$error = new FormError($options['post_max_size_message'], null, $errorParams);
|
|
|
|
$error->setOrigin($form);
|
2014-09-08 09:53:21 +01:00
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
$this->assertEquals([$error], iterator_to_array($form->getErrors()));
|
2014-09-15 15:48:43 +01:00
|
|
|
$this->assertTrue($form->isSubmitted());
|
|
|
|
} else {
|
|
|
|
$this->assertCount(0, $form->getErrors());
|
|
|
|
$this->assertFalse($form->isSubmitted());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPostMaxSizeFixtures()
|
|
|
|
{
|
2019-01-16 09:39:14 +00:00
|
|
|
return [
|
|
|
|
[pow(1024, 3) + 1, '1G', true, ['{{ max }}' => '1G']],
|
|
|
|
[pow(1024, 3), '1G', false],
|
|
|
|
[pow(1024, 2) + 1, '1M', true, ['{{ max }}' => '1M']],
|
|
|
|
[pow(1024, 2), '1M', false],
|
|
|
|
[1024 + 1, '1K', true, ['{{ max }}' => '1K']],
|
|
|
|
[1024, '1K', false],
|
|
|
|
[null, '1K', false],
|
|
|
|
[1024, '', false],
|
|
|
|
[1024, 0, false],
|
|
|
|
];
|
2014-09-08 09:53:21 +01:00
|
|
|
}
|
|
|
|
|
2017-09-01 10:39:51 +01:00
|
|
|
public function testUploadedFilesAreAccepted()
|
|
|
|
{
|
2019-02-06 20:50:10 +00:00
|
|
|
$this->assertTrue($this->requestHandler->isFileUpload($this->getUploadedFile()));
|
2017-09-01 10:39:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testInvalidFilesAreRejected()
|
|
|
|
{
|
|
|
|
$this->assertFalse($this->requestHandler->isFileUpload($this->getInvalidFile()));
|
|
|
|
}
|
|
|
|
|
2019-04-06 13:28:07 +01:00
|
|
|
/**
|
|
|
|
* @dataProvider uploadFileErrorCodes
|
|
|
|
*/
|
|
|
|
public function testFailedFileUploadIsTurnedIntoFormError($errorCode, $expectedErrorCode)
|
|
|
|
{
|
|
|
|
$this->assertSame($expectedErrorCode, $this->requestHandler->getUploadFileError($this->getFailedUploadedFile($errorCode)));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function uploadFileErrorCodes()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'no error' => [UPLOAD_ERR_OK, null],
|
|
|
|
'upload_max_filesize ini directive' => [UPLOAD_ERR_INI_SIZE, UPLOAD_ERR_INI_SIZE],
|
|
|
|
'MAX_FILE_SIZE from form' => [UPLOAD_ERR_FORM_SIZE, UPLOAD_ERR_FORM_SIZE],
|
|
|
|
'partially uploaded' => [UPLOAD_ERR_PARTIAL, UPLOAD_ERR_PARTIAL],
|
|
|
|
'no file upload' => [UPLOAD_ERR_NO_FILE, UPLOAD_ERR_NO_FILE],
|
|
|
|
'missing temporary directory' => [UPLOAD_ERR_NO_TMP_DIR, UPLOAD_ERR_NO_TMP_DIR],
|
|
|
|
'write failure' => [UPLOAD_ERR_CANT_WRITE, UPLOAD_ERR_CANT_WRITE],
|
|
|
|
'stopped by extension' => [UPLOAD_ERR_EXTENSION, UPLOAD_ERR_EXTENSION],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-01-16 09:39:14 +00:00
|
|
|
abstract protected function setRequestData($method, $data, $files = []);
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2013-04-20 14:56:42 +01:00
|
|
|
abstract protected function getRequestHandler();
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2019-02-06 20:50:10 +00:00
|
|
|
abstract protected function getUploadedFile($suffix = '');
|
2012-12-30 15:38:36 +00:00
|
|
|
|
2017-09-01 10:39:51 +01:00
|
|
|
abstract protected function getInvalidFile();
|
|
|
|
|
2019-04-06 13:28:07 +01:00
|
|
|
abstract protected function getFailedUploadedFile($errorCode);
|
|
|
|
|
2019-01-18 17:22:25 +00:00
|
|
|
protected function createForm($name, $method = null, $compound = false)
|
|
|
|
{
|
|
|
|
$config = $this->createBuilder($name, $compound);
|
|
|
|
|
|
|
|
if (null !== $method) {
|
|
|
|
$config->setMethod($method);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Form($config);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function createBuilder($name, $compound = false, array $options = [])
|
2012-12-30 15:38:36 +00:00
|
|
|
{
|
2019-01-18 17:22:25 +00:00
|
|
|
$builder = new FormBuilder($name, null, new EventDispatcher(), $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')->getMock(), $options);
|
|
|
|
$builder->setCompound($compound);
|
|
|
|
|
|
|
|
if ($compound) {
|
|
|
|
$builder->setDataMapper(new PropertyPathMapper());
|
|
|
|
}
|
|
|
|
|
|
|
|
return $builder;
|
2012-12-30 15:38:36 +00:00
|
|
|
}
|
|
|
|
}
|