From d8c20bdba666382b4553c3365c935dd8bf6654b9 Mon Sep 17 00:00:00 2001 From: DemeritCowboy Date: Thu, 6 Jun 2019 01:10:51 -0400 Subject: [PATCH] fix E_NOTICE --- api/v3/Mailing.php | 2 +- tests/phpunit/CRM/SMS/PreviewTest.php | 59 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/SMS/PreviewTest.php diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index c29d3d1350..a71e5645d9 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -594,7 +594,7 @@ function civicrm_api3_mailing_preview($params) { return civicrm_api3_create_success([ 'id' => $mailingID, 'contact_id' => $contactID, - 'subject' => $mime->headers()['Subject'], + 'subject' => CRM_Utils_Array::value('Subject', $mime->headers(), ''), 'body_html' => $mime->getHTMLBody(), 'body_text' => $mime->getTXTBody(), ]); diff --git a/tests/phpunit/CRM/SMS/PreviewTest.php b/tests/phpunit/CRM/SMS/PreviewTest.php new file mode 100644 index 0000000000..dfe82711c3 --- /dev/null +++ b/tests/phpunit/CRM/SMS/PreviewTest.php @@ -0,0 +1,59 @@ +callAPISuccess('option_value', 'create', ['option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'Test Provider Label', 'value' => 1]); + $this->option_value = $option['id']; + } + + /** + * Clean up after each test. + */ + public function tearDown() { + parent::tearDown(); + $this->callAPISuccess('option_value', 'delete', ['id' => $this->option_value]); + } + + /** + * Test SMS preview. + */ + public function testSMSPreview() { + $result = $this->callAPISuccess('SmsProvider', 'create', [ + 'title' => 'test SMS provider', + 'username' => 'test', + 'password' => 'password', + // 'name' is the option_value 'value' (not id, not name) we created in setUp() + 'name' => 1, + 'is_active' => 1, + 'is_default' => 1, + 'api_type' => 1, + ]); + $provider_id = $result['id']; + $result = $this->callAPISuccess('Mailing', 'create', [ + 'name' => "Test1", + 'from_name' => "+12223334444", + 'from_email' => "test@test.com", + 'replyto_email' => "test@test.com", + 'body_text' => "Testing body", + 'sms_provider_id' => $provider_id, + 'header_id' => NULL, + 'footer_id' => NULL, + 'unsubscribe_id' => NULL, + ]); + $mailing_id = $result['id']; + $result = $this->callAPISuccess('Mailing', 'preview', [ + 'id' => $mailing_id, + ]); + } + +} -- 2.25.1