From ff32c1284dc626634422aa8a7474843b6bfce5ee Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 1 May 2014 17:42:58 -0700 Subject: [PATCH] CRM-14319 additional test to check how limit to works - just for Yashi --- tests/phpunit/api/v3/JobTest.php | 48 +++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/api/v3/JobTest.php b/tests/phpunit/api/v3/JobTest.php index efc7c14b1c..5b8dda4609 100644 --- a/tests/phpunit/api/v3/JobTest.php +++ b/tests/phpunit/api/v3/JobTest.php @@ -58,7 +58,7 @@ class api_v3_JobTest extends CiviUnitTestCase { } function tearDown() { - $this->quickCleanup(array('civicrm_job')); + $this->quickCleanup(array('civicrm_job', 'civicrm_action_log', 'civicrm_action_schedule')); $this->quickCleanUpFinancialEntities(); CRM_Utils_Hook::singleton()->reset(); parent::tearDown(); @@ -212,6 +212,52 @@ class api_v3_JobTest extends CiviUnitTestCase { $this->assertEquals($successfulCronCount, $createTotal); } + /** + * test scheduled reminders respect limit to (since above identified addition_to handling issue) + * We create 3 contacts - 1 is in our group, 1 has our membership & the chosen one has both + * & check that only the chosen one got the reminder + */ + public function testCallSendReminderLimitTo() { + $membershipTypeID = $this->membershipTypeCreate(); + $this->membershipStatusCreate(); + $createTotal = 3; + $groupID = $this->groupCreate(array('name' => 'Texan drawlers', 'title' => 'a...')); + for($i = 1; $i <= $createTotal; $i++) { + $contactID = $this->individualCreate(); + if($i == 2) { + $theChosenOneID = $contactID; + } + if($i < 3) { + $this->callAPISuccess('group_contact', 'create', array('contact_id' => $contactID, 'status' => 'Added', 'group_id' => $groupID)); + } + if($i > 1) { + $this->callAPISuccess('membership', 'create', array( + 'contact_id' => $contactID, + 'membership_type_id' => $membershipTypeID, + 'join_date' => '+ 1 hour', + ) + ); + } + } + $result = $this->callAPISuccess('action_schedule', 'create', array( + 'title' => " remind all Texans", + 'subject' => "drawling renewal", + 'entity_value' => $membershipTypeID, + 'mapping_id' => 4, + 'start_action_date' => 'membership_join_date', + 'start_action_offset' => 0, + 'start_action_condition' => 'before', + 'start_action_unit' => 'hour', + 'group_id' => $groupID, + 'limit_to' => TRUE, + )); + $result = $this->callAPISuccess('job', 'send_reminder', array()); + $successfulCronCount = CRM_Core_DAO::singleValueQuery("SELECT count(*) FROM civicrm_action_log"); + $this->assertEquals($successfulCronCount, 1); + $sentToID = CRM_Core_DAO::singleValueQuery("SELECT contact_id FROM civicrm_action_log"); + $this->assertEquals($sentToID, $theChosenOneID); + } + public function testCallDisableExpiredRelationships() { $individualID = $this->individualCreate(); $orgID = $this->organizationCreate(); -- 2.25.1