Skip to content

Commit

Permalink
Merge pull request #12399 from eileenmcnaughton/jamie
Browse files Browse the repository at this point in the history
dev/core/#/229 Fix fatal error on send test mail
  • Loading branch information
seamuslee001 committed Jul 3, 2018
2 parents 10f44a8 + 480a934 commit 6adbfc5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 7 additions & 2 deletions api/v3/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ function civicrm_api3_mailing_preview($params) {
function _civicrm_api3_mailing_send_test_spec(&$spec) {
$spec['test_group']['title'] = 'Test Group ID';
$spec['test_email']['title'] = 'Test Email Address';
$spec['mailing_id']['api.required'] = TRUE;
$spec['mailing_id']['title'] = ts('Mailing Id');
}

/**
Expand All @@ -620,6 +622,10 @@ function civicrm_api3_mailing_send_test($params) {
);

$testEmailParams = _civicrm_api3_generic_replace_base_params($params);
if (isset($testEmailParams['id'])) {
unset($testEmailParams['id']);
}

$testEmailParams['is_test'] = 1;
$testEmailParams['status'] = 'Scheduled';
$testEmailParams['scheduled_date'] = CRM_Utils_Date::processDate(date('Y-m-d'), date('H:i:s'));
Expand Down Expand Up @@ -679,8 +685,7 @@ function civicrm_api3_mailing_send_test($params) {
}

$isComplete = FALSE;
$config = CRM_Core_Config::singleton();
$mailerJobSize = Civi::settings()->get('mailerJobSize');

while (!$isComplete) {
// Q: In CRM_Mailing_BAO_Mailing::processQueue(), the three runJobs*()
// functions are all called. Why does Mailing.send_test only call one?
Expand Down
6 changes: 4 additions & 2 deletions tests/phpunit/api/v3/MailingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function testMailerPreviewRecipientsDeduplicateAndOnholdEmails() {
}

/**
*
* Test sending a test mailing.
*/
public function testMailerSendTest_email() {
$contactIDs['alice'] = $this->individualCreate(array(
Expand All @@ -410,8 +410,10 @@ public function testMailerSendTest_email() {
$mail = $this->callAPISuccess('mailing', 'create', $this->_params);

$params = array('mailing_id' => $mail['id'], 'test_email' => 'alice@example.org', 'test_group' => NULL);
// Per https://lab.civicrm.org/dev/core/issues/229 ensure this is not passed through!
$params['id'] = $mail['id'];
$deliveredInfo = $this->callAPISuccess($this->_entity, 'send_test', $params);
$this->assertEquals(1, $deliveredInfo['count'], "in line " . __LINE__); // verify mail has been sent to user by count
$this->assertEquals(1, $deliveredInfo['count']); // verify mail has been sent to user by count

$deliveredContacts = array_values(CRM_Utils_Array::collect('contact_id', $deliveredInfo['values']));
$this->assertEquals(array($contactIDs['alice']), $deliveredContacts);
Expand Down

0 comments on commit 6adbfc5

Please sign in to comment.