Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core/#/229 Fix fatal error on send test mail #12399

Merged
merged 1 commit into from
Jul 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

$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'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eileenmcnaughton how has this test been passing is it just that there isn't a difference in ids between the civicrm_mailing table the civicrm_mailing_job table here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@seamuslee001 I was able to replicate it when I added to the test so it wasn't transposing 'mailing_id' to 'id' in the api wrapper (I haven't fully thought that through) -

in the api 'id' refers to mailing_id - but is passed to MailingJob as if it were MailingJob id - hence the bug

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(mailing id is supposed to be required here & it makes sense it should be)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm interesting. So the test was succeeding in that it was setting a mailing_id but no id but once the id got set then it started failing is that the case?

$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