Browse Source

Unit test ModelListType

Grégoire Paris 8 năm trước cách đây
mục cha
commit
173633d9a2
1 tập tin đã thay đổi với 47 bổ sung0 xóa
  1. 47 0
      Tests/Form/Type/ModelListTypeTest.php

+ 47 - 0
Tests/Form/Type/ModelListTypeTest.php

@@ -0,0 +1,47 @@
+<?php
+
+/*
+ * This file is part of the Sonata Project package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Tests\Form\Type;
+
+use Symfony\Component\Form\Test\TypeTestCase;
+
+class ModelListTypeTest extends TypeTestCase
+{
+    private $modelManager;
+
+    protected function setUp()
+    {
+        if (!method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
+            $this->markTestSkipped('Testing ancient versions would be more complicated.');
+        }
+
+        $this->modelManager = $this->prophesize('Sonata\AdminBundle\Model\ModelManagerInterface');
+
+        parent::setUp();
+    }
+
+    public function testSubmitValidData()
+    {
+        $formData = 42;
+
+        $form = $this->factory->create(
+            'Sonata\AdminBundle\Form\Type\ModelListType',
+            null,
+            array(
+                'model_manager' => $this->modelManager->reveal(),
+                'class' => 'My\Entity',
+            )
+        );
+        $this->modelManager->find('My\Entity', 42)->shouldBeCalled();
+        $form->submit($formData);
+        $this->assertTrue($form->isSynchronized());
+    }
+}