Пример #1
0
 public function testTransportRelation()
 {
     $transport = $this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $this->assertAttributeEmpty('transport', $this->entity);
     $this->entity->setTransport($transport);
     $this->assertSame($transport, $this->entity->getTransport());
     $this->entity->clearTransport();
     $this->assertAttributeEmpty('transport', $this->entity);
 }
Пример #2
0
 public function testProcessGoodScenario()
 {
     $testWebsiteId = 1;
     $testStoreId = 2;
     $testStoresArray = new \ArrayIterator([['website_id' => $testWebsiteId, 'store_id' => $testStoreId]]);
     $settingBag = new ParameterBag(['website_id' => $testWebsiteId]);
     $testData = [['id' => 1, 'originId' => 11], ['id' => 2, 'originId' => 22], ['id' => 3, 'originId' => 33]];
     $testExistedCarts = [(object) ['entity_id' => 22]];
     $repo = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\Repository\\CartRepository')->disableOriginalConstructor()->getMock();
     $this->em->expects($this->any())->method('getRepository')->with('OroCRMMagentoBundle:Cart')->will($this->returnValue($repo));
     $transport = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport')->setMethods(['getSettingsBag'])->getMockForAbstractClass();
     $transport->expects($this->any())->method('getSettingsBag')->will($this->returnValue($settingBag));
     $realTransport = $this->getMock('OroCRM\\Bundle\\MagentoBundle\\Provider\\Transport\\MagentoTransportInterface');
     $realTransport->expects($this->once())->method('isSupportedExtensionVersion')->will($this->returnValue(true));
     $realTransport->expects($this->once())->method('getStores')->will($this->returnValue($testStoresArray));
     $this->helper->expects($this->once())->method('getTransport')->will($this->returnValue($realTransport));
     $channel = new Channel();
     $channel->setTransport($transport);
     $realTransport->expects($this->at(3))->method('call')->with(SoapTransport::ACTION_ORO_CART_LIST, ['filters' => ['complex_filter' => [['key' => 'store_id', 'value' => ['key' => 'in', 'value' => $testStoreId]], ['key' => 'entity_id', 'value' => ['key' => 'in', 'value' => '11,22']]]], 'pager' => ['page' => 1, 'pageSize' => self::BATCH_SIZE]])->will($this->returnValue($testExistedCarts));
     $realTransport->expects($this->at(4))->method('call')->with(SoapTransport::ACTION_ORO_CART_LIST, ['filters' => ['complex_filter' => [['key' => 'store_id', 'value' => ['key' => 'in', 'value' => $testStoreId]], ['key' => 'entity_id', 'value' => ['key' => 'in', 'value' => '33']]]], 'pager' => ['page' => 1, 'pageSize' => self::BATCH_SIZE]])->will($this->returnValue([]));
     $repo->expects($this->once())->method('getCartsByChannelIdsIterator')->with($channel)->will($this->returnValue($testData));
     $repo->expects($this->at(1))->method('markExpired')->with([1]);
     $repo->expects($this->at(2))->method('markExpired')->with([3]);
     $this->processor->process($channel);
 }
 public function testGetChannelFromContext()
 {
     $testID = 1;
     $integration = new Integration();
     $integration->setTransport($this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport'));
     $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface');
     $context->expects($this->once())->method('getOption')->with('channel')->will($this->returnValue($testID));
     $this->repo->expects($this->once())->method('getOrLoadById')->with($testID)->will($this->returnValue($integration));
     $result = $this->contextMediator->getChannel($context);
     $this->assertEquals($integration, $result);
 }
Пример #4
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $om)
 {
     $this->organization = $this->getReference('default_organization');
     $this->users = $om->getRepository('OroUserBundle:User')->findAll();
     $website = new Website();
     $website->setCode('admin')->setName('Admin');
     $om->persist($website);
     $store = new Store();
     $store->setCode('admin')->setName('Admin')->setWebsite($website);
     $om->persist($store);
     $transport = new MagentoSoapTransport();
     $transport->setApiUser('api_user');
     $transport->setApiKey('api_key');
     $transport->setExtensionVersion(SoapTransport::REQUIRED_EXTENSION_VERSION);
     $transport->setIsExtensionInstalled(true);
     $transport->setMagentoVersion('1.9.1.0');
     $transport->setWsdlUrl('http://magento.domain');
     $om->persist($transport);
     $integration = new Integration();
     $integration->setType('magento');
     $integration->setConnectors(['customer', 'cart', 'order', 'newsletter_subscriber']);
     $integration->setName(self::INTEGRATION_NAME);
     $integration->setTransport($transport);
     $integration->setOrganization($this->organization);
     $om->persist($integration);
     $builder = $this->factory->createBuilderForIntegration($integration);
     $builder->setOwner($integration->getOrganization());
     $builder->setDataSource($integration);
     $builder->setStatus($integration->isEnabled() ? Channel::STATUS_ACTIVE : Channel::STATUS_INACTIVE);
     $this->dataChannel = $builder->getChannel();
     $om->persist($this->dataChannel);
     $group = new CustomerGroup();
     $group->setName('General');
     $group->setOriginId(15000);
     $group->setChannel($integration);
     $om->persist($group);
     $om->flush();
     $this->persistDemoCustomers($om, $website, $store, $group, $integration);
     $om->flush();
     $this->persistDemoCarts($om, $store, $integration);
     $om->flush();
     $this->persistDemoOrders($om, $store, $integration);
     $om->flush();
     $this->persistDemoRFM($om);
     $om->flush();
 }
