-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24265 from eileenmcnaughton/welcome
Add GroupTokens to replace WelcomeTokens
- Loading branch information
Showing
8 changed files
with
151 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* Class CRM_Core_GroupTokens | ||
* | ||
* Generate "member.*" tokens. | ||
*/ | ||
class CRM_Core_GroupTokens extends CRM_Core_EntityTokens { | ||
|
||
/** | ||
* Get the entity name for api v4 calls. | ||
* | ||
* @return string | ||
*/ | ||
protected function getApiEntityName(): string { | ||
return 'Group'; | ||
} | ||
|
||
/** | ||
* List out the fields that are exposed. | ||
* | ||
* @return string[] | ||
*/ | ||
protected function getExposedFields(): array { | ||
return [ | ||
'id', | ||
'name', | ||
'title', | ||
'frontend_title', | ||
'frontend_description', | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
use Civi\Api4\Group; | ||
use Civi\Api4\GroupContact; | ||
use Civi\Api4\Mailing; | ||
use Civi\Api4\MailingGroup; | ||
use Civi\Api4\SubscriptionHistory; | ||
|
||
/** | ||
* Class CRM_Mailing_BAO_MailingTest | ||
*/ | ||
class CRM_Mailing_BAO_ConfirmTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* Cleanup after test. | ||
*/ | ||
public function tearDown(): void { | ||
$this->quickCleanup(['civicrm_group', 'civicrm_group_contact', 'civicrm_mailing', 'civicrm_mailing_group', 'civicrm_mailing_event_subscribe']); | ||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* Test confirm function, with group token. | ||
* | ||
* @throws CRM_Core_Exception | ||
*/ | ||
public function testConfirm(): void { | ||
$mailUtil = new CiviMailUtils($this); | ||
$contactID = $this->individualCreate(); | ||
$groupID = Group::create()->setValues([ | ||
'name' => 'Test Group', | ||
'title' => 'Test Group', | ||
'frontend_title' => 'Test Group', | ||
])->execute()->first()['id']; | ||
GroupContact::create()->setValues(['contact_id' => $contactID, 'status' => 'Added', 'group_id' => $groupID])->execute(); | ||
SubscriptionHistory::create()->setValues([ | ||
'contact_id' => $contactID, | ||
'group_id' => $groupID, | ||
'method' => 'Email', | ||
])->execute(); | ||
$mailingID = Mailing::create()->execute()->first()['id']; | ||
MailingGroup::create()->setValues([ | ||
'mailing_id' => $mailingID, | ||
'group_type' => 'Include', | ||
'entity_table' => 'civicrm_group', | ||
'entity_id' => $groupID, | ||
])->execute()->first()['id']; | ||
|
||
$mailingComponentID = $this->callAPISuccess('MailingComponent', 'get', ['component_type' => 'Welcome'])['id']; | ||
$this->callAPISuccess('MailingComponent', 'create', [ | ||
// Swap {welcome.group} to {group.frontend_title} which is the standardised token. | ||
// The intent is to make this version the default, but need to ensure it is required. | ||
'body_html' => 'Welcome. Your subscription to the {group.frontend_title} mailing list has been activated.', | ||
'body_text' => 'Welcome. Your subscription to the {group.frontend_title} mailing list has been activated.', | ||
'id' => $mailingComponentID, | ||
]); | ||
$hash = 4; | ||
CRM_Core_DAO::executeQuery(" | ||
INSERT INTO civicrm_mailing_event_subscribe (group_id, contact_id, hash) VALUES ($groupID, $contactID, $hash) | ||
"); | ||
|
||
CRM_Mailing_Event_BAO_Confirm::confirm($contactID, 1, $hash); | ||
$mailUtil->checkAllMailLog([ | ||
'From: "FIXME" <[email protected]>', | ||
'To: "Mr. Anthony Anderson II" <[email protected]>', | ||
'Subject: Your Subscription has been Activated', | ||
'Welcome. Your subscription to the Test Group mailing list has been activated.', | ||
]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ class CRM_Mailing_BAO_MailingJobTest extends CiviUnitTestCase { | |
/** | ||
* Tests CRM_Mailing_BAO_MailingJob::isTemporaryError() method. | ||
*/ | ||
public function testIsTemporaryError() { | ||
public function testIsTemporaryError(): void { | ||
$testcases[] = ['return' => TRUE, 'message' => 'Failed to set sender: [email protected] [SMTP: Invalid response code received from SMTP server while sending email. This is often caused by a misconfiguration in Outbound Email settings. Please verify the settings at Administer CiviCRM >> Global Settings >> Outbound Email (SMTP). (code: 421, response: Timeout waiting for data from client.)]']; | ||
$testcases[] = ['return' => TRUE, 'message' => 'Failed to send data [SMTP: Invalid response code received from SMTP server while sending email. This is often caused by a misconfiguration in Outbound Email settings. Please verify the settings at Administer CiviCRM >> Global Settings >> Outbound Email (SMTP). (code: 454, response: Throttling failure: Maximum sending rate exceeded.)]']; | ||
$testcases[] = ['return' => TRUE, 'message' => 'Failed to set sender: [email protected] [SMTP: Failed to write to socket: not connected (code: -1, response: )]']; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters