protected function setUp() { parent::setUp(); $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new DateTimeJqueryTypeExtension())->addTypeExtension(new DateJqueryTypeExtension())->addTypeExtension(new BirthdayJqueryTypeExtension())->getFormFactory(); $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory); }
protected function setUp() { $this->factory = Forms::createFormFactoryBuilder()->addTypeExtension(new DataBlockExtension())->getFormFactory(); $templateRenderer = $this->getMock('Oro\\Bundle\\FormBundle\\Form\\Builder\\TemplateRendererInterface'); $templateRenderer->expects($this->any())->method('render')->will($this->returnArgument(0)); $this->builder = new DataBlockBuilder($templateRenderer, 'form'); }
/** * {@inheritdoc} */ protected function setUp() { $this->translatableType = new TranslatableType(); $this->translatableResource = $this->createResourceMock(); $this->translatableFactory = $this->createFactoryMock(); $this->formFactory = Forms::createFormFactoryBuilder()->addType(new ResourceType())->addType($this->translatableType)->addType(new TranslationsFormsType(new TranslationForm($this->createFormRegistryMock(), $this->createManagerRegistryMock()), new TranslationsFormsListener(), new DefaultProvider(['en', 'fr'], 'en', ['en'])))->addType(new TranslationTestType())->addType(new TranslatableTestType($this->translatableResource, $this->translatableFactory))->getFormFactory(); }
protected function setUp() { $this->fooGatewayFactoryMock = $this->getMock('Payum\\Core\\GatewayFactoryInterface'); $registry = $this->getMock('Payum\\Core\\Registry\\GatewayFactoryRegistryInterface'); $registry->expects($this->any())->method('getGatewayFactory')->with('foo')->willReturn($this->fooGatewayFactoryMock); $this->formFactory = Forms::createFormFactoryBuilder()->addType(new GatewayFactoriesChoiceType(array('foo' => 'Foo Factory')))->addType(new GatewayConfigType($registry))->getFormFactory(); }
protected function setUp() { parent::setUp(); $validator = new Validator(new ClassMetadataFactory(new LoaderChain([])), new ConstraintValidatorFactory(), new DefaultTranslator()); $this->factory = Forms::createFormFactoryBuilder()->addTypeExtension(new DataBlockExtension())->addTypeExtension(new FormTypeValidatorExtension($validator))->getFormFactory(); $this->type = new EntityType(new ExtendDbIdentifierNameGenerator()); }
protected function setUp() { parent::setUp(); $validator = $this->getMock('Symfony\\Component\\Validator\\ValidatorInterface'); $validator->expects($this->any())->method('validate')->willReturn([]); $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new FormTypeValidatorExtension($validator))->getFormFactory(); }
public function ajouterAction(Request $request) { $em = $this->getDoctrine()->getManager(); $sysmatricule = $this->get('trc_core.matricule'); $profil = new Profil(); $formFactory = Forms::createFormFactory(); $form = $this->get('form.factory')->create(new ProfilType(), $profil); if ($form->handleRequest($request)->isValid()) { $profil->setMatricule($sysmatricule->matriculeStandard($profil)); $em->persist($profil); $em->flush(); return $this->redirect($this->generateUrl('trc_admin_profils')); } $p = 1; $nbre = 5; $criteres = array(); if ($request->query->get('p') !== null && !empty($request->query->get('p'))) { $p = $request->query->get('p'); } $id = ($p - 1) * $nbre; if ($id < 0) { $id = 0; } $profils = $em->getRepository('TRCCoreBundle:Profil')->findBy($criteres, array(), $nbre, $id); $servicePagination = $this->get('trc_core.pagination'); $objet = 'Profil'; $url = $this->generateUrl('trc_admin_profils'); $urlRoute = 'trc_admin_profils'; $pagination = $servicePagination->pagination($objet, $p, $url, $urlRoute, $criteres, $nbre); return $this->render('TRCAdminBundle:Profils:ajouter.html.twig', array('form' => $form->createView(), 'profils' => $profils, 'pagination' => $pagination)); }
protected function setUp() { if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) { $this->markTestSkipped('The "EventDispatcher" component is not available'); } $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->getFormFactory(); }
/** * {@inheritdooc}. */ protected function setUp() { parent::setUp(); $params = self::$kernel->getContainer()->get('service_container')->getParameter('fm_tinymce'); $this->tinyMCEtype = new TinyMCEType($params); $this->factory = Forms::createFormFactoryBuilder()->addType($this->tinyMCEtype)->getFormFactory(); }
protected function setUp() { parent::setUp(); $this->factory = Forms::createFormFactoryBuilder()->addTypeExtension(new FormTypeValidatorExtension($this->getMock('Symfony\\Component\\Validator\\ValidatorInterface')))->addTypeGuesser($this->getMockBuilder('Symfony\\Component\\Form\\Extension\\Validator\\ValidatorTypeGuesser')->disableOriginalConstructor()->getMock())->getFormFactory(); $this->dispatcher = $this->getMock('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface'); $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->zoneProvider = $this->getMock('Silvestra\\Component\\Banner\\Provider\\BannerZoneProviderInterface'); $this->factory = Forms::createFormFactoryBuilder()->addTypeExtension($this->createValidatorExtension())->addTypeGuesser($this->getMockValidatorTypeGuesser())->addTypes(array(new BannerZoneType('Silvestra\\Component\\Banner\\Model\\BannerZone', $this->zoneProvider)))->getFormFactory(); $this->builder = $this->createFormBuilder(); }
/** * Get form * * @param Category $category * * @return \Symfony\Component\Form\Form * @throws \Rad\DependencyInjection\Exception\ServiceNotFoundException */ public function getForm(Category $category = null) { $data = null; if ($category) { $data = $category->toArray(); } $action = $category ? Container::get('router')->generateUrl(['categories', $data['id']]) : Container::get('router')->generateUrl(['categories']); $formFactory = Forms::createFormFactory(); $options = ['action' => $action, 'method' => $category ? 'PUT' : 'POST']; $event = $this->getEventManager()->dispatch(self::EVENT_CATEGORIES_FORM_SCOPE, $this); /** @var CategoriesTable $categoriesTable */ $categoriesTable = TableRegistry::get('Categories.Categories'); $treeList = $categoriesTable->find('treeList'); if (!empty($category)) { $treeList->where(['id !=' => $data['id']]); } $formBuilder = $formFactory->createBuilder('form', $data, $options)->add('title', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('slug', 'text', ['required' => true, 'attr' => ['class' => 'form-control']])->add('parent_id', 'choice', ['choices' => $treeList->toArray(), 'empty_data' => null, 'empty_value' => 'No Parent', 'label' => 'Parent', 'required' => false]); if (!empty($event->getResult())) { $choices = $event->getResult(); if (!is_array($choices)) { $choices = [$choices]; } $formBuilder->add('scope', 'choice', ['choices' => $choices, 'label' => 'Group']); } return $formBuilder->add('description', 'textarea', ['required' => false, 'attr' => ['class' => 'form-control wysiwyg']])->add('submit', 'submit')->getForm(); }
/** * Prepare tests and include custom form options. */ protected function setUp() { // add TopicTypeExtension $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new OptionalTypeExtension())->getFormFactory(); $this->dispatcher = $this->getMockBuilder('Symfony\\Component\\EventDispatcher\\EventDispatcherInterface')->getMock(); $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory); }
/** * {@inheritdooc}. */ public function setUp() { parent::setUp(); $ckeditorType = new CkeditorType($this->get('service_container')); $this->factory = Forms::createFormFactoryBuilder()->addType($ckeditorType)->getFormFactory(); $this->formType = method_exists('Symfony\\Component\\Form\\AbstractType', 'getBlockPrefix') ? 'Trsteel\\CkeditorBundle\\Form\\Type\\CkeditorType' : 'ckeditor'; }
/** * @throws \Twig_Error_Loader */ protected function setUp() { // Setup factory for tabs $this->tabFactory = Forms::createFormFactory(); parent::setUp(); $rendererEngine = new TwigRendererEngine(array('form_div_layout.html.twig', 'fields.html.twig')); if (interface_exists('Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface')) { $csrfProviderInterface = 'Symfony\\Component\\Security\\Csrf\\CsrfTokenManagerInterface'; } else { $csrfProviderInterface = 'Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface'; } $renderer = new TwigRenderer($rendererEngine, $this->getMock($csrfProviderInterface)); $this->extension = new FormExtension($renderer); $reflection = new \ReflectionClass($renderer); $bridgeDirectory = dirname($reflection->getFileName()) . '/../Resources/views/Form'; $loader = new \Twig_Loader_Filesystem(array($bridgeDirectory, __DIR__ . '/../../Resources/views/Form')); $loader->addPath(__DIR__ . '/../../Resources/views', 'MopaBootstrap'); $environment = new Twig_Environment($loader, array('strict_variables' => true)); $environment->addExtension(new TranslationExtension(new StubTranslator())); $environment->addExtension(new IconExtension('fontawesome')); $environment->addExtension(new FormExtension2()); $environment->addGlobal('global', ''); $environment->addExtension($this->extension); $this->extension->initRuntime($environment); }
protected function setUp() { $this->em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock(); $translator = $this->getMock('Symfony\\Component\\Translation\\TranslatorInterface'); $translator->expects($this->any())->method('trans')->will($this->returnArgument(0)); $registry = $this->getMockForAbstractClass('Doctrine\\Common\\Persistence\\ManagerRegistry', [], '', false); $registry->expects($this->any())->method('getManagerForClass')->will($this->returnValue($this->em)); $this->formFactory = Forms::createFormFactoryBuilder()->addExtensions([new PreloadedExtension(['oro_type_filter' => new FilterType($translator), 'oro_type_choice_filter' => new ChoiceFilterType($translator), 'entity' => new EntityType($registry), 'oro_type_entity_filter' => new EntityFilterType($translator)], []), new CsrfExtension($this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface'))])->getFormFactory(); $classMetaData = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $classMetaData->expects($this->any())->method('getName')->will($this->returnValue('OroSegment:Segment')); $classMetaData->expects($this->any())->method('getIdentifier')->will($this->returnValue(['id'])); $this->em->expects($this->any())->method('getClassMetadata')->will($this->returnValue($classMetaData)); $this->dynamicSegmentQueryBuilder = $this->getMockBuilder('Oro\\Bundle\\SegmentBundle\\Query\\DynamicSegmentQueryBuilder')->disableOriginalConstructor()->getMock(); $this->staticSegmentQueryBuilder = $this->getMockBuilder('Oro\\Bundle\\SegmentBundle\\Query\\StaticSegmentQueryBuilder')->disableOriginalConstructor()->getMock(); $this->entityNameProvider = $this->getMock('Oro\\Bundle\\SegmentBundle\\Provider\\EntityNameProvider'); $this->entityNameProvider->expects($this->any())->method('getEntityName')->will($this->returnValue('Namespace\\Entity')); $this->entityConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock(); $this->extendConfigProvider = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock(); $configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $this->entityConfigProvider->expects($this->any())->method('getConfigManager')->will($this->returnValue($configManager)); $configManager->expects($this->any())->method('getEntityManager')->will($this->returnValue($this->em)); $staticQBServiceID = uniqid('static'); $dynamicQBServiceID = uniqid('dynamic'); $container = new Container(); $container->set($staticQBServiceID, $this->staticSegmentQueryBuilder); $container->set($dynamicQBServiceID, $this->dynamicSegmentQueryBuilder); $this->filter = new SegmentFilter($this->formFactory, new FilterUtility(), new ServiceLink($container, $dynamicQBServiceID), new ServiceLink($container, $staticQBServiceID), $this->entityNameProvider, $this->entityConfigProvider, $this->extendConfigProvider); $this->filter->init('segment', ['entity' => '']); }
/** * FormFactory constructor. * @param Container $container */ public function __construct(Container $container) { # configuring the form factory $this->formFactory = Forms::createFormFactoryBuilder()->addExtension(new DoctrineOrmExtension(new ExtendedEntityManager($container->get('models'))))->addExtension(new ValidatorExtension(Validation::createValidator()))->getFormFactory(); # registering all necessary smarty plugins new SmartyPlugins($this->getFormHelper(), $container->get('template')); }
/** * Register the service provider. * * @return void */ public function register() { $configPath = __DIR__ . '/../config/form.php'; $this->mergeConfigFrom($configPath, 'form'); $this->app->bind('twig.form.engine', function ($app) { $theme = (array) $app['config']->get('form.theme', 'bootstrap_3_layout.html.twig'); return new TwigRendererEngine($theme); }); $this->app->bind('twig.form.renderer', function ($app) { return new TwigRenderer($app['twig.form.engine']); }); $this->app->bind('form.types', function () { return array(); }); $this->app->bind('form.type.extensions', function () { return array(); }); $this->app->bind('form.type.guessers', function () { return array(); }); $this->app->bind('form.extensions', function ($app) { return array($app->make('Barryvdh\\Form\\Extension\\SessionExtension'), new HttpFoundationExtension(), new EloquentExtension()); }); $this->app->bind('form.factory', function ($app) { return Forms::createFormFactoryBuilder()->addExtensions($app['form.extensions'])->addTypes($app['form.types'])->addTypeExtensions($app['form.type.extensions'])->addTypeGuessers($app['form.type.guessers'])->setResolvedTypeFactory($app['form.resolved_type_factory'])->getFormFactory(); }); $this->app->alias('form.factory', 'Symfony\\Component\\Form\\FormFactoryInterface'); $this->app->bind('form.resolved_type_factory', function () { return new ResolvedFormTypeFactory(); }); }
/** * {@inheritdoc} */ protected function setUp() { $this->securityFacade = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock(); $this->formType = new FrontendAccountUserType($this->securityFacade); $this->formType->setAccountUserClass(self::DATA_CLASS); $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->getFormFactory(); }
public function __construct(Request $request, $type = "form", $data = array(), $options = array()) { $this->request = $request; $validator = Validation::createValidatorBuilder(); if (!isset($options["attr"]["name"])) { $options["attr"]["thelia_name"] = $this->getName(); } $builder = Forms::createFormFactoryBuilder()->addExtension(new HttpFoundationExtension()); if (!isset($options["csrf_protection"]) || $options["csrf_protection"] !== false) { $builder->addExtension(new CsrfExtension(new SessionCsrfProvider($request->getSession(), isset($options["secret"]) ? $options["secret"] : ConfigQuery::read("form.secret", md5(__DIR__))))); } $translator = Translator::getInstance(); $validator->setTranslationDomain('validators')->setTranslator($translator); $this->formBuilder = $builder->addExtension(new ValidatorExtension($validator->getValidator()))->getFormFactory()->createNamedBuilder($this->getName(), $type, $data, $this->cleanOptions($options)); $this->buildForm(); // If not already set, define the success_url field // This field is not included in the standard form hidden fields // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (!$this->formBuilder->has('success_url')) { $this->formBuilder->add("success_url", "hidden"); } // The "error_message" field defines the error message displayed if // the form could not be validated. If it is empty, a standard error message is displayed instead. // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (!$this->formBuilder->has('error_message')) { $this->formBuilder->add("error_message", "hidden"); } $this->form = $this->formBuilder->getForm(); }
protected function setUp() { $this->serverParams = $this->getMock('Symfony\\Component\\Form\\Util\\ServerParams', array('getNormalizedIniPostMaxSize', 'getContentLength')); $this->requestHandler = $this->getRequestHandler(); $this->factory = Forms::createFormFactoryBuilder()->getFormFactory(); $this->request = null; }
/** * {@inheritdoc} */ protected function setUp() { $requestStatus = new RequestStatus(); $repository = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectRepository')->disableOriginalConstructor()->getMock(); $repository->expects($this->any())->method('findOneBy')->with(['name' => 'open'])->willReturn($requestStatus); $manager = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ObjectManager')->disableOriginalConstructor()->getMock(); $manager->expects($this->any())->method('getRepository')->with(self::REQUEST_STATUS_CLASS)->willReturn($repository); /** * @var \Doctrine\Common\Persistence\ManagerRegistry|\PHPUnit_Framework_MockObject_MockObject $registry */ $registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $registry->expects($this->any())->method('getManagerForClass')->with('OroUserBundle:User')->willReturn($manager); $registry = $this->getMockBuilder('Doctrine\\Common\\Persistence\\ManagerRegistry')->disableOriginalConstructor()->getMock(); $registry->expects($this->any())->method('getManagerForClass')->with(self::REQUEST_STATUS_CLASS)->willReturn($manager); /** @var ConfigManager|\PHPUnit_Framework_MockObject_MockObject $configManager */ $configManager = $this->getMockBuilder('Oro\\Bundle\\ConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $configManager->expects($this->any())->method('get')->with('oro_b2b_rfp.default_request_status')->willReturn('open'); /** * @var \Symfony\Component\Validator\ValidatorInterface|\PHPUnit_Framework_MockObject_MockObject $validator */ $validator = $this->getMock('\\Symfony\\Component\\Validator\\ValidatorInterface'); $validator->expects($this->any())->method('validate')->will($this->returnValue(new ConstraintViolationList())); $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new FormTypeValidatorExtension($validator))->getFormFactory(); $this->formType = new FrontendRequestType($configManager, $registry); $this->formType->setDataClass(self::DATA_CLASS); $this->formType->setRequestStatusClass(self::REQUEST_STATUS_CLASS); }
protected function setUp() { parent::setUp(); $validator = $this->getMock('\\Symfony\\Component\\Validator\\Validator\\ValidatorInterface'); $validator->method('validate')->will($this->returnValue(new ConstraintViolationList())); $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new FormTypeValidatorExtension($validator))->getFormFactory(); }
protected function setUp() { parent::setUp(); if (!class_exists('Symfony\\Component\\Form\\Form')) { $this->markTestSkipped('The "Form" component is not available'); } if (!class_exists('Doctrine\\DBAL\\Platforms\\MySqlPlatform')) { $this->markTestSkipped('Doctrine DBAL is not available.'); } if (!class_exists('Doctrine\\Common\\Version')) { $this->markTestSkipped('Doctrine Common is not available.'); } if (!class_exists('Doctrine\\ORM\\EntityManager')) { $this->markTestSkipped('Doctrine ORM is not available.'); } $this->em = DoctrineTestHelper::createTestEntityManager(); $this->emRegistry = $this->createRegistryMock('default', $this->em); $this->items = array(); $schemaTool = new SchemaTool($this->em); $classes = array($this->em->getClassMetadata(self::SINGLE_INT_ID_CLASS)); try { $schemaTool->dropSchema($classes); } catch (\Exception $e) { } try { $schemaTool->createSchema($classes); } catch (\Exception $e) { } $this->createEntities(); $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->addTypeExtension(new ChoiceSelect2TypeExtension($this->dispatcher, $this->requestStack, $this->router, $this->getExtensionTypeName(), 10))->addType(new EntityType($this->emRegistry))->addTypeExtension(new EntitySelect2TypeExtension())->getFormFactory(); $this->builder = new FormBuilder(null, null, $this->dispatcher, $this->factory); }
public function testSubmitDoesNotAddExtraFieldForNullValues() { $factory = Forms::createFormFactoryBuilder()->getFormFactory(); $child = $factory->create('file', null, array('auto_initialize' => false)); $this->form->add($child); $this->form->submit(array('file' => null)); $this->assertCount(0, $this->form->getExtraData()); }
/** * {@inheritdoc} */ protected function setUp() { $this->resource = $this->createResourceMock(); $this->resourceFactory = $this->createFactoryMock(); $this->resource->expects($this->any())->method('getName')->will($this->returnValue('model')); $this->resourceType = $this->getMockBuilder(AbstractResourceType::class)->setConstructorArgs([$this->resource, $this->resourceFactory])->getMockForAbstractClass(); $this->formFactory = Forms::createFormFactoryBuilder()->addType(new ResourceType())->addType($this->resourceType)->getFormFactory(); }
/** * {@inheritdoc} */ protected function setUp() { $this->resource = $this->createResourceMock(); $this->managerRegistry = $this->createManagerRegistryMock(); $this->resource->expects($this->any())->method('getName')->will($this->returnValue('model')); $this->resourceChoiceType = new ResourceChoiceType(); $this->factory = Forms::createFormFactoryBuilder()->addType(new EntityType($this->managerRegistry))->addType($this->resourceChoiceType)->getFormFactory(); }
protected function setUp() { if (!class_exists('Symfony\\Component\\EventDispatcher\\EventDispatcher')) { $this->markTestSkipped('The "EventDispatcher" component is not available'); } $this->factory = Forms::createFormFactoryBuilder()->addExtensions($this->getExtensions())->getFormFactory(); set_error_handler(array('Symfony\\Component\\Form\\Test\\DeprecationErrorHandler', 'handle')); }
public function testSubmitDoesNotAddExtraFieldForNullValues() { $factory = Forms::createFormFactoryBuilder()->getFormFactory(); $child = $factory->createNamed('file', 'Symfony\\Component\\Form\\Extension\\Core\\Type\\FileType', null, array('auto_initialize' => false)); $this->form->add($child); $this->form->submit(array('file' => null), false); $this->assertCount(0, $this->form->getExtraData()); }
public function register(Application $app, array $options = array()) { $secret = $app->getConfig('form.secret'); $app->shared['csrf_provider'] = new DefaultCsrfProvider($secret); $extensions = array(new CsrfExtension($app->shared['csrf_provider']), new HttpFoundationExtension()); $factory = Forms::createFormFactoryBuilder()->addExtensions($extensions)->addTypeExtensions(array())->addTypeGuessers(array())->getFormFactory(); return $factory; }