From baa85770437a4452cef90d459a53e8bbca0138c4 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 3 Dec 2014 12:42:23 +1300 Subject: [PATCH] CRM-15550 add test to check for extraneous emails --- .../CRM/Core/BAO/ActionScheduleTest.php | 65 ++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php index 23a78a82dc..2d97054a0c 100644 --- a/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php +++ b/tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php @@ -393,8 +393,36 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { 'start_action_unit' => 'month', 'subject' => 'subject sched_membership_end_2month', ); - - + $this->fixtures['sched_membership_end_limit_to_none'] = array( // create() + 'name' => 'limit to none', + 'title' => 'limit to none', + 'absolute_date' => '', + 'body_html' => '

body sched_membership_end_2month

', + 'body_text' => 'body sched_membership_end_2month', + 'end_action' => '', + 'end_date' => '', + 'end_frequency_interval' => '4', + 'end_frequency_unit' => 'month', + 'entity_status' => '', + 'entity_value' => '', + 'limit_to' => 0, + 'group_id' => '', + 'is_active' => 1, + 'is_repeat' => '1', + 'mapping_id' => 4, + 'msg_template_id' => '', + 'recipient' => '', + 'recipient_listing' => '', + 'recipient_manual' => '', + 'record_activity' => 1, + 'repetition_frequency_interval' => '4', + 'repetition_frequency_unit' => 'week', + 'start_action_condition' => 'after', + 'start_action_date' => 'membership_end_date', + 'start_action_offset' => '2', + 'start_action_unit' => 'month', + 'subject' => 'limit to none', + ); $this->_setUp(); } @@ -754,6 +782,39 @@ class CRM_Core_BAO_ActionScheduleTest extends CiviUnitTestCase { )); $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id'],)); } + /** + * Check that limit_to + an empty recipients doesn't sent to multiple contacts + */ + function testMembershipLimitToNone() { + // creates membership with end_date = 20120615 + $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership'], array('status_id' => 2))); + + $this->assertTrue(is_numeric($membership->id)); + $result = $this->callAPISuccess('Email', 'create', array( + 'contact_id' => $membership->contact_id, + 'email' => 'member@example.com', + )); + $this->callAPISuccess('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); + $this->callAPISuccess('contact', 'create', array('email' => 'b@c.com', 'contact_type' => 'Individual')); + + $this->assertAPISuccess($result); + + $actionSchedule = $this->fixtures['sched_membership_end_limit_to_none']; + $actionSchedule['entity_value'] = $membership->membership_type_id; + $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); + $this->assertTrue(is_numeric($actionScheduleDao->id)); + + // end_date=2012-06-15 ; schedule is 2 weeks before end_date + $this->assertCronRuns(array( + array( // Before the 2-week mark, no email + 'time' => '2012-05-31 01:00:00', + // 'time' => '2012-06-01 01:00:00', // FIXME: Is this the right boundary? + 'recipients' => array(), + ), + )); + } + + function testContactCustomDate_Anniv() { $group = array( -- 2.25.1