function testFindByGroupIdNoSyncSettings()
 {
     $group_name = 'Test Group testFindByGroupIdNoSyncSettings';
     $group_id = $this->groupCreate(array('name' => $group_name, 'title' => $group_name));
     $mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettings::findByGroupId($group_id);
     $this->assertNull($mailchimp_sync_setting);
 }
 function postProcess()
 {
     $values = $this->exportValues();
     $mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettings::findByGroupId($values['group']);
     $mailchimp_export_url = CRM_CiviMailchimp_Utils::formatMailchimpExportApiUrl($mailchimp_sync_setting->mailchimp_list_id);
     list($contacts, $mailchimp_members) = self::processForcedSync($mailchimp_sync_setting, $mailchimp_export_url);
     parent::postProcess();
     CRM_Core_Session::setStatus(ts("%1 contacts were synced to Mailchimp and %2  Mailchimp members were synced to CiviCRM.", array(1 => count($contacts), 2 => count($mailchimp_members))), ts('CiviMailchimp Force Sync Successful'), 'success');
     CRM_Utils_System::redirect($this->controller->_entryURL);
 }
/**
 * Implements hook_civicrm_pre for Group delete.
 */
function civimailchimp_civicrm_pre_Group_delete($group_id, &$group)
{
    $mailchimp_sync_settings = CRM_CiviMailchimp_BAO_SyncSettings::findByGroupId($group_id);
    if ($mailchimp_sync_settings) {
        civimailchimp_static('mailchimp_sync_settings', $mailchimp_sync_settings);
    }
}
 function test_civimailchimp_civicrm_postProcess_no_list()
 {
     $mailchimp_list_id = 'MailchimpListsTestListA';
     $mailchimp_interest_groups = array('MailchimpTestInterestGroupingA_MailchimpTestInterestGroupA', 'MailchimpTestInterestGroupingA_MailchimpTestInterestGroupC');
     $mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettingsTest::createTestGroupAndSyncSettings('Test Group postProcess_CRM_Group_Form_Edit_no_list', $mailchimp_list_id, $mailchimp_interest_groups);
     $formName = 'CRM_Group_Form_Edit';
     $form = $this->getMock('CRM_Core_Form');
     $form->expects($this->once())->method('getVar')->will($this->returnValue($mailchimp_sync_setting->civicrm_group_id));
     $form->expects($this->never())->method('get')->will($this->returnValue(TRUE));
     $form->_elementIndex['mailchimp_list'] = TRUE;
     $form->_submitValues = array('mailchimp_list' => NULL);
     civimailchimp_civicrm_postProcess($formName, $form);
     $mailchimp_sync_setting = CRM_CiviMailchimp_BAO_SyncSettings::findByGroupId($mailchimp_sync_setting->civicrm_group_id);
     $this->assertEmpty($mailchimp_sync_setting);
 }