submit example

$form = $this->factory->create(static::TESTED_TYPE);
        $form->setData(new Uuid($uuid));

        $this->assertSame($uuid$form->createView()->vars['value']);
    }

    public function testSubmitNullUsesDefaultEmptyData($emptyData = '', $expectedData = null)
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'empty_data' => $emptyData,
        ]);
        $form->submit(null);

        $this->assertSame($expectedData$form->getViewData());
        $this->assertSame($expectedData$form->getNormData());
        $this->assertSame($expectedData$form->getData());
    }
}


    public function testSubmitFromSingleTextDateTimeWithDefaultFormat()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'model_timezone' => 'UTC',
            'view_timezone' => 'UTC',
            'widget' => 'single_text',
            'input' => 'datetime',
        ]);

        $form->submit('2010-06-02');

        $this->assertEquals(new \DateTime('2010-06-02 UTC')$form->getData());
        $this->assertEquals('2010-06-02', $form->getViewData());
    }

    public function testSubmitFromSingleTextDateTimeWithCustomFormat()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'model_timezone' => 'UTC',
            'view_timezone' => 'UTC',
            'widget' => 'single_text',
            

        $this->expectException(UnexpectedTypeException::class);
        $form->setData(new \stdClass());
    }

    public function testNotResizedIfSubmittedWithMissingData()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'entry_type' => TextTypeTest::TESTED_TYPE,
        ]);
        $form->setData(['foo@foo.com', 'bar@bar.com']);
        $form->submit(['foo@bar.com']);

        $this->assertTrue($form->has('0'));
        $this->assertTrue($form->has('1'));
        $this->assertEquals('foo@bar.com', $form[0]->getData());
        $this->assertEquals('', $form[1]->getData());
    }

    public function testResizedDownIfSubmittedWithMissingDataAndAllowDelete()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'entry_type' => TextTypeTest::TESTED_TYPE,
            
'model_timezone' => 'UTC',
            'view_timezone' => 'UTC',
            'input' => 'datetime',
            'widget' => 'choice',
        ]);

        $input = [
            'hour' => '3',
            'minute' => '4',
        ];

        $form->submit($input);

        $dateTime = new \DateTime('1970-01-01 03:04:00 UTC');

        $this->assertEquals($dateTime$form->getData());
        $this->assertEquals($input$form->getViewData());
    }

    public function testSubmitDateTimeImmutable()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'model_timezone' => 'UTC',
            
class WeekTypeTest extends BaseTypeTestCase
{
    public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\WeekType';

    public function testSubmitArray()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'widget' => 'choice',
            'input' => 'array',
        ]);

        $form->submit([
            'year' => '2019',
            'week' => '1',
        ]);

        $this->assertSame(['year' => 2019, 'week' => 1]$form->getData());
    }

    public function testSubmitString()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'years' => [2019],
            
return;
                }

                $data = $_GET[$name];
            }
        } else {
            // Mark the form with an error if the uploaded size was too large             // This is done here and not in FormValidator because $_POST is             // empty when that error occurs. Hence the form is never submitted.             if ($this->serverParams->hasPostMaxSizeBeenExceeded()) {
                // Submit the form, but don't clear the default values                 $form->submit(null, false);

                $form->addError(new FormError(
                    $form->getConfig()->getOption('upload_max_size_message')(),
                    null,
                    ['{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize()]
                ));

                return;
            }

            $fixedFiles = [];
            
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;

class UrlTypeTest extends TextTypeTest
{
    public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\UrlType';

    public function testSubmitAddsDefaultProtocolIfNoneIsIncluded()
    {
        $form = $this->factory->create(static::TESTED_TYPE, 'name');

        $form->submit('www.domain.com');

        $this->assertSame('http://www.domain.com', $form->getData());
        $this->assertSame('http://www.domain.com', $form->getViewData());
    }

    public function testSubmitAddsNoDefaultProtocolIfAlreadyIncluded()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'default_protocol' => 'http',
        ]);

        
