/**
  *
  */
 public function testUpdateCiviFromMailchimpContactLogic()
 {
     $cases = [['label' => 'Test no changes', 'mailchimp' => ['first_name' => 'x', 'last_name' => 'y'], 'civi' => ['first_name' => 'x', 'last_name' => 'y'], 'expected' => []], ['label' => 'Test first name changes', 'mailchimp' => ['first_name' => 'a', 'last_name' => 'y'], 'civi' => ['first_name' => 'x', 'last_name' => 'y'], 'expected' => ['first_name' => 'a']], ['label' => 'Test first name provide', 'mailchimp' => ['first_name' => 'a', 'last_name' => 'y'], 'civi' => ['first_name' => '', 'last_name' => 'y'], 'expected' => ['first_name' => 'a']], ['label' => 'Test first name no clobber', 'mailchimp' => ['first_name' => '', 'last_name' => 'y'], 'civi' => ['first_name' => 'x', 'last_name' => 'y'], 'expected' => []], ['label' => 'Test last name changes', 'mailchimp' => ['last_name' => 'a', 'first_name' => 'y'], 'civi' => ['last_name' => 'x', 'first_name' => 'y'], 'expected' => ['last_name' => 'a']], ['label' => 'Test last name provide', 'mailchimp' => ['last_name' => 'a', 'first_name' => 'y'], 'civi' => ['last_name' => '', 'first_name' => 'y'], 'expected' => ['last_name' => 'a']], ['label' => 'Test last name no clobber', 'mailchimp' => ['last_name' => '', 'first_name' => 'y'], 'civi' => ['last_name' => 'x', 'first_name' => 'y'], 'expected' => []]];
     foreach ($cases as $case) {
         extract($case);
         $result = CRM_Mailchimp_Sync::updateCiviFromMailchimpContactLogic($mailchimp, $civi);
         $this->assertEquals($expected, $result, "FAILED: {$label}");
     }
 }
 /**
  * Find/create, and update.
  *
  * - "[list_id]": "a6b5da1054",
  * - "[email]": "*****@*****.**",
  * - "[merges][FNAME]": "MailChimp",
  * - "[merges][LNAME]": "API",
  * - "[merges][INTERESTS]": "Group1,Group2",
  *
  */
 public function findOrCreateSubscribeAndUpdate()
 {
     $this->findOrCreateContact();
     // Check whether names have changed.
     $contact = civicrm_api3('Contact', 'getsingle', ['contact_id' => $this->contact_id]);
     $edits = CRM_Mailchimp_Sync::updateCiviFromMailchimpContactLogic(['first_name' => empty($this->request_data['merges']['FNAME']) ? '' : $this->request_data['merges']['FNAME'], 'last_name' => empty($this->request_data['merges']['LNAME']) ? '' : $this->request_data['merges']['LNAME']], $contact);
     if ($edits) {
         // We do need to make some changes.
         civicrm_api3('Contact', 'create', ['contact_id' => $this->contact_id] + $edits);
     }
     // Contact has just subscribed, we'll need to add them to the list.
     civicrm_api3('GroupContact', 'create', ['contact_id' => $this->contact_id, 'group_id' => $this->sync->membership_group_id, 'status' => 'Added']);
     $this->updateInterestsFromMerges();
 }