From 51ae62c489a837639cd2c4137d36334ecc1f5731 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 20 Nov 2014 16:00:54 -0800 Subject: [PATCH] CRM-15578 - Mailing API - Extend test for "preview" action: * Assert subject, text, and html * Use force_rollback; assert no side-effects * Rename return properties for consistency (eg text => body_text) --- api/v3/Mailing.php | 4 ++-- tests/phpunit/api/v3/MailingTest.php | 34 ++++++++++++++++++++++------ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index af48f786ea..e8c0d7d063 100755 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -349,8 +349,8 @@ function civicrm_api3_mailing_preview($params) { 'id' => $params['id'], 'contact_id' => $contactID, 'subject' => $mime->_headers['Subject'], - 'html' => $mime->getHTMLBody(), - 'text' => $mime->getTXTBody(), + 'body_html' => $mime->getHTMLBody(), + 'body_text' => $mime->getTXTBody(), )); } diff --git a/tests/phpunit/api/v3/MailingTest.php b/tests/phpunit/api/v3/MailingTest.php index 2ed1eb732e..503311cf96 100755 --- a/tests/phpunit/api/v3/MailingTest.php +++ b/tests/phpunit/api/v3/MailingTest.php @@ -60,8 +60,9 @@ class api_v3_MailingTest extends CiviUnitTestCase { $this->_groupIDs = array(); $this->_email = 'test@test.test'; $this->_params = array( - 'subject' => 'maild', + 'subject' => 'Hello {contact.display_name}', 'body_text' => "This is {contact.display_name}", + 'body_html' => "

This is {contact.display_name}

", 'name' => 'mailing name', 'created_id' => $this->_contactIDs[0], ); @@ -91,17 +92,36 @@ class api_v3_MailingTest extends CiviUnitTestCase { } public function testMailerPreview() { + // BEGIN SAMPLE DATA $contactID = $this->individualCreate(); $displayName = $this->callAPISuccess('contact', 'get', array('id' => $contactID)); $displayName = $displayName['values'][$contactID]['display_name']; + $this->assertTrue(!empty($displayName)); - $result = $this->callAPISuccess('mailing', 'create', $this->_params); + $params = $this->_params; + $params['api.Mailing.preview'] = array( + 'id' => '$value.id', + 'contact_id' => $contactID, + ); + $params['options']['force_rollback'] = 1; + // END SAMPLE DATA + + $maxIDs = array( + 'mailing' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing'), + 'job' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_job'), + 'group' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_group'), + 'recip' => CRM_Core_DAO::singleValueQuery('SELECT MAX(id) FROM civicrm_mailing_recipients'), + ); + $result = $this->callAPISuccess('mailing', 'create', $params); + $this->assertDBQuery($maxIDs['mailing'], 'SELECT MAX(id) FROM civicrm_mailing'); // 'Preview should not create any mailing records' + $this->assertDBQuery($maxIDs['job'], 'SELECT MAX(id) FROM civicrm_mailing_job'); // 'Preview should not create any mailing_job record' + $this->assertDBQuery($maxIDs['group'], 'SELECT MAX(id) FROM civicrm_mailing_group'); // 'Preview should not create any mailing_group records' + $this->assertDBQuery($maxIDs['recip'], 'SELECT MAX(id) FROM civicrm_mailing_recipients'); // 'Preview should not create any mailing_recipient records' - $params = array('id' => $result['id'], 'contact_id' => $contactID); - $result = $this->callAPISuccess('mailing', 'preview', $params); - $text = $result['values']['text']; - $this->assertEquals("This is $displayName", $text); // verify the text returned is correct, with replaced token - $this->deleteMailing($result['id']); + $previewResult = $result['values'][$result['id']]['api.Mailing.preview']; + $this->assertEquals("Hello $displayName", $previewResult['values']['subject']); + $this->assertEquals("This is $displayName", $previewResult['values']['body_text']); + $this->assertContains("

This is $displayName

", $previewResult['values']['body_html']); } public function testMailerPreviewRecipients() { -- 2.25.1