getNormData example


        $form = $this->getBuilder()
            ->setCompound(true)
            ->setDataMapper(new DataMapper())
            ->getForm();

        $child = $this->getBuilder()->getForm();

        $form->add($child);

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

    public function testAddDoesNotMapViewDataToFormIfInheritData()
    {
        $form = $this->getBuilder()
            ->setCompound(true)
            ->setDataMapper(new DataMapper())
            ->getForm();

        $child = $this->getBuilder()
            
return $this->modelData;
    }

    public function getNormData(): mixed
    {
        if ($this->inheritData) {
            if (!$this->parent) {
                throw new RuntimeException('The form is configured to inherit its parent\'s data, but does not have a parent.');
            }

            return $this->parent->getNormData();
        }

        if (!$this->defaultDataSet) {
            if ($this->lockSetData) {
                throw new RuntimeException('A cycle was detected. Listeners to the PRE_SET_DATA event must not call getNormData() if the form data has not already been set.');
            }

            $this->setData($this->config->getData());
        }

        return $this->normData;
    }
$view = new FixedDataTransformer([
            'foo' => 'bar',
        ]);

        $config = new FormConfigBuilder('name', null, new EventDispatcher());
        $config->addViewTransformer($view);
        $config->addModelTransformer($model);
        $config->setData('default');
        $form = new Form($config);

        $this->assertSame('default', $form->getData());
        $this->assertSame('foo', $form->getNormData());
        $this->assertSame('bar', $form->getViewData());
    }

    public function testDataTransformationFailure()
    {
        $this->expectException(TransformationFailedException::class);
        $this->expectExceptionMessage('Unable to transform data for property path "name": No mapping for value "arg"');
        $model = new FixedDataTransformer([
            'default' => 'foo',
        ]);
        $view = new FixedDataTransformer([
            
$this->assertSame('{{ widget }}', $view->vars['money_pattern']);
    }

    public function testSubmitNullUsesDefaultEmptyData($emptyData = '10.00', $expectedData = 10.0)
    {
        $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 testDefaultFormattingWithDefaultRounding()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, ['scale' => 0]);
        $form->setData('12345.54321');

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

    
$form = $this->factory->createBuilder(static::TESTED_TYPE)
            ->addViewTransformer(new FixedDataTransformer([
                // required for the initial, internal setData(null)                 '' => 'null',
                // required to test that submit(null) is converted to ''                 'empty' => '',
            ]))
            ->setCompound(false)
            ->getForm();

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

        $form->submit(null);

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

    public function testSubmitWithEmptyDataUsesEmptyDataOption()
    {
        

        return [
            FormEvents::SUBMIT => 'onSubmit',
        ];
    }

    /** * @return void */
    public function onSubmit(FormEvent $event)
    {
        $dataToMergeInto = $event->getForm()->getNormData();
        $data = $event->getData() ?? [];

        if (!\is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
        }

        if (null !== $dataToMergeInto && !\is_array($dataToMergeInto) && !($dataToMergeInto instanceof \Traversable && $dataToMergeInto instanceof \ArrayAccess)) {
            throw new UnexpectedTypeException($dataToMergeInto, 'array or (\Traversable and \ArrayAccess)');
        }

        // If we are not allowed to change anything, return immediately
$this->assertSame($ulid$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 testSubmitNullWithText()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'widget' => 'text',
        ]);
        $form->submit(null);

        $this->assertNull($form->getData());
        $this->assertNull($form->getNormData());
        $this->assertSame([
            // View data is an array of choice values array             'date' => ['year' => '', 'month' => '', 'day' => ''],
            'time' => ['hour' => '', 'minute' => ''],
        ]$form->getViewData());
    }

    public function testSubmitNullWithSingleText()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'widget' => 'single_text',
        ]);


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

        // listener normalizes data on submit         $this->assertSame($expectedData$form->getViewData());
        $this->assertSame($expectedData$form->getNormData());
        $this->assertSame($expectedData$form->getData());
    }
}


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

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

    public function testHtml5EnablesSpecificFormatting()
    {
        \Locale::setDefault('de_CH');

        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'html5' => true,
            'rounding_mode' => \NumberFormatter::ROUND_UP,
            'scale' => 2,
            
$this->assertEquals('foobar', $form->getViewData());
        $this->assertFalse($form->isSynchronized());
    }

    public function testSubmitNull($expected = null, $norm = null, $view = null)
    {
        $form = $this->factory->create($this->getTestedType(), null, $this->getTestOptions());

        $form->submit(null);

        $this->assertNull($form->getData());
        $this->assertNull($form->getNormData());
        $this->assertSame('', $form->getViewData());
        $this->assertTrue($form->isSynchronized());
    }

    public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = null)
    {
        $emptyData = Suit::Hearts->value;

        $form = $this->factory->create($this->getTestedType(), null, [
            'class' => Suit::class,
            'empty_data' => $emptyData,
        ]);
$view->vars['attr']['readonly'] = true;
            }

            $helpTranslationParameters = array_merge($view->parent->vars['help_translation_parameters']$helpTranslationParameters);
        }

        $formConfig = $form->getConfig();
        $view->vars = array_replace($view->vars, [
            'errors' => $form->getErrors(),
            'valid' => $form->isSubmitted() ? $form->isValid() : true,
            'value' => $form->getViewData(),
            'data' => $form->getNormData(),
            'required' => $form->isRequired(),
            'label_attr' => $options['label_attr'],
            'help' => $options['help'],
            'help_attr' => $options['help_attr'],
            'help_html' => $options['help_html'],
            'help_translation_parameters' => $helpTranslationParameters,
            'compound' => $formConfig->getCompound(),
            'method' => $formConfig->getMethod(),
            'action' => $formConfig->getAction(),
            'submitted' => $form->isSubmitted(),
        ]);
    }
    public function testSubmitNull($expected = null, $norm = null, $view = null)
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'multiple' => false,
            'expanded' => false,
            'choices' => [],
        ]);

        $form->submit(null);

        $this->assertNull($form->getData());
        $this->assertNull($form->getNormData());
        $this->assertSame('', $form->getViewData());
        $this->assertTrue($form->isSynchronized());
    }

    public function testSubmitSingleNonExpandedEmpty()
    {
        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'multiple' => false,
            'expanded' => false,
            'choices' => $this->choices,
        ]);

        
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']);

        $form->submit('Europe/Amsterdam');

        
->createView();

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

    public function testSubmitNull($expected = null, $norm = null, $view = null)
    {
        $form = $this->factory->create($this->getTestedType(), null, $this->getTestOptions());
        $form->submit(null);

        $this->assertSame($expected$form->getData());
        $this->assertSame($norm$form->getNormData());
        $this->assertSame($view$form->getViewData());
    }

    public function testSubmitNullUsesDefaultEmptyData($emptyData = 'empty', $expectedData = null)
    {
        $builder = $this->factory->createBuilder($this->getTestedType(), null, $this->getTestOptions());

        if ($builder->getCompound()) {
            $emptyData = [];
            foreach ($builder as $field) {
                // empty children should map null (model data) in the compound view data
Home | Imprint | This part of the site doesn't use cookies.