Пример #1
0
 /**
  * @dataProvider addressTypesUpdateDataProvider
  *
  * @param string          $priority
  * @param ArrayCollection $remoteTypes
  * @param ArrayCollection $localTypes
  * @param ArrayCollection $contactTypes
  * @param array           $expectedTypeNames
  */
 public function testAddressTypesUpdate($priority, ArrayCollection $remoteTypes, ArrayCollection $localTypes, ArrayCollection $contactTypes, array $expectedTypeNames)
 {
     $channel = new Channel();
     $channel->getSynchronizationSettingsReference()->offsetSet('syncPriority', $priority);
     $testCountry = new Country('US');
     $contact = new Contact();
     $contactAddress = new ContactAddress();
     $contactAddress->setId(self::TEST_CONTACT_ADDRESS_ID);
     $contactAddress->setTypes($contactTypes);
     $contactAddress->setCountry($testCountry);
     $contact->addAddress($contactAddress);
     $phone = new ContactPhone();
     $phone->setPhone('123-123-123');
     $phone->setOwner($contact);
     $contact->addPhone($phone);
     $localCustomer = new Customer();
     $localAddress = new Address();
     $localAddress->setContactAddress($contactAddress);
     $localAddress->setTypes($localTypes);
     $localAddress->setCountry($testCountry);
     $localAddress->setPhone('123-123-123');
     $localAddress->setContactPhone($phone);
     $localCustomer->addAddress($localAddress);
     $remoteCustomer = new Customer();
     $remoteAddress = new Address();
     $remoteAddress->setContactAddress($contactAddress);
     $remoteAddress->setTypes($remoteTypes);
     $remoteAddress->setCountry($testCountry);
     $remoteAddress->setContactPhone($phone);
     $remoteCustomer->addAddress($remoteAddress);
     $helper = $this->getHelper($channel);
     $helper->merge($remoteCustomer, $localCustomer, $contact);
     $this->assertCount(1, $contact->getAddresses());
     $this->assertEquals($expectedTypeNames, $contactAddress->getTypeNames());
 }
Пример #2
0
 public function testOwner()
 {
     $contact = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock();
     $address = new ContactAddress();
     $address->setOwner($contact);
     $this->assertSame($contact, $address->getOwner());
 }
Пример #3
0
 /**
  * @param Contact $contact
  * @param ContactAddress $address
  * @return array
  * @throws BadRequestHttpException
  */
 protected function update(Contact $contact, ContactAddress $address)
 {
     $responseData = array('saved' => false, 'contact' => $contact);
     if ($this->getRequest()->getMethod() == 'GET' && !$address->getId()) {
         $address->setFirstName($contact->getFirstName());
         $address->setLastName($contact->getLastName());
         if (!$contact->getAddresses()->count()) {
             $address->setPrimary(true);
         }
     }
     if ($address->getOwner() && $address->getOwner()->getId() != $contact->getId()) {
         throw new BadRequestHttpException('Address must belong to contact');
     } elseif (!$address->getOwner()) {
         $contact->addAddress($address);
     }
     // Update contact's modification date when an address is changed
     $contact->setUpdatedAt(new \DateTime('now', new \DateTimeZone('UTC')));
     if ($this->get('orocrm_contact.form.handler.contact_address')->process($address)) {
         $this->getDoctrine()->getManager()->flush();
         $responseData['entity'] = $address;
         $responseData['saved'] = true;
     }
     $responseData['form'] = $this->get('orocrm_contact.contact_address.form')->createView();
     return $responseData;
 }
Пример #4
0
 /**
  * @param string $key
  * @param ContactAddress $entity
  */
 public function fillEntityData($key, $entity)
 {
     $typeRepository = $this->templateManager->getEntityRepository('Oro\\Bundle\\AddressBundle\\Entity\\AddressType');
     $billingType = $typeRepository->getEntity(AddressType::TYPE_BILLING);
     $shippingType = $typeRepository->getEntity(AddressType::TYPE_SHIPPING);
     switch ($key) {
         case 'Jerry Coleman':
             $entity->addType($billingType)->addType($shippingType);
             break;
         case 'John Smith':
             $entity->addType($billingType);
             break;
         case 'John Doo':
             $entity->addType($shippingType);
             break;
     }
     parent::fillEntityData($key, $entity);
 }
