From 9f0a25d7b7b9efbdfe2ed64e3ad5113174111048 Mon Sep 17 00:00:00 2001 From: JKingsnorth Date: Wed, 18 Oct 2017 15:36:16 +0100 Subject: [PATCH] CRM-21320 Test for mass SMS recipients --- tests/phpunit/CRM/Mailing/BAO/MailingTest.php | 136 ++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 tests/phpunit/CRM/Mailing/BAO/MailingTest.php diff --git a/tests/phpunit/CRM/Mailing/BAO/MailingTest.php b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php new file mode 100644 index 0000000000..958021bfd7 --- /dev/null +++ b/tests/phpunit/CRM/Mailing/BAO/MailingTest.php @@ -0,0 +1,136 @@ +groupCreate(); + $sms_provider = $this->callAPISuccess('SmsProvider', 'create', array( + 'sequential' => 1, + 'name' => 1, + 'title' => "Test", + 'username' => "Test", + 'password' => "Test", + 'api_type' => 1, + 'is_active' => 1, + )); + + // Contact 1 + $contact_1 = $this->individualCreate(array(), 0); + $contact_1_primary = $this->callAPISuccess('Phone', 'create', array( + 'contact_id' => $contact_1, + 'phone' => "01 01", + 'location_type_id' => "Home", + 'phone_type_id' => "Mobile", + 'is_primary' => 1, + )); + $contact_1_other = $this->callAPISuccess('Phone', 'create', array( + 'contact_id' => $contact_1, + 'phone' => "01 02", + 'location_type_id' => "Work", + 'phone_type_id' => "Mobile", + 'is_primary' => 0, + )); + $this->callAPISuccess('GroupContact', 'Create', array( + 'group_id' => $group, + 'contact_id' => $contact_1, + )); + + // Contact 2 + $contact_2 = $this->individualCreate(array(), 1); + $contact_2_other = $this->callAPISuccess('Phone', 'create', array( + 'contact_id' => $contact_2, + 'phone' => "02 01", + 'location_type_id' => "Home", + 'phone_type_id' => "Mobile", + 'is_primary' => 0, + )); + $contact_2_primary = $this->callAPISuccess('Phone', 'create', array( + 'contact_id' => $contact_2, + 'phone' => "02 02", + 'location_type_id' => "Work", + 'phone_type_id' => "Mobile", + 'is_primary' => 1, + )); + $this->callAPISuccess('GroupContact', 'Create', array( + 'group_id' => $group, + 'contact_id' => $contact_2, + )); + + // Prepare expected results + $check_ids = array( + $contact_1 => $contact_1_primary['id'], + $contact_2 => $contact_2_primary['id'], + ); + + // Create mailing + $mailing = $this->callAPISuccess('Mailing', 'create', array('sms_provider_id' => $sms_provider['id'])); + $mailing_include_group = $this->callAPISuccess('MailingGroup', 'create', array( + 'mailing_id' => $mailing['id'], + 'group_type' => "Include", + 'entity_table' => "civicrm_group", + 'entity_id' => $group, + )); + + // Populate the recipients table (job id doesn't matter) + CRM_Mailing_BAO_Mailing::getRecipients('123', $mailing['id'], TRUE, FALSE, 'sms'); + + // Get recipients + $recipients = $this->callAPISuccess('MailingRecipients', 'get', array('mailing_id' => $mailing['id'])); + + // Check the count is correct + $this->assertEquals(2, $recipients['count'], 'Check recipient count'); + + // Check we got the 'primary' mobile for both contacts + foreach ($recipients['values'] as $value) { + $this->assertEquals($value['phone_id'], $check_ids[$value['contact_id']], 'Check correct phone number for contact ' . $value['contact_id']); + } + + // Tidy up + $this->deleteMailing($mailing['id']); + $this->callAPISuccess('SmsProvider', 'Delete', array('id' => $sms_provider['id'])); + $this->groupDelete($group); + $this->contactDelete($contact_1); + $this->contactDelete($contact_2); + } + +} -- 2.25.1