public function testProcess() { $customer = new Customer(); $customer->setOriginId(1); $transport = $this->getMockBuilder('OroCRM\\Bundle\\MagentoBundle\\Entity\\MagentoSoapTransport')->disableOriginalConstructor()->getMock(); $transport->expects($this->once())->method('getIsExtensionInstalled')->will($this->returnValue(true)); $channel = $this->getMockBuilder('Oro\\Bundle\\IntegrationBundle\\Entity\\Channel')->disableOriginalConstructor()->getMock(); $channel->expects($this->once())->method('getTransport')->will($this->returnValue($transport)); $order = new Order(); $cart = new Cart(); $cart->setOriginId(1); $order->setCustomer($customer); $order->setChannel($channel); $order->setCart($cart); $this->databaseHelper->expects($this->once())->method('findOneByIdentity')->with($channel)->will($this->returnValue($channel)); $strategy = $this->getStrategy(); $execution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext'); $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($execution)); $strategy->setStepExecution($this->stepExecution); $orderItemDate = ['customerId' => uniqid()]; /** @var \PHPUnit_Framework_MockObject_MockObject|ContextInterface $context */ $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $context->expects($this->once())->method('getValue')->will($this->returnValue($orderItemDate)); $strategy->setImportExportContext($context); $execution->expects($this->exactly(3))->method('get')->with($this->isType('string')); $execution->expects($this->exactly(3))->method('put')->with($this->isType('string'), $this->isType('array')); $this->assertNull($strategy->process($order)); }
public function testProcessLoadCustomer() { /** @var NewsletterSubscriber $newsletterSubscriber */ $newsletterSubscriber = $this->getReference('newsletter_subscriber2'); $customer = new Customer(); $originId = time(); $customer->setOriginId($originId); $newsletterSubscriber->setCustomer($customer); $this->strategy->setEntityName(get_class($newsletterSubscriber)); $this->assertEquals(null, $this->strategy->process($newsletterSubscriber)); $this->assertNotEmpty($this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessSubscribers')); $this->assertEquals([$originId], $this->stepExecution->getJobExecution()->getExecutionContext()->get('postProcessCustomerIds')); }
/** * @param array $item * @param Customer $entity */ protected function writeNewItem(array $item, Customer $entity) { try { $customerId = $this->transport->createCustomer($item); $entity->setOriginId($customerId); $this->stateHandler->markCustomerSynced($entity); $this->stateHandler->markAddressesForSync($entity); $this->logger->info(sprintf('Customer with id %s successfully created with data %s', $customerId, json_encode($item))); $entity->setCreatedAt(new \DateTime('now', new \DateTimeZone('UTC'))); $entity->setUpdatedAt($entity->getCreatedAt()); } catch (\Exception $e) { $this->logger->error($e->getMessage()); $this->stepExecution->addFailureException($e); } }
/** * @return array */ public function itemsProvider() { $order1 = new Order(); $order2 = new Order(); $order1->setIncrementId('1111'); $order2->setIncrementId('2222'); $order3 = clone $order1; $cart1 = new Cart(); $cart2 = new Cart(); $cart1->setOriginId(1111); $cart2->setOriginId(2222); $cart3 = clone $cart1; $customer1 = new Customer(); $customer1->setOriginId(111); $customer2 = clone $customer1; $someEntity = new \stdClass(); $someEntity2 = new \stdClass(); return ['should skip non-unique orders' => ['$items' => [$order1, $order2, $order3], '$expectedItems' => [$order3->getIncrementId() => $order3, $order2->getIncrementId() => $order2]], 'should skip non-unique carts' => ['$items' => [$cart1, $cart2, $cart3], '$expectedItems' => [$cart3->getOriginId() => $cart3, $cart2->getOriginId() => $cart2]], 'should skip non-unique customers' => ['$items' => [$customer1, $customer2], '$expectedItems' => [$customer2->getOriginId() => $customer2]], 'should not break logic with entities that not consist originId' => ['$items' => [$someEntity, $someEntity2], '$expectedItems' => [$someEntity, $someEntity2]]]; }
public function testProcess() { $customer = new Customer(); $customer->setOriginId(1); $channel = new Channel(); $cart = new Cart(); $cart->setCustomer($customer)->setChannel($channel)->setItemsCount(2)->setEmail('*****@*****.**'); $strategy = $this->getStrategy(); $execution = $this->getMock('Akeneo\\Bundle\\BatchBundle\\Item\\ExecutionContext'); $this->jobExecution->expects($this->any())->method('getExecutionContext')->will($this->returnValue($execution)); $strategy->setStepExecution($this->stepExecution); $cartItem = ['customerId' => uniqid()]; /** @var \PHPUnit_Framework_MockObject_MockObject|ContextInterface $context */ $context = $this->getMock('Oro\\Bundle\\ImportExportBundle\\Context\\ContextInterface'); $context->expects($this->once())->method('getValue')->will($this->returnValue($cartItem)); $strategy->setImportExportContext($context); $execution->expects($this->exactly(2))->method('get')->with($this->isType('string')); $execution->expects($this->exactly(2))->method('put')->with($this->isType('string'), $this->isType('array')); $this->assertNull($strategy->process($cart)); }
/** * @param array $data * * @dataProvider dataProvider */ public function testRead(array $data) { $this->executionContext->expects($this->once())->method('get')->will($this->returnCallback(function ($key) use($data) { if (empty($data[$key])) { return null; } return $data[$key]; })); $originId = 123; $expectedData = new Customer(); $expectedData->setOriginId($originId); $this->context->expects($this->any())->method('getConfiguration')->will($this->returnValue(['data' => $expectedData])); $this->transport->expects($this->once())->method('getCustomerInfo')->will($this->returnCallback(function ($customerId) { return ['origin_id' => $customerId, 'group_id' => 0, 'store_id' => 0, 'website_id' => 0]; })); $address = ['zip' => uniqid()]; $this->transport->expects($this->once())->method('getCustomerAddresses')->will($this->returnValue([$address])); $reader = $this->getReader(); $reader->setStepExecution($this->stepExecutionMock); $this->assertEquals(['origin_id' => $originId, 'group_id' => 0, 'store_id' => 0, 'website_id' => 0, 'addresses' => [['zip' => $address['zip']]]], $reader->read()); $this->assertNull($reader->read()); }
/** * @param $oid * @param Account $account * @param MagentoAddress $address * * @return Customer */ protected function createCustomer($oid, Account $account, MagentoAddress $address) { $customer = new Customer(); $customer->setChannel($this->integration); $customer->setDataChannel($this->channel); $customer->setFirstName('John'); $customer->setLastName('Doe'); $customer->setEmail('*****@*****.**'); $customer->setOriginId($oid); $customer->setIsActive(true); $customer->setWebsite($this->website); $customer->setStore($this->store); $customer->setAccount($account); $customer->setGender(Gender::MALE); $customer->setGroup($this->customerGroup); $customer->setCreatedAt(new \DateTime('now')); $customer->setUpdatedAt(new \DateTime('now')); $customer->addAddress($address); $customer->setOwner($this->getUser()); $customer->setOrganization($this->organization); $this->em->persist($customer); return $customer; }
/** * @param $oid * @param Account $account * @param MagentoAddress $address * * @return Customer */ protected function createCustomer($oid, Account $account, MagentoAddress $address) { $customer = new Customer(); $customer->setChannel($this->integration); $customer->setDataChannel($this->channel); $customer->setFirstName('John'); $customer->setLastName('Doe'); $customer->setEmail('*****@*****.**'); $customer->setOriginId($oid); $customer->setIsActive(true); $customer->setWebsite($this->website); $customer->setStore($this->store); $customer->setAccount($account); $customer->setGender(Gender::MALE); $customer->setGroup($this->customerGroup); // TODO: DateTimeZones should be removed in BAP-8710. Tests should be passed for: // - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\CustomerControllerTest // - OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller\Api\Rest\MagentoCustomerControllerTest $customer->setCreatedAt(new \DateTime('now', new \DateTimezone('UTC'))); $customer->setUpdatedAt(new \DateTime('now', new \DateTimezone('UTC'))); $customer->addAddress($address); $customer->setOwner($this->getUser()); $customer->setOrganization($this->organization); $this->em->persist($customer); return $customer; }
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); }