Ejemplo n.º 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());
 }
Ejemplo n.º 2
0
 /**
  * @param string $phone
  * @param bool   $primary
  *
  * @return ContactPhone
  */
 protected function createContactPhone($phone, $primary = false)
 {
     $entity = new ContactPhone($phone);
     if ($primary) {
         $entity->setPrimary(true);
     }
     return $entity;
 }
Ejemplo n.º 3
0
 public function testGetPhoneNumbers()
 {
     $entity = new Contact();
     $this->assertSame([], $this->provider->getPhoneNumbers($entity));
     $phone1 = new ContactPhone('123-123');
     $entity->addPhone($phone1);
     $phone2 = new ContactPhone('456-456');
     $phone2->setPrimary(true);
     $entity->addPhone($phone2);
     $this->assertSame([['123-123', $entity], ['456-456', $entity]], $this->provider->getPhoneNumbers($entity));
 }
Ejemplo n.º 4
0
 public function testGetPhoneNumbers()
 {
     $entity = new Address();
     $contact = $this->getMockBuilder('OroCRM\\Bundle\\ContactBundle\\Entity\\Contact')->disableOriginalConstructor()->getMock();
     $this->assertSame([], $this->provider->getPhoneNumbers($entity));
     $contactPhone = new ContactPhone('123-123');
     $contactPhone->setOwner($contact);
     $entity->setContactPhone($contactPhone);
     $this->assertSame([['123-123', $contact]], $this->provider->getPhoneNumbers($entity));
     $entity->setPhone('456-456');
     $this->assertSame([['456-456', $entity], ['123-123', $contact]], $this->provider->getPhoneNumbers($entity));
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $contact = $this->getReference('Contact_' . LoadContactEntitiesData::FIRST_ENTITY_NAME);
     foreach ($this->contactEmailData as $contactEmailData) {
         $contactPhone = new ContactPhone();
         $contactPhone->setPrimary($contactEmailData['primary']);
         $contactPhone->setOwner($contact);
         $contactPhone->setPhone($contactEmailData['phone']);
         $this->setReference('ContactPhone_Several_' . $contactEmailData['phone'], $contactPhone);
         $manager->persist($contactPhone);
     }
     $contact2 = $this->getReference('Contact_' . LoadContactEntitiesData::SECOND_ENTITY_NAME);
     $contactPhone = new ContactPhone();
     $contactPhone->setPrimary($this->contactEmailData[0]['primary']);
     $contactPhone->setOwner($contact2);
     $contactPhone->setPhone($this->contactEmailData[0]['phone']);
     $this->setReference('ContactPhone_Single_' . $this->contactEmailData[0]['phone'], $contactPhone);
     $manager->persist($contactPhone);
     $manager->flush();
 }
Ejemplo n.º 6
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;
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  *
  * @param ContactPhone $value
  */
 public function validate(ContactPhone $value)
 {
     return $value->isPrimary() && $value->getOwner()->getPhones()->count() === 1;
 }
Ejemplo n.º 8
0
 /**
  * Get ContactPhone from contact by ContactPhone
  *
  * @param Contact      $contact
  * @param ContactPhone $contactPhone
  *
  * @return mixed
  */
 protected function getContactPhoneFromContact(Contact $contact, ContactPhone $contactPhone)
 {
     $filtered = $contact->getPhones()->filter(function (ContactPhone $phone) use($contactPhone) {
         return $phone && $phone->getId() === $contactPhone->getId();
     });
     return $filtered->first();
 }
Ejemplo n.º 9
0
 /**
  * Filtered phone by phone number from contact and return entity or null
  *
  * @param Contact      $contact
  * @param ContactPhone $contactPhone
  *
  * @return ContactPhone|null
  */
 protected function getContactPhoneFromContact(Contact $contact, ContactPhone $contactPhone)
 {
     foreach ($contact->getPhones() as $phone) {
         if ($phone->getPhone() === $contactPhone->getPhone()) {
             $hash = spl_object_hash($phone);
             if (array_key_exists($hash, $this->processedEntities)) {
                 // skip if contact phone used for previously imported phone
                 continue;
             }
             $this->processedEntities[$hash] = $phone;
             return $phone;
         }
     }
     return null;
 }
Ejemplo n.º 10
0
 /**
  * @param ContactPhone $entity
  * @param Contact $contact
  */
 protected function onSuccess(ContactPhone $entity, Contact $contact)
 {
     $entity->setOwner($contact);
     $this->manager->persist($entity);
     $this->manager->flush();
 }
Ejemplo n.º 11
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]];
 }
Ejemplo n.º 12
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);
 }