Пример #5
0
 /**
  * @dataProvider initializationDataProvider
  *
  * @param \PHPUnit_Framework_MockObject_MockObject|mixed $transport
  * @param null                                           $source
  * @param bool|string                                    $expectedException
  */
 public function testInitialization($transport, $source = null, $expectedException = false)
 {
     $logger = new LoggerStrategy(new NullLogger());
     $contextRegistry = new ContextRegistry();
     $contextMediatorMock = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Provider\\ConnectorContextMediator')->disableOriginalConstructor()->getMock();
     $integration = new Integration();
     $integration->setTransport($this->transportSettings);
     $context = $contextRegistry->getByStepExecution($this->stepExecutionMock);
     $contextMediatorMock->expects($this->at(0))->method('getTransport')->with($this->equalTo($context))->will($this->returnValue($transport));
     $contextMediatorMock->expects($this->at(1))->method('getChannel')->with($this->equalTo($context))->will($this->returnValue($integration));
     $connector = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Provider\\AbstractConnector')->setMethods(['getConnectorSource'])->setConstructorArgs([$contextRegistry, $logger, $contextMediatorMock])->getMockForAbstractClass();
     if (false !== $expectedException) {
         $this->setExpectedException($expectedException);
     } else {
         $transport->expects($this->once())->method('init')->with($this->equalTo($this->transportSettings));
         $connector->expects($this->once())->method('getConnectorSource')->will($this->returnValue($source));
     }
     $connector->setStepExecution($this->stepExecutionMock);
     $this->assertAttributeSame($transport, 'transport', $connector);
     $this->assertAttributeSame($integration, 'channel', $connector);
 }
 public function testGetInitializedTransport()
 {
     $testTransport = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Provider\\TransportInterface');
     $transportEntity = $this->getMockForAbstractClass('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $integration = new Integration();
     $integration->setTransport($transportEntity);
     $this->registry->expects($this->once())->method('getTransportTypeBySettingEntity')->will($this->returnValue($testTransport));
     $testTransport->expects($this->once())->method('init')->with($transportEntity);
     $result = $this->contextMediator->getInitializedTransport($integration);
     $this->assertEquals($testTransport, $result);
     // test local cache
     $this->contextMediator->getInitializedTransport($integration);
 }
Пример #7
0
 /**
  * @return $this
  */
 protected function createIntegration()
 {
     $integration = new Integration();
     $integration->setName('Demo Web store');
     $integration->setType('magento');
     $integration->setConnectors(["customer", "order", "cart", "region"]);
     $integration->setTransport($this->transport);
     $integration->setOrganization($this->organization);
     $this->em->persist($integration);
     $this->integration = $integration;
     return $this;
 }
Пример #8
0
 /**
  * @return $this
  */
 protected function createIntegration()
 {
     $integration = new Integration();
     $integration->setName('Demo Web store');
     $integration->setType('magento');
     $integration->setConnectors(['customer', 'order', 'cart']);
     $integration->setTransport($this->transport);
     $integration->setOrganization($this->organization);
     $synchronizationSettings = Object::create(['isTwoWaySyncEnabled' => true]);
     $integration->setSynchronizationSettings($synchronizationSettings);
     $this->em->persist($integration);
     $this->integration = $integration;
     return $this;
 }
Пример #9
0
 public function testUpdateAddress()
 {
     $transportSetting = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $channel = new Channel();
     $channel->setTransport($transportSetting);
     $channel->getSynchronizationSettingsReference()->offsetSet('syncPriority', TwoWaySyncConnectorInterface::LOCAL_WINS);
     $customer = new Customer();
     $customer->setOriginId(self::TEST_CUSTOMER_ID);
     $customer->setChannel($channel);
     $customer->setFirstName(self::TEST_CUSTOMER_FIRSTNAME);
     $customer->setLastName(self::TEST_CUSTOMER_LASTNAME);
     $contactAddress = new ContactAddress();
     $address = new Address();
     $address->setFirstName(self::TEST_FIRSTNAME);
     $address->setCountry(new Country(self::TEST_ADDRESS_COUNTRY));
     $address->setRegionText(self::TEST_ADDRESS_REGION);
     $address->setStreet(self::TEST_ADDRESS_STREET);
     $address->setContactAddress($contactAddress);
     $address->setOriginId(1);
     $this->transport->expects($this->once())->method('init');
     $this->regionConverter->expects($this->once())->method('toMagentoData')->with($this->identicalTo($address))->will($this->returnValue(['region' => self::TEST_ADDRESS_REGION_RESOLVED, 'region_id' => null]));
     $this->transport->expects($this->at(2))->method('getCustomerAddresses')->with($this->identicalTo($customer))->will($this->returnValue([(object) ['customer_address_id' => 1, 'telephone' => '911', 'middlename' => 'testMiddleName', 'suffix' => 'testSuffix', 'company' => 'testCompany', 'city' => 'testCity', 'is_default_shipping' => false, 'is_default_billing' => false]]));
     $this->transport->expects($this->at(3))->method('call')->with($this->equalTo(SoapTransport::ACTION_CUSTOMER_ADDRESS_UPDATE), $this->equalTo(['addressId' => 1, 'addressData' => ['prefix' => null, 'firstname' => 'newName', 'middlename' => null, 'lastname' => 'newLastName', 'suffix' => null, 'company' => null, 'street' => [0 => self::TEST_ADDRESS_STREET, 1 => null], 'city' => null, 'postcode' => null, 'country_id' => self::TEST_ADDRESS_COUNTRY, 'region' => self::TEST_ADDRESS_REGION_RESOLVED, 'region_id' => null, 'created_at' => null, 'updated_at' => null, 'is_default_billing' => false, 'is_default_shipping' => false, 'telephone' => 'no phone']]))->will($this->returnValue(true));
     $this->em->expects($this->atLeastOnce())->method('persist');
     $this->em->expects($this->once())->method('flush');
     $data = [];
     array_push($data, (object) ['entity' => $customer, 'object' => ['addresses' => [['entity' => $address, 'status' => AbstractReverseProcessor::UPDATE_ENTITY, 'object' => ['firstname' => 'newName', 'lastname' => 'newLastName']]]]]);
     $this->writer->write($data);
 }