From: Eileen McNaughton Date: Tue, 21 Sep 2021 09:06:13 +0000 (+1200) Subject: Initial test on event tokens X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=f399fbd861f957d61caffe891bd1c54209957e58;p=civicrm-core.git Initial test on event tokens Note there is an issue to do with caching affecting the custom token but it's out of scope on this test --- diff --git a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php index 0a0ab45571..b1c36e62aa 100644 --- a/tests/phpunit/CRM/Utils/TokenConsistencyTest.php +++ b/tests/phpunit/CRM/Utils/TokenConsistencyTest.php @@ -10,6 +10,10 @@ */ use Civi\Token\TokenProcessor; +use Civi\Api4\LocBlock; +use Civi\Api4\Email; +use Civi\Api4\Phone; +use Civi\Api4\Address; /** * CRM_Utils_TokenConsistencyTest @@ -446,6 +450,32 @@ Check'; return $this->ids['Membership'][0]; } + /** + * Get expected output from token parsing. + * + * @return string + */ + protected function getExpectedEventTokenOutput(): string { + return ' +1 +Annual CiviCRM meet +October 21st, 2008 12:00 AM +October 23rd, 2008 12:00 AM +Conference +If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now +event@example.com +456 789 +event description +15 Walton St +Emerald City, Maine 90210 + +$ 50.00 +' . CRM_Utils_System::url('civicrm/event/info', NULL, TRUE) . '&reset=1&id=1 +' . CRM_Utils_System::url('civicrm/event/register', NULL, TRUE) . '&reset=1&id=1 + +my field'; + } + /** * Get expected output from token parsing. * @@ -532,6 +562,9 @@ December 21st, 2007 * Test that domain tokens are consistently rendered. */ public function testEventTokenConsistency(): void { + $mut = new CiviMailUtils($this); + $this->setupParticipantScheduledReminder(); + $tokens = CRM_Core_SelectValues::eventTokens(); $this->assertEquals($this->getEventTokens(), $tokens); $tokenProcessor = new TokenProcessor(\Civi::dispatcher(), [ @@ -540,6 +573,57 @@ December 21st, 2007 'schema' => ['eventId'], ]); $this->assertEquals(array_merge($tokens, $this->getDomainTokens()), $tokenProcessor->listTokens()); + + $this->callAPISuccess('job', 'send_reminder', []); + $expected = $this->getExpectedEventTokenOutput(); + $mut->checkMailLog([$expected]); + } + + /** + * Set up scheduled reminder for participants. + * + * @throws \API_Exception + */ + public function setupParticipantScheduledReminder(): void { + $this->createCustomGroupWithFieldOfType(['extends' => 'Event']); + $emailID = Email::create()->setValues(['email' => 'event@example.com'])->execute()->first()['id']; + $addressID = Address::create()->setValues([ + 'street_address' => '15 Walton St', + 'supplemental_address_1' => 'up the road', + 'city' => 'Emerald City', + 'state_province_id:label' => 'Maine', + 'postal_code' => 90210, + ])->execute()->first()['id']; + $phoneID = Phone::create()->setValues(['phone' => '456 789'])->execute()->first()['id']; + + $locationBlockID = LocBlock::save(FALSE)->setRecords([ + [ + 'email_id' => $emailID, + 'address_id' => $addressID, + 'phone_id' => $phoneID, + ], + ])->execute()->first()['id']; + $event = $this->eventCreate([ + 'description' => 'event description', + $this->getCustomFieldName('text') => 'my field', + 'loc_block_id' => $locationBlockID, + ]); + // Create an unrelated participant record so that the ids don't match. + // this prevents things working just because the id 'happens to be valid' + $this->participantCreate(['register_date' => '2020-01-01', 'event_id' => $event['id']]); + $this->participantCreate(['event_id' => $event['id'], 'fee_amount' => 50]); + CRM_Utils_Time::setTime('2007-02-20 15:00:00'); + $this->callAPISuccess('action_schedule', 'create', [ + 'title' => 'job', + 'subject' => 'job', + 'entity_value' => 1, + 'mapping_id' => 2, + 'start_action_date' => 'register_date', + 'start_action_offset' => 1, + 'start_action_condition' => 'after', + 'start_action_unit' => 'day', + 'body_html' => implode("\n", array_keys($this->getEventTokens())), + ]); } /** @@ -563,6 +647,7 @@ December 21st, 2007 '{event.info_url}' => 'Event Info URL', '{event.registration_url}' => 'Event Registration URL', '{event.balance}' => 'Event Balance', + '{event.' . $this->getCustomFieldName('text') . '}' => 'Enter text here :: Group with field text', ]; } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 5a0bbb29a6..8c3dbc2982 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -855,7 +855,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * @return int * $id of participant created */ - public function participantCreate($params = []) { + public function participantCreate(array $params = []) { if (empty($params['contact_id'])) { $params['contact_id'] = $this->individualCreate(); } @@ -1097,9 +1097,8 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { * Name-value pair for an event. * * @return array - * @throws \CRM_Core_Exception */ - public function eventCreate($params = []) { + public function eventCreate(array $params = []): array { // if no contact was passed, make up a dummy event creator if (!isset($params['contact_id'])) { $params['contact_id'] = $this->_contactCreate([ @@ -1113,7 +1112,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { $params = array_merge([ 'title' => 'Annual CiviCRM meet', 'summary' => 'If you have any CiviCRM related issues or want to track where CiviCRM is heading, Sign up now', - 'description' => 'This event is intended to give brief idea about progess of CiviCRM and giving solutions to common user issues', + 'description' => 'This event is intended to give brief idea about progress of CiviCRM and giving solutions to common user issues', 'event_type_id' => 1, 'is_public' => 1, 'start_date' => 20081021, @@ -1129,7 +1128,9 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { 'is_email_confirm' => 1, ], $params); - return $this->callAPISuccess('Event', 'create', $params); + $event = $this->callAPISuccess('Event', 'create', $params); + $this->ids['event'][] = $event['id']; + return $event; } /**