Пример #5
0
 /**
  * Create a Contact
  *
  * @param array $data
  * @param int $iteration
  * @return Contact
  */
 private function createContact(array $data, $iteration = 0)
 {
     $contact = new Contact();
     $contact->setFirstName($data['GivenName']);
     $lastName = $data['Surname'];
     if ($iteration) {
         $lastName .= '_' . $iteration;
     }
     $contact->setLastName($lastName);
     $contact->setNamePrefix($data['Title']);
     $phone = new ContactPhone($data['TelephoneNumber']);
     $phone->setPrimary(true);
     $contact->addPhone($phone);
     $email = new ContactEmail($data['EmailAddress']);
     $email->setPrimary(true);
     $contact->addEmail($email);
     $date = \DateTime::createFromFormat('m/d/Y', $data['Birthday']);
     $contact->setBirthday($date);
     /** @var ContactAddress $address */
     $address = new ContactAddress();
     $address->setCity($data['City']);
     $address->setStreet($data['StreetAddress']);
     $address->setPostalCode($data['ZipCode']);
     $address->setFirstName($data['GivenName']);
     $address->setLastName($data['Surname']);
     $address->setPrimary(true);
     $isoCode = $data['Country'];
     $country = array_filter($this->countries, function (Country $a) use($isoCode) {
         return $a->getIso2Code() == $isoCode;
     });
     $country = array_values($country);
     /** @var Country $country */
     $country = $country[0];
     $idRegion = $data['State'];
     /** @var Collection $regions */
     $regions = $country->getRegions();
     $region = $regions->filter(function (Region $a) use($idRegion) {
         return $a->getCode() == $idRegion;
     });
     $address->setCountry($country);
     if (!$region->isEmpty()) {
         $address->setRegion($region->first());
     }
     $contact->addAddress($address);
     return $contact;
 }
Пример #6
0
 /**
  * @param string $name
  * @param int    $number
  *
  * @return ContactAddress
  *
  * @throws \LogicException
  */
 protected function createContactAddress($name, $number)
 {
     $countryRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\AddressBundle\\Entity\\Country');
     $regionRepo = $this->templateManager->getEntityRepository('Oro\\Bundle\\AddressBundle\\Entity\\Region');
     $entity = new ContactAddress();
     switch ($name) {
         case 'Jerry Coleman':
             $entity->setFirstName('Jerry')->setLastName('Coleman');
             break;
         case 'John Smith':
             $entity->setFirstName('John')->setLastName('Smith');
             break;
         default:
             throw new \LogicException(sprintf('Undefined contact address. Name: %s. Number: %d.', $name, $number));
     }
     switch ($number) {
         case 1:
             $entity->setCity('Rochester')->setStreet('1215 Caldwell Road')->setPostalCode('14608')->setRegion($regionRepo->getEntity('NY'))->setCountry($countryRepo->getEntity('US'));
             break;
         case 2:
             $entity->setCity('New York')->setStreet('4677 Pallet Street')->setPostalCode('10011')->setRegion($regionRepo->getEntity('NY'))->setCountry($countryRepo->getEntity('US'));
             break;
         case 3:
             $entity->setCity('New York')->setStreet('52 Jarvisville Road')->setPostalCode('11590')->setRegion($regionRepo->getEntity('NY'))->setCountry($countryRepo->getEntity('US'));
             break;
         default:
             throw new \LogicException(sprintf('Undefined contact address. Name: %s. Number: %d.', $name, $number));
     }
     return $entity;
 }
Пример #7
0
 /**
  * Find customer address by given contact address
  *
  * @param Customer       $customer
  * @param ContactAddress $contactAddress
  *
  * @return Address|false
  */
 protected function getCustomerAddressByContactAddress(Customer $customer, ContactAddress $contactAddress)
 {
     $filtered = $customer->getAddresses()->filter(function (Address $address) use($contactAddress) {
         return $address->getContactAddress() && $address->getContactAddress()->getId() === $contactAddress->getId();
     });
     return $filtered->first();
 }