parent::setUp();

        $this->constraint = new Form();
    }

    public function testValidate()
    {
        $object = new \stdClass();
        $options = ['validation_groups' => ['group1', 'group2']];
        $form = $this->getCompoundForm($object$options);
        $form->submit([]);

        $this->expectValidateAt(0, 'data', $object['group1', 'group2']);

        $this->validator->validate($formnew Form());

        $this->assertNoViolation();
    }

    public function testValidateConstraints()
    {
        $object = new \stdClass();
        
public function testSubmitNull($expected = null, $norm = null, $view = null)
    {
        parent::testSubmitNull($expected$norm, '');
    }

    public function testSubmitNullUsesDefaultEmptyData($emptyData = 'Africa/Kinshasa', $expectedData = 'Africa/Kinshasa')
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'empty_data' => $emptyData,
        ]);
        $form->submit(null);

        $this->assertSame($emptyData$form->getViewData());
        $this->assertSame($expectedData$form->getNormData());
        $this->assertSame($expectedData$form->getData());
    }

    public function testDateTimeZoneInput()
    {
        $form = $this->factory->create(static::TESTED_TYPE, new \DateTimeZone('America/New_York')['input' => 'datetimezone']);

        $this->assertSame('America/New_York', $form->createView()->vars['value']);

        

  public function formLogin($username$password$working_dir = NULL) {
    $this->visit('/user/login', $working_dir);
    $assert = $this->getMink()->assertSession();
    $assert->statusCodeEquals(200);
    $assert->fieldExists('edit-name')->setValue($username);
    $assert->fieldExists('edit-pass')->setValue($password);
    $session = $this->getMink()->getSession();
    $session->getPage()->findButton('Log in')->submit();
  }

}
public function testSubmitNull($expected = null, $norm = null, $view = null)
    {
        parent::testSubmitNull($expected$norm, '');
    }

    public function testSubmitNullReturnsNullWithEmptyDataAsString()
    {
        $form = $this->factory->create(static::TESTED_TYPE, 'name', [
            'empty_data' => '',
        ]);

        $form->submit(null);
        $this->assertSame('', $form->getData());
        $this->assertSame('', $form->getNormData());
        $this->assertSame('', $form->getViewData());
    }

    public static function provideZeros()
    {
        return [
            [0, '0'],
            ['0', '0'],
            ['00000', '00000'],
        ];
$preSubmit = $preSetData;
        };

        $config = new FormConfigBuilder('name', null, new EventDispatcher());
        $config->addEventListener(FormEvents::PRE_SET_DATA, $preSetDataListener);
        $config->addEventListener(FormEvents::PRE_SUBMIT, $preSubmitListener);
        $form = new Form($config);

        // no call to setData() or similar where the object would be         // initialized otherwise
        $form->submit('foobar');

        $this->assertTrue($preSetData);
        $this->assertTrue($preSubmit);
    }

    // https://github.com/symfony/symfony/pull/7789     public function testFalseIsConvertedToNull()
    {
        $passedDataIsNull = false;

        $config = new FormConfigBuilder('name', null, new EventDispatcher());
        
->setData(false)
            ->createView();

        $this->assertFalse($view->vars['checked']);
    }

    public function testSubmitWithValueChecked()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'value' => 'foobar',
        ]);
        $form->submit('foobar');

        $this->assertTrue($form->getData());
        $this->assertEquals('foobar', $form->getViewData());
    }

    public function testSubmitWithRandomValueChecked()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'value' => 'foobar',
        ]);
        $form->submit('krixikraxi');

        
public function testSubmittedDataIsTrimmedBeforeTransforming()
    {
        $form = $this->factory->createBuilder(static::TESTED_TYPE)
            ->addViewTransformer(new FixedDataTransformer([
                '' => '',
                'reverse[a]' => 'a',
            ]))
            ->setCompound(false)
            ->getForm();

        $form->submit(' a ');

        $this->assertEquals('a', $form->getViewData());
        $this->assertEquals('reverse[a]', $form->getData());
    }

    public function testSubmittedDataIsNotTrimmedBeforeTransformingIfNoTrimming()
    {
        $form = $this->factory->createBuilder(static::TESTED_TYPE, null, ['trim' => false])
            ->addViewTransformer(new FixedDataTransformer([
                '' => '',
                'reverse[ a ]' => ' a ',
            ]))
public function testNotClickedByDefault()
    {
        $button = $this->factory->create(static::TESTED_TYPE);

        $this->assertFalse($button->isClicked());
    }

    public function testNotClickedIfSubmittedWithNull()
    {
        $button = $this->factory->create(static::TESTED_TYPE);
        $button->submit(null);

        $this->assertFalse($button->isClicked());
    }

    public function testClickedIfSubmittedWithEmptyString()
    {
        $button = $this->factory->create(static::TESTED_TYPE);
        $button->submit('');

        $this->assertTrue($button->isClicked());
    }

    
Home | Imprint | This part of the site doesn't use cookies.