Exemplo n.º 1
0
 protected function getExtensions()
 {
     $assetsHelper = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock();
     $integrationType = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Provider\\ChannelInterface');
     $transportType = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Provider\\TransportInterface');
     $registry = new TypesRegistry();
     $registry->addChannelType(self::TEST_TYPE, $integrationType);
     $registry->addTransportType(uniqid('transport'), self::TEST_TYPE, $transportType);
     $security = $this->getMockBuilder('Oro\\Bundle\\SecurityBundle\\SecurityFacade')->disableOriginalConstructor()->getMock();
     $em = $this->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $metadata = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock();
     $em->expects($this->once())->method('getClassMetadata')->with($this->equalTo('OroUser:User'))->will($this->returnValue($metadata));
     $metadata->expects($this->once())->method('getSingleIdentifierFieldName')->will($this->returnValue(self::TEST_ID_FIELD_NAME));
     $searchHandler = $this->getMock('Oro\\Bundle\\FormBundle\\Autocomplete\\SearchHandlerInterface');
     $searchHandler->expects($this->any())->method('getEntityName')->will($this->returnValue('OroUser:User'));
     $searchRegistry = new SearchRegistry();
     $searchRegistry->addSearchHandler('acl_users', $searchHandler);
     $config = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigInterface');
     $config->expects($this->any())->method('has')->with($this->equalTo('grid_name'))->will($this->returnValue(true));
     $config->expects($this->any())->method('get')->with($this->equalTo('grid_name'))->will($this->returnValue('test_grid'));
     $cp = $this->getMock('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProviderInterface');
     $cp->expects($this->any())->method('getConfig')->will($this->returnValue($config));
     $cm = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock();
     $cm->expects($this->any())->method('getProvider')->will($this->returnValue($cp));
     $validator = new Validator(new ClassMetadataFactory(new LoaderChain([])), new ConstraintValidatorFactory(), new DefaultTranslator());
     $settingsProvider = $this->getMockBuilder('OroCRM\\Bundle\\ChannelBundle\\Provider\\SettingsProvider')->disableOriginalConstructor()->getMock();
     return [new PreloadedExtension(['oro_integration_channel_form' => $this->getChannelType($registry), 'oro_integration_type_select' => new IntegrationTypeSelectType($registry, $assetsHelper), 'oro_user_organization_acl_select' => new OrganizationUserAclSelectType(), 'oro_user_acl_select' => new UserAclSelectType(), 'oro_entity_create_or_select_inline' => new OroEntitySelectOrCreateInlineType($security, $cm), 'oro_jqueryselect2_hidden' => new OroJquerySelect2HiddenType($em, $searchRegistry, $cp), 'genemu_jqueryselect2_choice' => new Select2Type('choice'), 'genemu_jqueryselect2_hidden' => new Select2Type('hidden')], ['form' => [new FormTypeCsrfExtension($this->getMock('Symfony\\Component\\Form\\Extension\\Csrf\\CsrfProvider\\CsrfProviderInterface')), new FormTypeValidatorExtension($validator), new TooltipFormExtension()], 'oro_integration_channel_form' => [new IntegrationTypeExtension($settingsProvider)]])];
 }
Exemplo n.º 2
0
 /**
  * @return SearchRegistry|\PHPUnit_Framework_MockObject_MockObject
  */
 public function getMockSearchRegistry()
 {
     if (!$this->searchRegistry) {
         $this->searchRegistry = $this->getMock('Oro\\Bundle\\FormBundle\\Autocomplete\\SearchRegistry');
         $this->searchRegistry->method('getSearchHandler')->willReturn($this->getMockSearchHandler());
     }
     return $this->searchRegistry;
 }
 /**
  * @param OptionsResolverInterface $resolver
  * @param array                    $defaultConfig
  */
 protected function setConfigsNormalizer(OptionsResolverInterface $resolver, array $defaultConfig)
 {
     $resolver->setNormalizers(['configs' => function (Options $options, $configs) use($defaultConfig) {
         $result = array_replace_recursive($defaultConfig, $configs);
         if ($autoCompleteAlias = $options->get('autocomplete_alias')) {
             $result['autocomplete_alias'] = $autoCompleteAlias;
             if (empty($result['properties'])) {
                 $searchHandler = $this->searchRegistry->getSearchHandler($autoCompleteAlias);
                 $result['properties'] = $searchHandler->getProperties();
             }
             if (empty($result['route_name'])) {
                 $result['route_name'] = 'oro_form_autocomplete_search';
             }
             if (empty($result['extra_config'])) {
                 $result['extra_config'] = 'autocomplete';
             }
         }
         if (!array_key_exists('route_parameters', $result)) {
             $result['route_parameters'] = [];
         }
         if (empty($result['route_name'])) {
             throw new InvalidConfigurationException('Option "configs[route_name]" must be set.');
         }
         return $result;
     }]);
 }
Exemplo n.º 4
0
 /**
  * @param OptionsResolver $resolver
  * @param array $defaultConfigs
  */
 protected function setConfigsNormalizer(OptionsResolver $resolver, array $defaultConfigs)
 {
     $resolver->setNormalizer('autocomplete', function (Options $options, $configs) use($defaultConfigs) {
         $configs = array_replace_recursive($defaultConfigs, $configs);
         $configs['route_parameters']['per_page'] = $configs['per_page'];
         if (empty($configs['route_name']) && !empty($configs['alias'])) {
             $configs['route_name'] = 'oro_form_autocomplete_search';
             $configs['route_parameters']['name'] = $configs['alias'];
         }
         if (empty($configs['properties']) && !empty($configs['alias'])) {
             $searchHandler = $this->searchRegistry->getSearchHandler($configs['alias']);
             $configs['properties'] = $searchHandler->getProperties();
         }
         return $configs;
     });
 }