From 83aefb2eaba5f8cc194daa14d2560b04d2c6e804 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 26 Jan 2016 22:06:45 -0800 Subject: [PATCH] CRM-16514 - CRM_Activity_ActionMappingTest - Add some tests Notably, this includes a test with `recipientIsBob`. There other tests mostly a sanity check to ensure that I was writing the test well. --- .../CRM/Activity/ActionMappingTest.php | 237 ++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 tests/phpunit/CRM/Activity/ActionMappingTest.php diff --git a/tests/phpunit/CRM/Activity/ActionMappingTest.php b/tests/phpunit/CRM/Activity/ActionMappingTest.php new file mode 100644 index 0000000000..0cd894a670 --- /dev/null +++ b/tests/phpunit/CRM/Activity/ActionMappingTest.php @@ -0,0 +1,237 @@ + '2015-02-01 00:00:00', + 'to' => array('alice@example.org'), + 'subject' => '/Hello, Alice.*via subject/', + ), + ), + ); + + $cs[] = array( + '2015-02-01 00:00:00', + 'addAliceMeeting scheduleForAny startOnTime useHelloFirstName recipientIsBob', + array( + array( + 'time' => '2015-02-01 00:00:00', + 'to' => array('bob@example.org'), + 'subject' => '/Hello, Bob.*via subject/', + // It might make more sense to get Alice's details... but path of least resistance... + ), + ), + ); + + $cs[] = array( + '2015-02-01 00:00:00', + 'addAliceMeeting addBobPhoneCall scheduleForMeeting startOnTime useHelloFirstName recipientIsActivitySource', + array( + array( + 'time' => '2015-02-01 00:00:00', + 'to' => array('alice@example.org'), + 'subject' => '/Hello, Alice.*via subject/', + ), + ), + ); + + $cs[] = array( + '2015-02-01 00:00:00', + 'addAliceMeeting addBobPhoneCall scheduleForAny startOnTime useHelloFirstName recipientIsActivitySource', + array( + array( + 'time' => '2015-02-01 00:00:00', + 'to' => array('alice@example.org'), + 'subject' => '/Hello, Alice.*via subject/', + ), + array( + 'time' => '2015-02-01 00:00:00', + 'to' => array('bob@example.org'), + 'subject' => '/Hello, Bob.*via subject/', + ), + ), + ); + + $cs[] = array( + '2015-02-02 00:00:00', + 'addAliceMeeting addBobPhoneCall scheduleForPhoneCall startWeekBefore repeatTwoWeeksAfter useHelloFirstName recipientIsActivitySource', + array( + array( + 'time' => '2015-01-26 00:00:00', + 'to' => array('bob@example.org'), + 'subject' => '/Hello, Bob.*via subject/', + ), + array( + 'time' => '2015-02-02 00:00:00', + 'to' => array('bob@example.org'), + 'subject' => '/Hello, Bob.*via subject/', + ), + array( + 'time' => '2015-02-09 00:00:00', + 'to' => array('bob@example.org'), + 'subject' => '/Hello, Bob.*via subject/', + ), + array( + 'time' => '2015-02-16 00:00:00', + 'to' => array('bob@example.org'), + 'subject' => '/Hello, Bob.*via subject/', + ), + ), + ); + + return $cs; + } + + /** + * Create an activity record for Alice with type "Meeting". + */ + public function addAliceMeeting() { + $this->callAPISuccess('Activity', 'create', array( + 'source_contact_id' => $this->contacts['alice']['id'], + 'activity_type_id' => 'Meeting', + 'subject' => 'Subject for Alice', + 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate)), + 'status_id' => 2, + 'assignee_contact_id' => array($this->contacts['carol']['id']), + )); + } + + /** + * Create a contribution record for Bob with type "Donation". + */ + public function addBobPhoneCall() { + $this->callAPISuccess('Activity', 'create', array( + 'source_contact_id' => $this->contacts['bob']['id'], + 'activity_type_id' => 'Phone Call', + 'subject' => 'Subject for Bob', + 'activity_date_time' => date('Y-m-d H:i:s', strtotime($this->targetDate)), + 'status_id' => 2, + 'assignee_contact_id' => array($this->contacts['carol']['id']), + )); + } + + /** + * Schedule message delivery for activities of type "Meeting". + */ + public function scheduleForMeeting() { + $actTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id'); + $this->schedule->mapping_id = CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID; + $this->schedule->start_action_date = 'receive_date'; + $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(array_search('Meeting', $actTypes))); + $this->schedule->entity_status = CRM_Utils_Array::implodePadded(array(2)); + } + + /** + * Schedule message delivery for activities of type "Phone Call". + */ + public function scheduleForPhoneCall() { + $actTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id'); + $this->schedule->mapping_id = CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID; + $this->schedule->start_action_date = 'receive_date'; + $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array(array_search('Phone Call', $actTypes))); + $this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL); + } + + /** + * Schedule message delivery for any contribution, regardless of type. + */ + public function scheduleForAny() { + $actTypes = CRM_Activity_BAO_Activity::buildOptions('activity_type_id'); + $this->schedule->mapping_id = CRM_Activity_ActionMapping::ACTIVITY_MAPPING_ID; + $this->schedule->start_action_date = 'receive_date'; + $this->schedule->entity_value = CRM_Utils_Array::implodePadded(array_keys($actTypes)); + $this->schedule->entity_status = CRM_Utils_Array::implodePadded(NULL); + } + + /** + * Set the recipient to "Choose Recipient(s): Bob". + */ + public function recipientIsBob() { + $this->schedule->limit_to = 1; + $this->schedule->recipient = NULL; + $this->schedule->recipient_listing = NULL; + $this->schedule->recipient_manual = $this->contacts['bob']['id']; + } + + /** + * Set the recipient to "Activity Assignee". + */ + public function recipientIsActivityAssignee() { + $this->schedule->limit_to = 1; + $this->schedule->recipient = 1; + $this->schedule->recipient_listing = NULL; + $this->schedule->recipient_manual = NULL; + } + + /** + * Set the recipient to "Activity Source". + */ + public function recipientIsActivitySource() { + $this->schedule->limit_to = 1; + $this->schedule->recipient = 2; + $this->schedule->recipient_listing = NULL; + $this->schedule->recipient_manual = NULL; + } + +} -- 2.25.1