/**
  * @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'));
 }
Exemple #2
0
 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();
 }
 /**
  * @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));
 }
 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');
 }
 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']);
 }
 /**
  * @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);
 }
 public function testGetChannelTypeMetadata()
 {
     $expectedResult = new \stdClass();
     $this->provider->expects($this->once())->method('getChannelTypeMetadata')->will($this->returnValue($expectedResult));
     $this->assertSame($expectedResult, $this->extension->getChannelTypeMetadata());
 }
 /**
  * @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));
 }