From 30b036fa977017f7a5cee8acb9be9af558bc8fe9 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 2 Aug 2019 11:17:39 +1000 Subject: [PATCH] dev/core#1162 add in unit test checking that no bulk email flag is respected when building recipients --- tests/phpunit/CRM/Mailing/BAO/MailingTest.php | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php index bdc6891df27..1962e7c60d3 100644 --- a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php +++ b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php @@ -421,6 +421,49 @@ public function testgetRecipientsEmailGroupIncludeExclude() { } } + /** + * Test That No BUlk Emails User Optt Out is resepected when constructing a mailing + */ + public function testGetReceipientNoBulkEmails() { + // Set up groups; 3 standard, 4 smart + $groupIDs = []; + $params = [ + 'name' => 'Test static group 1', + 'title' => 'Test static group 1', + 'is_active' => 1, + ]; + $groupIDs[] = $this->groupCreate($params); + + // Create contacts + $contactIDs = [ + $this->individualCreate(['last_name' => 'test_contact1'], 0), + $this->individualCreate(['last_name' => 'test_contact2', 'is_opt_out' => 1], 1), + ]; + + // Add contacts to static groups + $this->callAPISuccess('GroupContact', 'Create', [ + 'group_id' => $groupIDs[0], + 'contact_id' => $contactIDs[0], + ]); + $this->callAPISuccess('GroupContact', 'Create', [ + 'group_id' => $groupIDs[0], + 'contact_id' => $contactIDs[1], + ]); + + // Check that we can include static groups in the mailing. + // Expected: Contacts [0-3] should be included. + $mailing = $this->callAPISuccess('Mailing', 'create', []); + $this->createMailingGroup($mailing['id'], $groupIDs[0]); + $this->assertRecipientsCorrect($mailing['id'], [$contactIDs[0]]); + $this->deleteMailing($mailing['id']); + foreach ($groupIDs as $groupID) { + $this->groupDelete($groupID); + } + foreach ($contactIDs as $contactID) { + $this->contactDelete($contactID); + } + } + /** * Test CRM_Mailing_BAO_Mailing::getRecipients() on sms mode */