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); }
/** * @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); }
/** * 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; }
/** * 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'); } }