From: Eileen McNaughton Date: Wed, 28 May 2014 08:37:25 +0000 (+1200) Subject: mailing tests X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=07c09ae4aab026b359e21ffb6b50f9ab4f27aa35;p=civicrm-core.git mailing tests --- diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index 0666486959..a7bd0f051f 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -910,7 +910,7 @@ ORDER BY civicrm_email.is_bulkmail DESC 'email_id' => $dao->email_id, 'contact_id' => $groupContact, ); - $queue = CRM_Mailing_Event_BAO_Queue::create($params); + CRM_Mailing_Event_BAO_Queue::create($params); } } } @@ -2692,7 +2692,7 @@ WHERE civicrm_mailing_job.id = %1 // CRM_Core_Error::debug_log_message("Beginning processQueue run: {$config->mailerJobsMax}, {$config->mailerJobSize}"); if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") { - CRM_Core_Error::fatal(ts('The default mailbox has not been configured. You will find more info in the online user and administrator guide', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), 2 => "http://book.civicrm.org/user/advanced-configuration/email-system-configuration/"))); + throw new CRM_Core_Exception(ts('The default mailbox has not been configured. You will find more info in the online user and administrator guide', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), 2 => "http://book.civicrm.org/user/advanced-configuration/email-system-configuration/"))); } // check if we are enforcing number of parallel cron jobs diff --git a/CRM/Mailing/BAO/MailingJob.php b/CRM/Mailing/BAO/MailingJob.php index 4193a567c9..c855d86a88 100644 --- a/CRM/Mailing/BAO/MailingJob.php +++ b/CRM/Mailing/BAO/MailingJob.php @@ -294,7 +294,6 @@ class CRM_Mailing_BAO_MailingJob extends CRM_Mailing_DAO_MailingJob { public static function runJobs_pre($offset = 200, $mode = NULL) { $job = new CRM_Mailing_BAO_MailingJob(); - $config = CRM_Core_Config::singleton(); $jobTable = CRM_Mailing_DAO_MailingJob::getTableName(); $mailingTable = CRM_Mailing_DAO_Mailing::getTableName(); diff --git a/CRM/Mailing/Event/BAO/Queue.php b/CRM/Mailing/Event/BAO/Queue.php index e91a5507a5..ccc2083452 100644 --- a/CRM/Mailing/Event/BAO/Queue.php +++ b/CRM/Mailing/Event/BAO/Queue.php @@ -44,13 +44,13 @@ class CRM_Mailing_Event_BAO_Queue extends CRM_Mailing_Event_DAO_Queue { /** * Queue a new recipient * - * @param array The values of the new EventQueue + * @param array $params values of the new EventQueue * - * @return object The new EventQueue + * @return CRM_Mailing_Event_BAO_Queue The new EventQueue * @access public * @static */ - public static function &create(&$params) { + public static function create($params) { $eq = new CRM_Mailing_Event_BAO_Queue(); $eq->copyValues($params); $eq->hash = self::hash($params); diff --git a/tests/phpunit/api/v3/JobProcessMailingTest.php b/tests/phpunit/api/v3/JobProcessMailingTest.php new file mode 100644 index 0000000000..18f5dbe8d2 --- /dev/null +++ b/tests/phpunit/api/v3/JobProcessMailingTest.php @@ -0,0 +1,119 @@ +_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'))); + } + + /** + * + */ + function tearDown() { + $this->_mut->stop(); + $this->quickCleanup(array('civicrm_mailing', 'civicrm_mailing_job', 'civicrm_contact')); + CRM_Utils_Hook::singleton()->reset(); + parent::tearDown(); + + } + + /** + * Check mailing is sent + */ + 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 integer $count + * @param integer $groupID + */ + 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 integer $start + * @param integer $count + * + * @return array + */ + function getRecipients($start, $count) { + $recipients = array(); + for($i = $start; $i < ($start + $count); $i++ ) { + $recipients[][0] = 'mail' . $i . '@nul.com'; + } + return $recipients; + } +}