useTransaction(); CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW $this->_groupID = $this->groupCreate(); $this->_email = 'test@test.test'; $this->_params = array( 'subject' => 'Accidents in cars cause children', 'body_text' => 'BEWARE children need regular infusions of toys', 'name' => 'mailing name', 'created_id' => 1, 'groups' => array('include' => array($this->_groupID)), ); $this->_mut = new CiviMailUtils($this, TRUE); $this->callAPISuccess('mail_settings', 'get', array('api.mail_settings.create' => array('domain' => 'chaos.org'))); } /** */ public function tearDown() { $this->_mut->stop(); // $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact')); CRM_Utils_Hook::singleton()->reset(); CRM_Mailing_BAO_MailingJob::$mailsProcessed = 0; // DGW parent::tearDown(); } /** * Check mailing is sent */ public function testProcessMailing() { $this->createContactsInGroup(10, $this->_groupID); CRM_Core_Config::singleton()->mailerBatchLimit = 2; $this->callAPISuccess('mailing', 'create', $this->_params); $this->callAPISuccess('job', 'process_mailing', array()); $this->_mut->assertRecipients($this->getRecipients(1, 2)); } /** * @param int $count * @param int $groupID */ public function createContactsInGroup($count, $groupID) { for ($i = 1; $i <= $count; $i++) { $contactID = $this->individualCreate(array('first_name' => $count, 'email' => 'mail' . $i . '@nul.com')); $this->callAPISuccess('group_contact', 'create', array( 'contact_id' => $contactID, 'group_id' => $groupID, 'status' => 'Added', )); } } /** * @param int $start * @param int $count * * @return array */ public function getRecipients($start, $count) { $recipients = array(); for ($i = $start; $i < ($start + $count); $i++) { $recipients[][0] = 'mail' . $i . '@nul.com'; } return $recipients; } }