Пример #8
0
 public function testSetAddressType()
 {
     $contact = new Contact();
     $shippingType = new AddressType('shipping');
     $addressOne = new ContactAddress();
     $addressOne->addType($shippingType);
     $contact->addAddress($addressOne);
     $addressTwo = new ContactAddress();
     $contact->addAddress($addressTwo);
     $contact->setAddressType($addressTwo, $shippingType);
     $this->assertFalse($addressOne->hasTypeWithName('shipping'));
     $this->assertTrue($addressTwo->hasTypeWithName('shipping'));
 }
Пример #9
0
 public function dataTest()
 {
     $testContact = new ExtendContact();
     $testContactAddress = new ContactAddress();
     $testContactEmail = new ContactEmail();
     $testContactPhone = new ContactPhone();
     $testContactAddress->setOwner($testContact);
     $testContactEmail->setOwner($testContact);
     $testContactPhone->setOwner($testContact);
     $testMagentoCustomer = new ExtendCustomer();
     $channel = new Channel();
     $channel->getSynchronizationSettingsReference()->offsetSet('isTwoWaySyncEnabled', true);
     $channel->setName('test');
     $channel->setEnabled(true);
     $testMagentoCustomer->setChannel($channel);
     return ['Updated contact' => [$testContact, $testMagentoCustomer, $channel, [], [$testContact], [], true, true, true, true, true], 'Inserted contact' => [$testContact, $testMagentoCustomer, $channel, [$testContact], [], [], true, false, false, true, false], 'Deleted contact' => [$testContact, $testMagentoCustomer, $channel, [], [], [$testContact], true, true, true, false, true], 'Updated contact with testContactAddress' => [$testContact, $testMagentoCustomer, $channel, [], [$testContact, $testContactAddress], [], true, true, true, true, true], 'Test process Contact Address' => [$testContact, $testMagentoCustomer, $channel, [], [$testContactAddress], [], true, true, true, false, true], 'Test deleted Contact Address' => [$testContact, $testMagentoCustomer, $channel, [], [], [$testContactAddress], true, true, true, false, true]];
 }
