CRM-15550 add test to check for extraneous emails
authorEileen McNaughton <eileen@fuzion.co.nz>
Tue, 2 Dec 2014 23:42:23 +0000 (12:42 +1300)
committerEileen McNaughton <eileen@fuzion.co.nz>
Fri, 5 Dec 2014 02:44:07 +0000 (15:44 +1300)
tests/phpunit/CRM/Core/BAO/ActionScheduleTest.php

index 23a78a82dc3554c24eddd3a6d60a99e6213f2d12..2d97054a0c5e3f775fc4efa5adfd5e78e0771556 100644 (file)
@@ -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' => '<p>body sched_membership_end_2month</p>',
+      '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(