mailing tests
authorEileen McNaughton <eileen@fuzion.co.nz>
Wed, 28 May 2014 08:37:25 +0000 (20:37 +1200)
committerEileen McNaughton <eileen@fuzion.co.nz>
Wed, 28 May 2014 08:58:03 +0000 (20:58 +1200)
CRM/Mailing/BAO/Mailing.php
CRM/Mailing/BAO/MailingJob.php
CRM/Mailing/Event/BAO/Queue.php
tests/phpunit/api/v3/JobProcessMailingTest.php [new file with mode: 0644]

index 06664869597ce99d84c282bcab3f7fa3b4bb2ab2..a7bd0f051f0807a1606a22363422ac43a42354e5 100644 (file)
@@ -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 <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online user and administrator guide</a>', 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 <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online user and administrator guide</a>', 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
index 4193a567c9798adc8fc865153f423f51fea0d6a1..c855d86a88c9033dedcb665831c1f49798186f6e 100644 (file)
@@ -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();
 
index e91a5507a5b2b2dbb51b26a3ba76e9c56b572656..ccc2083452a58837f62fff21c1a3338a3b6ae645 100644 (file)
@@ -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 (file)
index 0000000..18f5dbe
--- /dev/null
@@ -0,0 +1,119 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.5                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * File for the CiviCRM APIv3 job functions
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_Job
+ *
+ * @copyright CiviCRM LLC (c) 2004-2014
+ * @version $Id: Job.php 30879 2010-11-22 15:45:55Z shot $
+ *
+ */
+require_once 'CiviTest/CiviUnitTestCase.php';
+//@todo - why doesn't class loader find these (I tried renaming)
+require_once 'CiviTest/CiviMailUtils.php';
+/**
+ * Class api_v3_JobTest
+ */
+class api_v3_JobProcessMailingTest extends CiviUnitTestCase {
+  protected $_apiversion = 3;
+
+  public $DBResetRequired = FALSE;
+  public $_entity = 'Job';
+  public $_params = array();
+  private $_groupID;
+  private $_email;
+
+  /**
+   * @var CiviMailUtils
+   */
+  private $_mut;
+
+  function setUp() {
+    parent::setUp();
+    $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')));
+  }
+
+  /**
+   *
+   */
+  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;
+  }
+}