public function testFormErrorsWithNonFormComponents() { if (!class_exists('Symfony\\Component\\Form\\Extension\\Core\\Type\\SubmitType')) { $this->markTestSkipped('Not using Symfony Form >= 2.3 with submit type'); } $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $factoryBuilder = new FormFactoryBuilder(); $factoryBuilder->addType(new \Symfony\Component\Form\Extension\Core\Type\SubmitType()); $factoryBuilder->addType(new \Symfony\Component\Form\Extension\Core\Type\ButtonType()); $factory = $factoryBuilder->getFormFactory(); $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('foo', null, $dispatcher); $formConfigBuilder->setFormFactory($factory); $formConfigBuilder->setCompound(true); $formConfigBuilder->setDataMapper($this->getMock('Symfony\\Component\\Form\\DataMapperInterface')); $fooConfig = $formConfigBuilder->getFormConfig(); $form = new Form($fooConfig); $form->add('save', 'submit'); try { $this->serialize($form); } catch (\Exception $e) { $this->assertTrue(false, 'Serialization should not throw an exception'); } }
public function testNestedFormErrors() { $dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('foo', null, $dispatcher); $formConfigBuilder->setCompound(true); $formConfigBuilder->setDataMapper($this->getMock('Symfony\\Component\\Form\\DataMapperInterface')); $fooConfig = $formConfigBuilder->getFormConfig(); $form = new Form($fooConfig); $form->addError(new FormError('This is the form error')); $formConfigBuilder = new \Symfony\Component\Form\FormConfigBuilder('bar', null, $dispatcher); $barConfig = $formConfigBuilder->getFormConfig(); $child = new Form($barConfig); $child->addError(new FormError('Error of the child form')); $form->add($child); $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form)); }