createForm example

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\PropertyAccess\PropertyAccess;

class CompoundFormTest extends TestCase
{
    private FormFactory $factory;
    private FormInterface $form;

    protected function setUp(): void
    {
        $this->factory = new FormFactory(new FormRegistry([]new ResolvedFormTypeFactory()));
        $this->form = $this->createForm();
    }

    public function testValidIfAllChildrenAreValid()
    {
        $this->form->add($this->getBuilder('firstName')->getForm());
        $this->form->add($this->getBuilder('lastName')->getForm());

        $this->form->submit([
            'firstName' => 'Bernhard',
            'lastName' => 'Schussek',
        ]);

        
class CheckboxTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(CheckboxType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('The checkbox has an invalid value.', $form->getConfig()->getOption('invalid_message'));
    }
}
'form_name' => 'form_2',
            'button_2' => '',
            'app_frontend_form_type_contact_form_type' => ['contactType' => '', 'firstName' => 'John'],
        ];

        $this->assertEquals($values1$form1->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
        $this->assertEquals($values2$form2->getPhpValues(), 'HTML5-compliant form attribute handled incorrectly');
    }

    public function testMultiValuedFields()
    {
        $form = $this->createForm('<form> <input type="text" name="foo[4]" value="foo" disabled="disabled" /> <input type="text" name="foo" value="foo" disabled="disabled" /> <input type="text" name="foo[2]" value="foo" disabled="disabled" /> <input type="text" name="foo[]" value="foo" disabled="disabled" /> <input type="text" name="bar[foo][]" value="foo" disabled="disabled" /> <input type="text" name="bar[foo][foobar]" value="foo" disabled="disabled" /> <input type="submit" /> </form> ');

        $this->assertEquals(
            [
use Symfony\Component\Form\Test\FormInterface;
use Symfony\Component\Form\Test\TypeTestCase;
use Symfony\Component\Validator\Constraints\GroupSequence;

/** * @author Bernhard Schussek <bschussek@gmail.com> */
abstract class BaseValidatorExtensionTestCase extends TypeTestCase
{
    public function testValidationGroupNullByDefault()
    {
        $form = $this->createForm();

        $this->assertNull($form->getConfig()->getOption('validation_groups'));
    }

    public function testValidationGroupsTransformedToArray()
    {
        $form = $this->createForm([
            'validation_groups' => 'group',
        ]);

        $this->assertEquals(['group']$form->getConfig()->getOption('validation_groups'));
    }
class LocaleTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(LocaleType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please select a valid locale.', $form->getConfig()->getOption('invalid_message'));
    }
}
class LanguageTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(LanguageType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please select a valid language.', $form->getConfig()->getOption('invalid_message'));
    }
}
class PasswordTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(PasswordType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('The password is invalid.', $form->getConfig()->getOption('invalid_message'));
    }
}
class DateTimeTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(DateTimeType::class, null, $options + ['widget' => 'choice']);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please enter a valid date and time.', $form->getConfig()->getOption('invalid_message'));
    }
}
class HiddenTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(HiddenType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('The hidden field is invalid.', $form->getConfig()->getOption('invalid_message'));
    }
}
class MoneyTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(MoneyType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please enter a valid money amount.', $form->getConfig()->getOption('invalid_message'));
    }
}
class ChoiceTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(ChoiceType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('The selected choice is invalid.', $form->getConfig()->getOption('invalid_message'));
    }
}
$this->redirect(array_merge($location$params));
    }

    /** * @param array<string, mixed> $data * * @return FormInterface<Customer> */
    private function createCustomerForm(array $data): FormInterface
    {
        $customer = new Customer();
        $form = $this->createForm(PersonalFormType::class$customer);
        $form->submit($data);

        return $form;
    }

    /** * @param array<string, mixed> $data * * @return FormInterface<Address> */
    private function createBillingForm(array $data): FormInterface
    {
class FileTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(FileType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please select a valid file.', $form->getConfig()->getOption('invalid_message'));
    }
}
class CountryTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(CountryType::class, null, $options);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please select a valid country.', $form->getConfig()->getOption('invalid_message'));
    }
}
class BirthdayTypeValidatorExtensionTest extends BaseValidatorExtensionTestCase
{
    use ValidatorExtensionTrait;

    protected function createForm(array $options = [])
    {
        return $this->factory->create(BirthdayType::class, null, $options + ['widget' => 'choice']);
    }

    public function testInvalidMessage()
    {
        $form = $this->createForm();

        $this->assertSame('Please enter a valid birthdate.', $form->getConfig()->getOption('invalid_message'));
    }
}
Home | Imprint | This part of the site doesn't use cookies.