Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial test on event tokens #21563

Merged
merged 2 commits into from
Sep 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions tests/phpunit/CRM/Utils/TokenConsistencyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -446,6 +450,32 @@ protected function getMembershipID(): int {
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
[email protected]
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.
*
Expand Down Expand Up @@ -532,6 +562,9 @@ public function getDomainTokens(): array {
* 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(), [
Expand All @@ -540,6 +573,57 @@ public function testEventTokenConsistency(): void {
'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' => '[email protected]'])->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())),
]);
}

/**
Expand All @@ -563,6 +647,7 @@ protected function getEventTokens(): array {
'{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',
];
}

Expand Down
11 changes: 6 additions & 5 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ public function paymentProcessorAuthorizeNetCreate($params = []) {
* @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();
}
Expand Down Expand Up @@ -1097,9 +1097,8 @@ public function contributionDelete($contributionId) {
* 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([
Expand All @@ -1113,7 +1112,7 @@ public function eventCreate($params = []) {
$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,
Expand All @@ -1129,7 +1128,9 @@ public function eventCreate($params = []) {
'is_email_confirm' => 1,
], $params);

return $this->callAPISuccess('Event', 'create', $params);
$event = $this->callAPISuccess('Event', 'create', $params);
$this->ids['event'][] = $event['id'];
return $event;
}

/**
Expand Down
69 changes: 4 additions & 65 deletions tests/phpunit/api/v3/ParticipantPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class api_v3_ParticipantPaymentTest extends CiviUnitTestCase {
public function setUp(): void {
parent::setUp();
$this->useTransaction(TRUE);
$event = $this->eventCreate(NULL);
$event = $this->eventCreate();
$this->_eventID = $event['id'];
$this->_contactID = $this->individualCreate();
$this->_createdParticipants = [];
Expand Down Expand Up @@ -60,29 +60,10 @@ public function setUp(): void {
]);
}

/**
* Test civicrm_participant_payment_create with empty params.
*/
public function testPaymentCreateEmptyParams() {
$params = [];
$this->callAPIFailure('participant_payment', 'create', $params);
}

/**
* Check without contribution_id.
*/
public function testPaymentCreateMissingContributionId() {
//Without Payment EntityID
$params = [
'participant_id' => $this->_participantID,
];
$this->callAPIFailure('participant_payment', 'create', $params);
}

/**
* Check with valid array.
*/
public function testPaymentCreate() {
public function testPaymentCreate(): void {
//Create Contribution & get contribution ID
$contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]);

Expand All @@ -92,18 +73,14 @@ public function testPaymentCreate() {
'contribution_id' => $contributionID,
];

$result = $this->callAPIAndDocument('participant_payment', 'create', $params, __FUNCTION__, __FILE__);
$this->assertTrue(array_key_exists('id', $result));

//delete created contribution
$this->contributionDelete($contributionID);
$this->callAPIAndDocument('participant_payment', 'create', $params, __FUNCTION__, __FILE__);
}

/**
* Test getPaymentInfo() returns correct
* information of the participant payment
*/
public function testPaymentInfoForEvent() {
public function testPaymentInfoForEvent(): void {
//Create Contribution & get contribution ID
$contributionID = $this->contributionCreate(['contact_id' => $this->_contactID]);

Expand All @@ -120,35 +97,6 @@ public function testPaymentInfoForEvent() {
$this->assertEquals('100.00', $paymentInfo['total']);
}

///////////////// civicrm_participant_payment_create methods

/**
* Check with empty array.
*/
public function testPaymentUpdateEmpty() {
$this->callAPIFailure('participant_payment', 'create', []);
}

/**
* Check with missing participant_id.
*/
public function testPaymentUpdateMissingParticipantId() {
$params = [
'contribution_id' => '3',
];
$this->callAPIFailure('participant_payment', 'create', $params);
}

/**
* Check with missing contribution_id.
*/
public function testPaymentUpdateMissingContributionId() {
$params = [
'participant_id' => $this->_participantID,
];
$participantPayment = $this->callAPIFailure('participant_payment', 'create', $params);
}

/**
* Check financial records for offline Participants.
*/
Expand Down Expand Up @@ -251,15 +199,6 @@ public function testPaymentPayLaterOnline() {
$this->callAPISuccess('participant_payment', 'delete', $params);
}

/**
* Check with empty array.
*/
public function testPaymentDeleteWithEmptyParams() {
$params = [];
$deletePayment = $this->callAPIFailure('participant_payment', 'delete', $params);
$this->assertEquals('Mandatory key(s) missing from params array: id', $deletePayment['error_message']);
}

/**
* Check with wrong id.
*/
Expand Down
Loading