From a6c57feec09e8784a4f34a4ce11d0429eab79865 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Tue, 26 Jan 2016 18:22:07 -0800 Subject: [PATCH] CRM-16514 - CRM_Contribute_ActionMapping_ByTypeTest - Add test case for "limit_to/recipient_manual" --- .../Contribute/ActionMapping/ByTypeTest.php | 45 ++++++++++++ .../ActionSchedule/AbstractMappingTest.php | 69 ++++++++++++++++--- 2 files changed, 103 insertions(+), 11 deletions(-) diff --git a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php index bbc918759e..08c037fa1a 100644 --- a/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php +++ b/tests/phpunit/CRM/Contribute/ActionMapping/ByTypeTest.php @@ -26,6 +26,14 @@ */ /** + * Class CRM_Contribute_ActionMapping_ByTypeTest + * @group ActionSchedule + * + * This class tests various configurations of scheduled-reminders, with a focus on + * reminders for *contribution types*. It follows a design/pattern described in + * AbstractMappingTest. + * + * @see \Civi\ActionSchedule\AbstractMappingTest * @group headless */ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\AbstractMappingTest { @@ -48,6 +56,43 @@ class CRM_Contribute_ActionMapping_ByTypeTest extends \Civi\ActionSchedule\Abstr $cs[] = array( '2015-02-01 00:00:00', + 'addAliceDues scheduleForAny startOnTime useHelloFirstName alsoRecipientBob', + 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/', + // It might make more sense to get Alice's details... but path of least resistance... + ), + ), + ); + + $cs[] = array( + '2015-02-01 00:00:00', + 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientBob', + array(), + ); + + $cs[] = array( + '2015-02-01 00:00:00', + 'addAliceDues scheduleForAny startOnTime useHelloFirstName limitToRecipientAlice', + 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', + // 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstName', 'addAliceDues addBobDonation scheduleForDues startOnTime useHelloFirstNameStatus', array( array( diff --git a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php index 9d49fd77be..1077baedd6 100644 --- a/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php +++ b/tests/phpunit/Civi/ActionSchedule/AbstractMappingTest.php @@ -3,23 +3,40 @@ namespace Civi\ActionSchedule; /** * The AbstractMappingTest is a base class which can help define new - * tests for ActionMappings. Concrete classes should implement a few - * elements: + * tests for scheduled-reminders. * - * - Optionally, override clock() to specify when the cron jobs run. - * (By default, clock specifies daily from 20-Jan-15 to 1-Mar-15.) + * Generally, the problem of testing scheduled-reminders is one of permutations -- + * there are many different types of records, fields on the records, and scheduling options. + * To test these, we setup a schedule of cron-runs (eg Jan 20 to Mar 1) and create some example + * records. + * + * To setup the examples, we need to string together several helper functions, like: + * + * - startOnTime(), startWeekBefore(), or startWeekAfter() + * - repeatTwoWeeksAfter() + * - limitToRecipientAlice(), limitToRecipientBob(), alsoRecipientBob() + * - addAliceDues(), addBobDonation() + * - addAliceMeeting(), addBobPhoneCall() + * + * (Some of these helpers are defined in AbstractMappingTest. Some are defined in subclasses.) + * + * Concrete subclasses should implement a few elements: + * + * - Optionally, modify $cronSchedule to specify when the cron jobs run. + * (By default, it specifies daily from 20-Jan-15 to 1-Mar-15.) * - Implement at least one setup-helper which creates example records. * The example records should use the specified date (`$this->targetDate`) - * and should relate to `$this->matchedContact`. Additionally, the - * setup-helper should created spurious contacts which are almost - * (but not quite) matched to the schedule rules. - * - Implement at least one schedule-helper which configures `$this->scheduled` + * and should relate to `$this->contact['alice']` (or 'bob 'or 'carol'). + * - Implement at least one schedule-helper which configures `$this->schedule` * to use the preferred action mapping. It may define various - * filters, such value-filters, status-filters, or recipient-filters. + * filters, such as value-filters, status-filters, or recipient-filters. * - Implement `createTestCases()` which defines various - * permutations of tests to run. + * permutations of tests to run. Each test provides a list of emails + * which should be fired (datetime/recipient/subject). * - * For an example, see CRM_Contribute_ActionMapping_ByTypeTest. + * For examples: + * @see CRM_Contribute_ActionMapping_ByTypeTest + * @see CRM_Activity_ActionMappingTest */ abstract class AbstractMappingTest extends \CiviUnitTestCase { @@ -132,6 +149,36 @@ abstract class AbstractMappingTest extends \CiviUnitTestCase { $this->schedule->body_text = 'Hello, {contact.first_name}. (via body_text)'; } + /** + * Limit possible recipients to Alice. + */ + public function limitToRecipientAlice() { + $this->schedule->limit_to = 1; + $this->schedule->recipient = NULL; + $this->schedule->recipient_listing = NULL; + $this->schedule->recipient_manual = $this->contacts['alice']['id']; + } + + /** + * Limit possible recipients to Bob. + */ + public function limitToRecipientBob() { + $this->schedule->limit_to = 1; + $this->schedule->recipient = NULL; + $this->schedule->recipient_listing = NULL; + $this->schedule->recipient_manual = $this->contacts['bob']['id']; + } + + /** + * Also include recipient Bob. + */ + public function alsoRecipientBob() { + $this->schedule->limit_to = 0; + $this->schedule->recipient = NULL; + $this->schedule->recipient_listing = NULL; + $this->schedule->recipient_manual = $this->contacts['bob']['id']; + } + // ---------------------------------------- Core test definitions ---------------------------------------- /** -- 2.25.1