Пример #10
0
 /**
  * @SuppressWarnings(PHPMD)
  *
  * @dataProvider  getDataProvider
  *
  * @param array     $fields
  * @param \stdClass $checkingObject
  */
 public function testProcess(array $fields, $checkingObject)
 {
     $customerReverseProcessor = new CustomerReverseProcessor();
     $checkingObject->entity = $this->customer;
     $this->customer->expects($this->any())->method('getOriginId')->will($this->returnValue(true));
     $this->customer->expects($this->any())->method('getEmail')->will($this->returnValue($fields['email']));
     $this->contact->expects($this->any())->method('getPrimaryEmail')->will($this->returnValue($fields['emailContact']));
     $this->customer->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstName']));
     $this->contact->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstNameContact']));
     $this->customer->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastName']));
     $this->contact->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastNameContact']));
     $this->customer->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefix']));
     $this->contact->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefixContact']));
     $this->customer->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['suffix']));
     $this->contact->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['suffixContact']));
     $this->customer->expects($this->any())->method('getBirthday')->will($this->returnValue($fields['dob']));
     $this->contact->expects($this->any())->method('getBirthday')->will($this->returnValue($fields['dobContact']));
     $this->customer->expects($this->any())->method('getGender')->will($this->returnValue($fields['gender']));
     $this->contact->expects($this->any())->method('getGender')->will($this->returnValue($fields['genderContact']));
     $this->customer->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleName']));
     $this->contact->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleNameContact']));
     $this->address->expects($this->any())->method('getCity')->will($this->returnValue($fields['cityAddress']));
     $this->contactAddress->expects($this->any())->method('getCity')->will($this->returnValue($fields['cityContactAddress']));
     $this->address->expects($this->any())->method('getOrganization')->will($this->returnValue($fields['organizationAddress']));
     $this->contactAddress->expects($this->any())->method('getOrganization')->will($this->returnValue($fields['organizationContactAddress']));
     $this->address->expects($this->any())->method('getCountry')->will($this->returnValue($fields['countryAddress']));
     $this->contactAddress->expects($this->any())->method('getCountry')->will($this->returnValue($fields['countryContactAddress']));
     $this->address->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstNameAddress']));
     $this->contactAddress->expects($this->any())->method('getFirstName')->will($this->returnValue($fields['firstNameContactAddress']));
     $this->address->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastNameAddress']));
     $this->contactAddress->expects($this->any())->method('getLastName')->will($this->returnValue($fields['lastNameContactAddress']));
     $this->address->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleNameAddress']));
     $this->contactAddress->expects($this->any())->method('getMiddleName')->will($this->returnValue($fields['middleNameContactAddress']));
     $this->address->expects($this->any())->method('getPostalCode')->will($this->returnValue($fields['postalCodeAddress']));
     $this->contactAddress->expects($this->any())->method('getPostalCode')->will($this->returnValue($fields['postalCodeContactAddress']));
     $this->address->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefixAddress']));
     $this->contactAddress->expects($this->any())->method('getNamePrefix')->will($this->returnValue($fields['prefixContactAddress']));
     $this->address->expects($this->any())->method('getRegion')->will($this->returnValue($fields['regionAddress']));
     $this->contactAddress->expects($this->any())->method('getRegion')->will($this->returnValue($fields['regionContactAddress']));
     $this->address->expects($this->any())->method('getRegionText')->will($this->returnValue($fields['regionTextAddress']));
     $this->contactAddress->expects($this->any())->method('getRegionText')->will($this->returnValue($fields['regionTextContactAddress']));
     $this->address->expects($this->any())->method('getStreet')->will($this->returnValue($fields['streetAddress']));
     $this->contactAddress->expects($this->any())->method('getStreet')->will($this->returnValue($fields['streetContactAddress']));
     $this->address->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['nameSuffixAddress']));
     $this->contactAddress->expects($this->any())->method('getNameSuffix')->will($this->returnValue($fields['nameSuffixContactAddress']));
     $this->address->expects($this->any())->method('getPhone')->will($this->returnValue($fields['phone']));
     $this->contactPhone->expects($this->any())->method('getPhone')->will($this->returnValue($fields['phone']));
     $this->contact->expects($this->any())->method('getAddresses')->will($this->returnValue([$this->contactAddress]));
     if (!empty($checkingObject->object['addresses'])) {
         foreach ($checkingObject->object['addresses'] as &$address) {
             $address['entity'] = $this->address;
             if (!empty($address['status'])) {
                 if ('update' === $address['status']) {
                     $address['object']['country'] = $this->country;
                     $address['object']['region'] = $this->region;
                 }
             }
         }
         unset($address);
     }
     $result = $customerReverseProcessor->process($this->customer);
     $this->assertEquals($checkingObject, $result);
 }
Пример #11
0
 public function testAddressCreateDefaultData()
 {
     $transportSetting = $this->getMock('Oro\\Bundle\\IntegrationBundle\\Entity\\Transport');
     $channel = new Channel();
     $channel->setTransport($transportSetting);
     $customer = new Customer();
     $customer->setOriginId(self::TEST_CUSTOMER_ID);
     $customer->setChannel($channel);
     $customer->setFirstName(self::TEST_CUSTOMER_FIRSTNAME);
     $customer->setLastName(self::TEST_CUSTOMER_LASTNAME);
     $address = new ContactAddress();
     $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);
     $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(3))->method('call')->with($this->equalTo(SoapTransport::ACTION_CUSTOMER_ADDRESS_CREATE), $this->equalTo(['customerId' => self::TEST_CUSTOMER_ID, 'addressData' => ['telephone' => 'no phone', 'prefix' => null, 'firstname' => self::TEST_FIRSTNAME, 'middlename' => null, 'lastname' => self::TEST_CUSTOMER_LASTNAME, '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]]))->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::NEW_ENTITY, 'magentoId' => self::TEST_CUSTOMER_ID]]]]);
     $this->writer->write($data);
 }