Ejemplo n.º 1
0
 /**
  * `push()` function is taking a `ContactCollection` object as argument. If
  * contact doesn't exist it will be created. Result will be array:
  *
  * array['created'] = ContactCollection();
  *
  */
 public function testPushContactsCreate()
 {
     $data = array('Email' => '*****@*****.**', 'FirstName' => 'FirstName1');
     $createdContact = new Contact();
     $createdContact->setIsCreated();
     $i = $this->getMockBuilder('\\Wildsurfer\\Infusionsoft\\Sync')->disableOriginalConstructor()->setMethods(array('createContact'))->getMock();
     $i->expects($this->once())->method('createContact')->will($this->returnValue($createdContact));
     $isdk = $this->getMockedIsdk();
     $isdk->expects($this->never())->method('dsQuery');
     $i->setIsdk($isdk);
     $collection = new ContactCollection();
     $collection->create($data);
     $expected = $i->push($collection);
     $this->assertEquals(1, $expected['create']->count());
 }
Ejemplo n.º 2
0
 public function createContact(Contact $contact)
 {
     $isdk = $this->getIsdk();
     try {
         $response = $isdk->addCon($contact->getData());
         if (is_string($response)) {
             $messsage = 'Add failed. Error:' . $response;
             $contact->setErrorMessage($messsage);
             $contact->setIsFailed();
         } else {
             $contact->setId($response);
             $contact->setIsCreated();
             $tags = $contact->getTags();
             if (count($tags) > 0) {
                 foreach ($tags as $t) {
                     $response1 = $isdk->grpAssign($contact->getId(), $t);
                     if (is_string($response1)) {
                         $messsage1 = 'Add Tag failed. Error:' . $response1;
                         $isdk->dsDelete('Contact', $contact->getId());
                         $contact->setErrorMessage($messsage1);
                         $contact->setIsFailed();
                         break;
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $contact->setErrorMessage($e->getMessage());
         $contact->setIsFailed();
     }
     return $contact;
 }