Example #1
0
 protected function setUp()
 {
     $this->controller = $controller = $this->getMock("Thelia\\Controller\\BaseController", ["getParser", "render", "renderRaw"]);
     /**
      * Reset static :: $formDefinition on controllers
      */
     $this->definitionReflection = $reflection = (new \ReflectionObject($this->controller))->getProperty('formDefinition');
     $reflection->setAccessible(true);
     $this->formDefinition = $reflection->getValue();
     $reflection->setValue(null);
     /**
      * Add the test type to the factory and
      * the form to the container
      */
     $factory = new FormFactoryBuilder();
     $factory->addExtension(new CoreExtension());
     $factory->addType(new TestType());
     /**
      * Construct the container
      */
     $container = new Container();
     $container->set("thelia.form_factory_builder", $factory);
     $container->set("thelia.translator", new Translator($container));
     $container->setParameter("thelia.parser.forms", array("test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm"));
     $request = new Request();
     $request->setSession(new Session(new MockArraySessionStorage()));
     $container->set("request", $request);
     $container->set("thelia.forms.validator_builder", new ValidatorBuilder());
     $container->set("event_dispatcher", new EventDispatcher());
     $this->controller->setContainer($container);
 }
 protected function setUp()
 {
     /**
      * Add the test type to the factory and
      * the form to the container
      */
     $factory = new FormFactoryBuilder();
     $factory->addExtension(new CoreExtension());
     $factory->addType(new TestType());
     /**
      * Construct the container
      */
     $container = new Container();
     $container->set("thelia.form_factory_builder", $factory);
     $container->set("thelia.translator", new Translator($container));
     $container->setParameter("thelia.parser.forms", $definition = array("test_form" => "Thelia\\Tests\\Resources\\Form\\TestForm"));
     $request = new Request();
     $requestStack = new RequestStack();
     $requestStack->push($request);
     $request->setSession(new Session(new MockArraySessionStorage()));
     $container->set("request", $request);
     $container->set("request_stack", $requestStack);
     $container->set("thelia.forms.validator_builder", new ValidatorBuilder());
     $container->set("event_dispatcher", new EventDispatcher());
     $this->factory = new TheliaFormFactory($requestStack, $container, $definition);
 }
 protected function setUp()
 {
     $this->registry = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry');
     $builder = new FormFactoryBuilder();
     $builder->addExtensions($this->getExtensions())->addExtension(new CoreExtension());
     $this->factory = $builder->getFormFactory();
     $this->formType = new OptionRowType();
 }
 public function testAddTypeGuesser()
 {
     $factoryBuilder = new FormFactoryBuilder();
     $factoryBuilder->addTypeGuesser($this->guesser);
     $factory = $factoryBuilder->getFormFactory();
     $registry = $this->registry->getValue($factory);
     $extensions = $registry->getExtensions();
     $this->assertCount(1, $extensions);
     $this->assertNotNull($extensions[0]->getTypeGuesser());
 }
 /**
  * @dataProvider dataTestParse
  */
 public function testParse($typeName, $expected)
 {
     $resolvedTypeFactory = new ResolvedFormTypeFactory();
     $formFactoryBuilder = new FormFactoryBuilder();
     $formFactoryBuilder->setResolvedTypeFactory($resolvedTypeFactory);
     $formFactoryBuilder->addExtension(new CoreExtension());
     $formFactoryBuilder->addTypeExtension(new DescriptionFormTypeExtension());
     $formFactory = $formFactoryBuilder->getFormFactory();
     $formTypeParser = new FormTypeParser($formFactory);
     $output = $formTypeParser->parse($typeName);
     $this->assertEquals($expected, $output);
 }
 /**
  * @dataProvider dataTestParseWithoutEntity
  */
 public function testParseWithoutEntity($typeName, $expected)
 {
     $resolvedTypeFactory = new ResolvedFormTypeFactory();
     $formFactoryBuilder = new FormFactoryBuilder();
     $formFactoryBuilder->setResolvedTypeFactory($resolvedTypeFactory);
     $formFactoryBuilder->addExtension(new CoreExtension());
     $formFactoryBuilder->addTypeExtension(new DescriptionFormTypeExtension());
     $formFactory = $formFactoryBuilder->getFormFactory();
     $formTypeParser = new FormTypeParser($formFactory, $entityToChoice = false);
     set_error_handler(array('Nayzo\\ApiDocBundle\\Tests\\WebTestCase', 'handleDeprecation'));
     trigger_error('test', E_USER_DEPRECATED);
     $output = $formTypeParser->parse($typeName);
     restore_error_handler();
     $this->assertEquals($expected, $output);
 }
Example #7
0
 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');
     }
 }
Example #8
0
 /**
  * Creates a form factory builder with the default configuration.
  *
  * @return FormFactoryBuilderInterface The form factory builder
  */
 public static function createFormFactoryBuilder()
 {
     $builder = new FormFactoryBuilder();
     $builder->addExtension(new CoreExtension());
     return $builder;
 }
 public function testFormErrorsWithNonFormComponents()
 {
     if (!class_exists(SubmitType::class)) {
         $this->markTestSkipped('Not using Symfony Form >= 2.3 with submit type');
     }
     $dispatcher = $this->createMock(EventDispatcherInterface::class);
     $factoryBuilder = new FormFactoryBuilder();
     $factoryBuilder->addType(new SubmitType());
     $factoryBuilder->addType(new ButtonType());
     $factory = $factoryBuilder->getFormFactory();
     $formConfigBuilder = new FormConfigBuilder('foo', null, $dispatcher);
     $formConfigBuilder->setFormFactory($factory);
     $formConfigBuilder->setCompound(true);
     $formConfigBuilder->setDataMapper($this->createMock(DataMapperInterface::class));
     $fooConfig = $formConfigBuilder->getFormConfig();
     $form = new Form($fooConfig);
     $form->add('save', method_exists(AbstractType::class, 'getBlockPrefix') ? SubmitType::class : 'submit');
     $this->serialize($form);
     $this->assertTrue(true);
     // Exception not thrown
 }
Example #10
0
 /**
  * Adds validation capabilities to the form, including translations for the messages.
  *
  * @param FormFactoryBuilder $builder
  *
  * @return void
  */
 protected function addValidatorExtensionToFactoryBuilder(FormFactoryBuilder $builder)
 {
     $builder->addExtension(new ValidatorExtension($this->app->validator));
     if (isset($this->app->translator)) {
         $r = new \ReflectionClass('Symfony\\Component\\Form\\Form');
         $this->app->translator->addResource('xliff', dirname($r->getFilename()) . '/Resources/translations/validators.' . $this->locale . '.xlf', $this->locale, 'validators');
     }
 }