|
@@ -11,8 +11,11 @@
|
|
|
|
|
|
namespace Sonata\AdminBundle\Tests\Form\Type;
|
|
|
|
|
|
+use Prophecy\Argument\Token\AnyValueToken;
|
|
|
+use Sonata\AdminBundle\Form\Extension\Field\Type\FormTypeFieldExtension;
|
|
|
use Sonata\AdminBundle\Form\Type\AdminType;
|
|
|
use Symfony\Component\Form\Test\TypeTestCase;
|
|
|
+use Symfony\Component\Form\Tests\Fixtures\TestExtension;
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
|
|
|
|
|
class AdminTypeTest extends TypeTestCase
|
|
@@ -38,4 +41,62 @@ class AdminTypeTest extends TypeTestCase
|
|
|
$this->assertSame('link_delete', $options['btn_delete']);
|
|
|
$this->assertSame('SonataAdminBundle', $options['btn_catalogue']);
|
|
|
}
|
|
|
+
|
|
|
+ public function testSubmitValidData()
|
|
|
+ {
|
|
|
+ if (!method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix')) {
|
|
|
+ $this->markTestSkipped('Testing ancient versions would be more complicated.');
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ $parentAdmin = $this->prophesize('Sonata\AdminBundle\Admin\AdminInterface');
|
|
|
+ $parentField = $this->prophesize('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
|
|
|
+ $parentField->getAdmin()->shouldBeCalled()->willReturn($parentAdmin->reveal());
|
|
|
+
|
|
|
+ $modelManager = $this->prophesize('Sonata\AdminBundle\Model\ModelManagerInterface');
|
|
|
+ $modelManager->modelReverseTransform(
|
|
|
+ 'Sonata\AdminBundle\Tests\Fixtures\Entity\Foo',
|
|
|
+ array()
|
|
|
+ )->shouldBeCalled();
|
|
|
+
|
|
|
+ $admin = $this->prophesize('Sonata\AdminBundle\Admin\AbstractAdmin');
|
|
|
+ $admin->hasParentFieldDescription()->shouldBeCalled()->willReturn(false);
|
|
|
+ $admin->getParentFieldDescription()->shouldBeCalled()->willReturn($parentField->reveal());
|
|
|
+ $admin->isGranted('DELETE')->shouldBeCalled()->willReturn(false);
|
|
|
+ $admin->setSubject(null)->shouldBeCalled();
|
|
|
+ $admin->defineFormBuilder(new AnyValueToken())->shouldBeCalled();
|
|
|
+ $admin->getModelManager()->shouldBeCalled()->willReturn($modelManager);
|
|
|
+ $admin->getClass()->shouldBeCalled()->willReturn('Sonata\AdminBundle\Tests\Fixtures\Entity\Foo');
|
|
|
+
|
|
|
+ $field = $this->prophesize('Sonata\AdminBundle\Admin\FieldDescriptionInterface');
|
|
|
+ $field->getAssociationAdmin()->shouldBeCalled()->willReturn($admin->reveal());
|
|
|
+ $field->getAdmin()->shouldBeCalled();
|
|
|
+ $field->getName()->shouldBeCalled();
|
|
|
+ $field->getOption('edit', 'standard')->shouldBeCalled();
|
|
|
+ $field->getOption('inline', 'natural')->shouldBeCalled();
|
|
|
+ $field->getOption('block_name', false)->shouldBeCalled();
|
|
|
+ $formData = array();
|
|
|
+
|
|
|
+ $form = $this->factory->create(
|
|
|
+ 'Sonata\AdminBundle\Form\Type\AdminType',
|
|
|
+ null,
|
|
|
+ array(
|
|
|
+ 'sonata_field_description' => $field->reveal(),
|
|
|
+ )
|
|
|
+ );
|
|
|
+ $form->submit($formData);
|
|
|
+ $this->assertTrue($form->isSynchronized());
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function getExtensions()
|
|
|
+ {
|
|
|
+ $extensions = parent::getExtensions();
|
|
|
+ $guesser = $this->prophesize('Symfony\Component\Form\FormTypeGuesserInterface')->reveal();
|
|
|
+ $extension = new TestExtension($guesser);
|
|
|
+
|
|
|
+ $extension->addTypeExtension(new FormTypeFieldExtension(array(), array()));
|
|
|
+ $extensions[] = $extension;
|
|
|
+
|
|
|
+ return $extensions;
|
|
|
+ }
|
|
|
}
|