Browse Source

Tests added

minayaserrano 11 years ago
parent
commit
dee78a620f

+ 31 - 0
tests/JMS/Serializer/Tests/Serializer/BaseSerializationTest.php

@@ -27,6 +27,7 @@ use JMS\Serializer\Tests\Fixtures\Discriminator\Car;
 use JMS\Serializer\Tests\Fixtures\InlineChildEmpty;
 use JMS\Serializer\Tests\Fixtures\InlineChildEmpty;
 use JMS\Serializer\Tests\Fixtures\Tree;
 use JMS\Serializer\Tests\Fixtures\Tree;
 use PhpCollection\Sequence;
 use PhpCollection\Sequence;
+use Symfony\Component\Form\FormFactoryBuilder;
 use Symfony\Component\Translation\MessageSelector;
 use Symfony\Component\Translation\MessageSelector;
 use Symfony\Component\Translation\IdentityTranslator;
 use Symfony\Component\Translation\IdentityTranslator;
 use JMS\Serializer\EventDispatcher\Subscriber\DoctrineProxySubscriber;
 use JMS\Serializer\EventDispatcher\Subscriber\DoctrineProxySubscriber;
@@ -501,6 +502,36 @@ abstract class BaseSerializationTest extends \PHPUnit_Framework_TestCase
         $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
         $this->assertEquals($this->getContent('nested_form_errors'), $this->serialize($form));
     }
     }
 
 
+    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 testConstraintViolation()
     public function testConstraintViolation()
     {
     {
         $violation = new ConstraintViolation('Message of violation', array(), null, 'foo', null);
         $violation = new ConstraintViolation('Message of violation', array(), null, 'foo', null);

+ 5 - 0
tests/JMS/Serializer/Tests/Serializer/YamlSerializationTest.php

@@ -42,6 +42,11 @@ class YamlSerializationTest extends BaseSerializationTest
         $this->markTestSkipped('This is not available for the YAML format.');
         $this->markTestSkipped('This is not available for the YAML format.');
     }
     }
 
 
+    public function testFormErrorsWithNonFormComponents()
+    {
+        $this->markTestSkipped('This is not available for the YAML format.');
+    }
+
     protected function getContent($key)
     protected function getContent($key)
     {
     {
         if (!file_exists($file = __DIR__.'/yml/'.$key.'.yml')) {
         if (!file_exists($file = __DIR__.'/yml/'.$key.'.yml')) {