getTestedType example

/** * @author Bernhard Schussek <bschussek@gmail.com> */
abstract class BaseTypeTestCase extends TypeTestCase
{
    use VersionAwareTest;

    public const TESTED_TYPE = '';

    public function testPassDisabledAsOption()
    {
        $form = $this->factory->create($this->getTestedType(), null, array_merge($this->getTestOptions()['disabled' => true]));

        $this->assertTrue($form->isDisabled());
    }

    public function testPassIdAndNameToView()
    {
        $view = $this->factory->createNamed('name', $this->getTestedType(), null, $this->getTestOptions())
            ->createView();

        $this->assertEquals('name', $view->vars['id']);
        $this->assertEquals('name', $view->vars['name']);
        

            'widget' => 'choice',
        ]);

        $view = $form->createView();
        $this->assertSame('foo', $view['year']->vars['choice_translation_domain']);
        $this->assertSame('test', $view['week']->vars['choice_translation_domain']);
    }

    public function testSubmitNull($expected = null, $norm = null, $view = null)
    {
        $form = $this->factory->create($this->getTestedType(), null, [
            'widget' => 'choice',
        ]);
        $form->submit(null);

        $this->assertSame(['year' => null, 'week' => null]$form->getData());
        $this->assertSame(['year' => null, 'week' => null]$form->getNormData());
        $this->assertSame(['year' => null, 'week' => null]$form->getViewData());
    }

    public function testSubmitFromChoiceEmpty()
    {
        
$this->assertSame('0', $view->vars['label']);
    }

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

    public function testPassBlockPrefixToViewWithParent()
    {
        $view = $this->factory->createNamedBuilder('parent', static::TESTED_TYPE)
            ->add('child', $this->getTestedType()[
                'block_prefix' => 'child',
            ])
            ->getForm()
            ->createView();

        $this->assertSame(['form', 'child', '_parent_child']$view['child']->vars['block_prefixes']);
    }

    public function testDefaultHelpTranslationParameters()
    {
        $view = $this->factory->createNamedBuilder('parent', self::TESTED_TYPE)
            
$this->expectException(BadMethodCallException::class);
        $this->expectExceptionMessage('Buttons do not support empty data.');
        parent::testSubmitNullUsesDefaultEmptyData($emptyData$expectedData);
    }

    public function testFormAttrOnRoot()
    {
        $view = $this->factory
            ->createNamedBuilder('parent', FormType::class, null, [
                'form_attr' => true,
            ])
            ->add('child1', $this->getTestedType())
            ->add('child2', $this->getTestedType())
            ->getForm()
            ->createView();
        $this->assertArrayNotHasKey('form', $view->vars['attr']);
        $this->assertSame($view->vars['id']$view['child1']->vars['attr']['form']);
        $this->assertSame($view->vars['id']$view['child2']->vars['attr']['form']);
    }

    public function testFormAttrOnChild()
    {
        $view = $this->factory
            
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symfony\Component\Translation\IdentityTranslator;
use Symfony\Contracts\Translation\TranslatableInterface;

class EnumTypeTest extends BaseTypeTestCase
{
    public const TESTED_TYPE = EnumType::class;

    public function testClassOptionIsRequired()
    {
        $this->expectException(MissingOptionsException::class);
        $this->factory->createNamed('name', $this->getTestedType());
    }

    public function testInvalidClassOption()
    {
        $this->expectException(InvalidOptionsException::class);
        $this->factory->createNamed('name', $this->getTestedType(), null, [
            'class' => 'foo',
        ]);
    }

    public function testInvalidClassOptionType()
    {
Home | Imprint | This part of the site doesn't use cookies.