/** * @param SettingsProvider $settingsProvider */ public function __construct(SettingsProvider $settingsProvider) { $settings = $settingsProvider->getLifetimeValueSettings(); foreach ($settings as $singleChannelTypeData) { $this->customerIdentities[$singleChannelTypeData['entity']] = $singleChannelTypeData['field']; } }
/** * @param ConfigureMenuEvent $event */ public function onNavigationConfigure(ConfigureMenuEvent $event) { foreach ((array) $this->settings->getSettings(SettingsProvider::DATA_PATH) as $setting) { if (!$this->state->isEntityEnabled($setting['name'])) { continue; } foreach ($setting['navigation_items'] as $item) { $navigateArray = explode('.', $item); $menu = $event->getMenu(); if ($menu->getName() !== $navigateArray[0]) { continue; } $navigateArrayCount = count($navigateArray); for ($i = 1; $i < $navigateArrayCount; $i++) { if ($menu->getChild($navigateArray[$i])) { /** redefinition of variable $menu */ $menu = $menu->getChild($navigateArray[$i]); } if ($menu && !$menu->isDisplayed()) { $menu->setDisplay(true); } } } } }
/** * @dataProvider buildFormProvider * * @param array $configValue * @param null|Integration $data * @param array $expectedChoices */ public function testBuildForm($configValue, $data, $expectedChoices) { $this->settingsProvider->expects($this->any())->method('getSourceIntegrationTypes')->will($this->returnValue($configValue)); $form = $this->factory->create('oro_integration_channel_form'); $form->setData($data); $this->assertEquals($expectedChoices, $form->get('type')->getConfig()->getOption('choices')); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { if (!$options['disable_customer_datasource_types']) { return; } $builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { /** @var Integration $data */ $data = $event->getData(); $form = $event->getForm(); if ($data === null) { return; } // Remove integration types that could be created only in scope of the channel // if type is already set, then keep choice list as is $sourceTypes = $this->settingsProvider->getSourceIntegrationTypes(); if (!in_array($data->getType(), $sourceTypes)) { $field = $form->get('type'); $config = $field->getConfig()->getOptions(); foreach ($sourceTypes as $sourceType) { unset($config['choices'][$sourceType]); } FormUtils::replaceField($form, 'type', ['choices' => $config['choices']], ['choice_list']); } }, 100); }
public function setUp() { $this->builder = $this->getMockBuilder('Symfony\\Component\\Form\\FormBuilder')->disableOriginalConstructor()->getMock(); $this->settingsProvider = $this->getMockBuilder('OroCRM\\Bundle\\ChannelBundle\\Provider\\SettingsProvider')->disableOriginalConstructor()->getMock(); $this->channelTypeSubscriber = $this->getMockBuilder('OroCRM\\Bundle\\ChannelBundle\\Form\\EventListener\\ChannelTypeSubscriber')->disableOriginalConstructor()->getMock(); $this->settingsProvider->expects($this->any())->method('getSettings')->will($this->returnValue([])); $this->type = new ChannelType($this->settingsProvider, $this->channelTypeSubscriber); }
public function setUp() { $this->settingsProvider = $this->getMockBuilder('OroCRM\\Bundle\\ChannelBundle\\Provider\\SettingsProvider')->disableOriginalConstructor()->getMock(); $this->settingsProvider->expects($this->once())->method('getSettings')->will($this->returnValue($this->testConfig)); $this->entityProvider = $this->getMockBuilder('Oro\\Bundle\\EntityBundle\\Provider\\EntityProvider')->disableOriginalConstructor()->getMock(); $this->configManager = $this->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Config\\ConfigManager')->disableOriginalConstructor()->getMock(); $this->router = $this->getMockBuilder('Symfony\\Component\\Routing\\RouterInterface')->disableOriginalConstructor()->getMock(); }
/** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventSubscriber($this->channelTypeSubscriber); $builder->add('name', 'text', ['required' => true, 'label' => 'orocrm.channel.name.label']); $builder->add('entities', 'orocrm_channel_entities'); $builder->add('channelType', 'genemu_jqueryselect2_choice', ['choices' => $this->settingsProvider->getChannelTypeChoiceList(), 'required' => true, 'label' => 'orocrm.channel.channel_type.label', 'configs' => ['placeholder' => 'orocrm.channel.form.select_channel_type.label']]); $builder->add('status', 'choice', ['choices' => [Channel::STATUS_INACTIVE => 'orocrm.channel.inactive.label', Channel::STATUS_ACTIVE => 'orocrm.channel.active.label'], 'required' => true, 'label' => 'orocrm.channel.status.label']); }
/** * @dataProvider exclusionProvider * * @param bool $expected * @param bool $isChannelEntity * @param array $dependentDataMap * @param array $enabledEntityMap */ public function testIsRelationExcluded($expected, $isChannelEntity, $dependentDataMap = [], $enabledEntityMap = []) { $this->settingsProvider->expects($this->any())->method('isChannelEntity')->will($this->returnValueMap([[self::TEST_MAIN_ENTITY_NAME, true], [self::TEST_ENTITY_NAME, $isChannelEntity]])); $this->settingsProvider->expects($this->any())->method('getDependentEntityData')->will($this->returnValueMap($dependentDataMap)); $this->stateProvider->expects($this->any())->method('isEntityEnabled')->will($this->returnValueMap($enabledEntityMap)); $classMetadataMock = $this->getMockBuilder('Doctrine\\ORM\\Mapping\\ClassMetadata')->disableOriginalConstructor()->getMock(); $classMetadataMock->expects($this->once())->method('getName')->will($this->returnValue(self::TEST_MAIN_ENTITY_NAME)); $classMetadataMock->expects($this->once())->method('getAssociationTargetClass')->with($this->equalTo(self::TEST_ASSOC_NAME))->will($this->returnValue(self::TEST_ENTITY_NAME)); $this->assertSame($expected, $this->exclusionProvider->isIgnoredRelation($classMetadataMock, self::TEST_ASSOC_NAME)); }
/** * @param SettingsProvider $settingsProvider * @param string $integrationType * * @return bool|string */ protected function getChannelTypeForIntegration(SettingsProvider $settingsProvider, $integrationType) { $channelTypeConfigs = $settingsProvider->getSettings(SettingsProvider::CHANNEL_TYPE_PATH); foreach ($channelTypeConfigs as $channelTypeName => $config) { if ($settingsProvider->getIntegrationType($channelTypeName) == $integrationType) { return $channelTypeName; } } return false; }
protected function prepareEvent() { $this->entity->setEntities(['OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1', 'OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2']); $this->event->expects($this->atLeastOnce())->method('getChannel')->will($this->returnValue($this->entity)); $this->settingProvider->expects($this->at(0))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1')->will($this->returnValue('TestConnector1')); $this->settingProvider->expects($this->at(1))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2')->will($this->returnValue('TestConnector2')); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('persist')->with($this->integration); $this->em->expects($this->once())->method('flush'); }
/** * @param array $entities * * @return array */ protected function getConnectors(array $entities) { $result = []; foreach ($entities as $entity) { $connectorName = $this->settingsProvider->getIntegrationConnectorName($entity); if (!empty($connectorName)) { array_push($result, $connectorName); } } return $result; }
/** * @param Channel $channel */ protected function validateIntegration(Channel $channel) { $errorLabel = 'orocrm.channel.form.integration_invalid.label'; $field = 'dataSource'; $integrationType = $this->provider->getIntegrationType($channel->getChannelType()); if (!empty($integrationType)) { $integration = $channel->getDataSource(); if (empty($integration)) { $this->context->addViolationAt($field, $errorLabel); } } }
/** * @return array */ protected function getChannelEntities() { $customEntities = $this->configManager->getProvider('extend')->map(function (ConfigInterface $extendConfig) { $isCustom = $extendConfig->is('is_extend') && $extendConfig->get('owner') === ExtendScope::OWNER_CUSTOM && $extendConfig->in('state', [ExtendScope::STATE_ACTIVE, ExtendScope::STATE_UPDATED]); return $isCustom ? $extendConfig->getId()->getClassName() : false; }); $customEntities = array_filter($customEntities); $entities = array_map(function ($setting) { return $setting['name']; }, $this->settings->getSettings(SettingsProvider::DATA_PATH)); return array_unique(array_merge($customEntities, $entities)); }
public function testOnChannelSucceedSave() { $this->entity->setEntities(['OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1', 'OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2']); $this->event->expects($this->once())->method('getChannel')->will($this->returnValue($this->entity)); $this->settingProvider->expects($this->at(0))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity1')->will($this->returnValue('TestConnector1')); $this->settingProvider->expects($this->at(1))->method('getIntegrationConnectorName')->with('OroCRM\\Bundle\\AcmeBundle\\Entity\\TestEntity2')->will($this->returnValue('TestConnector2')); $this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->em)); $this->em->expects($this->once())->method('persist')->with($this->integration); $this->em->expects($this->once())->method('flush'); $channelSaveSucceedListener = new ChannelSaveSucceedListener($this->settingProvider, $this->registry); $channelSaveSucceedListener->onChannelSucceedSave($this->event); $this->assertEquals($this->integration->getConnectors(), ['TestConnector1', 'TestConnector2']); }
/** * @param string $entityFQCN entity full class name * * @return bool */ protected function isIncludedByChannels($entityFQCN) { if ($this->settingsProvider->isChannelEntity($entityFQCN)) { return $this->stateProvider->isEntityEnabled($entityFQCN); } elseif ($this->settingsProvider->isDependentOnChannelEntity($entityFQCN)) { $enabled = false; $dependencies = $this->settingsProvider->getDependentEntityData($entityFQCN); foreach ($dependencies as $entityName) { $enabled |= $this->stateProvider->isEntityEnabled($entityName); } return $enabled; } return true; }
/** * Returns built channel * * @SuppressWarnings(PHPMD.NPathComplexity) * * @return Channel */ public function getChannel() { $type = $this->getDefaultType(); $name = $this->getDefaultName($type); $identity = $this->settingsProvider->getCustomerIdentityFromConfig($type); if ($this->populateEntities) { $this->entities = $this->settingsProvider->getEntitiesByChannelType($type); } $this->addEntity($identity, true); $owner = $this->owner; if (!$owner) { $owner = $this->getDefaultOrganization(); } $this->channel->setChannelType($type); $this->channel->setName($name); $this->channel->setOwner($owner); $this->channel->setCustomerIdentity($identity); $this->channel->setEntities($this->entities); $this->channel->setStatus($this->status); $this->channel->setDataSource($this->dataSource); if (null !== $this->createdAt) { // set created at only whn not nullable, otherwise update scenario will fail $this->channel->setCreatedAt($this->createdAt); } return $this->channel; }
/** * @dataProvider validItemsDataProvider * * @param boolean $isValid * @param null|Integration $integration */ public function testValidateValid($isValid, $integration) { $channel = $this->getMockBuilder('OroCRM\\Bundle\\ChannelBundle\\Entity\\Channel')->disableOriginalConstructor()->getMock(); $context = $this->getMockBuilder('Symfony\\Component\\Validator\\ExecutionContext')->disableOriginalConstructor()->getMock(); $channel->expects($this->once())->method('getChannelType'); $channel->expects($this->once())->method('getDataSource')->will($this->returnValue($integration)); $this->provider->expects($this->once())->method('getIntegrationType')->will($this->returnValue('testType')); if ($isValid) { $context->expects($this->never())->method('addViolationAt'); } else { $context->expects($this->once())->method('addViolationAt'); } $constraint = new ChannelIntegrationConstraint(); $validator = new ChannelIntegrationConstraintValidator($this->provider); $validator->initialize($context); $validator->validate($channel, $constraint); }
/** * @dataProvider formDataProviderForPreSet * * @param Channel|null $formData * @param string $channelType */ public function testPreSet($formData, $channelType) { $events = $this->subscriber->getSubscribedEvents(); $this->assertArrayHasKey(FormEvents::PRE_SET_DATA, $events); $this->assertEquals($events[FormEvents::PRE_SET_DATA], 'preSet'); $form = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $fieldMock = $this->getMock('Symfony\\Component\\Form\\Test\\FormInterface'); $configMock = $this->getMock('Symfony\\Component\\Form\\FormConfigInterface'); if ($formData) { $form->expects($this->any())->method('get')->will($this->returnValue($fieldMock)); $fieldMock->expects($this->any())->method('getConfig')->will($this->returnValue($configMock)); $formData->expects($this->exactly(5))->method('getChannelType')->will($this->returnValue($channelType)); $this->settingsProvider->expects($this->once())->method('getIntegrationType')->will($this->returnValue($channelType)); } $event = new FormEvent($form, $formData); $event->setData($formData); $this->subscriber->preSet($event); }
/** * @param SettingsProvider $settingsProvider */ protected function createChannelsForIntegrations(SettingsProvider $settingsProvider) { // create channels for integrations $types = $settingsProvider->getSourceIntegrationTypes(); $integrations = $this->em->getRepository('OroIntegrationBundle:Channel')->findBy(['type' => $types]); /** @var Integration $integration */ foreach ($integrations as $integration) { $builder = $this->container->get('orocrm_channel.builder.factory')->createBuilderForIntegration($integration); $builder->setOwner($integration->getOrganization()); $builder->setDataSource($integration); $builder->setStatus($integration->getEnabled() ? Channel::STATUS_ACTIVE : Channel::STATUS_INACTIVE); $builder->setName($integration->getName() . ' channel'); $channel = $builder->getChannel(); $this->em->persist($builder->getChannel()); $this->em->flush(); foreach ($channel->getEntities() as $entity) { $this->fillChannelToEntity($channel, $entity); } } }
/** * Warm up local data cache in order to prevent multiple queries to DB */ protected function ensureLocalCacheWarmed() { if ($this->enabledEntities === null) { if (false !== ($data = $this->tryCacheLookUp())) { $this->enabledEntities = $data; return; } $settings = $this->settingsProvider->getSettings(SettingsProvider::DATA_PATH); $qb = $this->getManager()->createQueryBuilder(); $qb->distinct(true); $qb->select('e.name')->from('OroCRMChannelBundle:Channel', 'c')->andWhere('c.status = :status')->setParameter('status', Channel::STATUS_ACTIVE)->innerJoin('c.entities', 'e'); $assignedEntityNames = $qb->getQuery()->getArrayResult(); $assignedEntityNames = array_map(function ($result) { return $result['name']; }, $assignedEntityNames); $this->enabledEntities = []; foreach ($settings as $entityName => $singleEntitySettings) { if (in_array($entityName, $assignedEntityNames, true)) { $this->enabledEntities[$entityName] = true; } } $this->persistToCache(); } }
/** * Returns built channel * * @SuppressWarnings(PHPMD.NPathComplexity) * * @return Channel */ public function getChannel() { $type = $this->getDefaultType(); $name = $this->getDefaultName($type); $identity = $this->settingsProvider->getCustomerIdentityFromConfig($type); if ($this->populateEntities) { $this->entities = $this->settingsProvider->getEntitiesByChannelType($type); } $this->addEntity($identity, true); $owner = $this->owner; if (!$owner) { $owner = $this->getDefaultOrganization(); } $this->channel->setChannelType($type); $this->channel->setName($name); $this->channel->setOwner($owner); $this->channel->setCustomerIdentity($identity); $this->channel->setEntities($this->entities); $this->channel->setStatus($this->status); $this->channel->setDataSource($this->dataSource); return $this->channel; }
/** * @return string */ protected function getFirstChannelType() { $channelTypes = $this->settingsProvider->getChannelTypeChoiceList(); reset($channelTypes); return (string) key($channelTypes); }
/** * {@inheritdoc} */ public function getIdentityTarget() { return $this->settingsProvider->getCustomerIdentityFromConfig(ChannelType::TYPE); }
/** * {@inheritdoc} */ public function isIgnoredEntity($className) { return !$this->settingsProvider->isChannelEntity($className); }
/** * @dataProvider exclusionProvider * * @param bool $expected * @param bool $isChannelEntity * @param bool $belongsToIntegration */ public function testIsEntityExcluded($expected, $isChannelEntity, $belongsToIntegration) { $this->settingsProvider->expects($this->any())->method('isChannelEntity')->with($this->equalTo(self::TEST_ENTITY_NAME))->will($this->returnValue($isChannelEntity)); $this->settingsProvider->expects($this->any())->method('belongsToIntegration')->with($this->equalTo(self::TEST_ENTITY_NAME))->will($this->returnValue($belongsToIntegration)); $this->assertSame($expected, $this->exclusionProvider->isIgnoredEntity(self::TEST_ENTITY_NAME)); }
public function testGetChannelTypeMetadata() { $expectedResult = new \stdClass(); $this->provider->expects($this->once())->method('getChannelTypeMetadata')->will($this->returnValue($expectedResult)); $this->assertSame($expectedResult, $this->extension->getChannelTypeMetadata()); }