namespace Civi\Test;
+use Civi\Api4\UFField;
+use Civi\Api4\UFGroup;
+use Civi\Api4\UFJoin;
+
/**
* Helper for event tests.
*
'pay_later_text' => 'Send Money Now',
];
$contributionPageValues += $contributionPageDefaults;
- return $this->createTestEntity('ContributionPage', $contributionPageValues, $identifier);
+ $return = $this->createTestEntity('ContributionPage', $contributionPageValues, $identifier);
+ $this->addProfilesToContributionPage();
+ return $return;
}
/**
], 'check_box');
}
+ /**
+ * Add profiles to the event.
+ *
+ * This function is designed to reflect the
+ * normal use case where events do have profiles.
+ *
+ * Note if any classes do not want profiles, or want something different,
+ * the thinking is they should override this. Once that arises we can review
+ * making it protected rather than private & checking we are happy with the
+ * signature.
+ *
+ * @param string $identifier
+ */
+ private function addProfilesToContributionPage(string $identifier = 'ContributionPage'): void {
+ $profiles = [
+ ['name' => '_pre', 'title' => 'Page Pre Profile', 'weight' => 1, 'fields' => ['email']],
+ ['name' => '_post', 'title' => 'Page Post Profile', 'weight' => 2, 'fields' => ['first_name', 'last_name']],
+ ];
+ foreach ($profiles as $profile) {
+ $this->createContributionPageProfile($profile, $identifier);
+ }
+ }
+
+ /**
+ * Create a profile attached to an event.
+ *
+ * @param array $profile
+ * @param string $identifier
+ */
+ private function createContributionPageProfile(array $profile, string $identifier): void {
+ $profileName = $identifier . $profile['name'];
+ $profileIdentifier = $profileName;
+ try {
+ $this->setTestEntity('UFGroup', UFGroup::create(FALSE)->setValues([
+ 'group_type' => 'Individual,Contact',
+ 'name' => $profileName,
+ 'title' => $profile['title'],
+ 'frontend_title' => 'Public ' . $profile['title'],
+ ])->execute()->first(),
+ $profileIdentifier);
+ }
+ catch (\CRM_Core_Exception $e) {
+ $this->fail('UF group creation failed for ' . $profileName . ' with error ' . $e->getMessage());
+ }
+ foreach ($profile['fields'] as $field) {
+ $this->setTestEntity('UFField', UFField::create(FALSE)
+ ->setValues([
+ 'uf_group_id:name' => $profileName,
+ 'field_name' => $field,
+ 'label' => $field,
+ ])
+ ->execute()
+ ->first(), $field . '_' . $profileIdentifier);
+ }
+ try {
+ $this->setTestEntity('UFJoin', UFJoin::create(FALSE)->setValues([
+ 'module' => 'CiviContribute',
+ 'uf_group_id:name' => $profileName,
+ 'entity_id' => $this->getContributionPageID($identifier),
+ ])->execute()->first(), $profileIdentifier);
+ }
+ catch (\CRM_Core_Exception $e) {
+ $this->fail('UF join creation failed for UF Group ' . $profileName . ' with error ' . $e->getMessage());
+ }
+ }
+
}
'id' => $this->getContributionPageID(),
'first_name' => 'J',
'last_name' => 'T',
- 'email' => 'JT@ohcanada.ca',
+ 'email-5' => 'JT@ohcanada.ca',
'receive_date' => date('Y-m-d H:i:s'),
'payment_processor_id' => 0,
'priceSetId' => $this->getPriceSetID('ContributionPage'),
$lineItems = LineItem::get()->addWhere('contribution_id', '=', $contribution['id'])->execute();
$this->assertEquals($lineItems[0]['line_total'] + $lineItems[1]['line_total'] + $lineItems[2]['line_total'], round($totalAmount, 2), 'Line Item Total is incorrect.');
$this->assertEquals(round($lineItems[0]['tax_amount'] + $lineItems[1]['tax_amount'] + $lineItems[2]['tax_amount'], 2), round($taxAmount, 2), 'Wrong Sales Tax Amount is calculated and stored.');
+ $mailUtil = new CiviMailUtils($this);
+ $this->callAPISuccess('Payment', 'create', [
+ 'contribution_id' => $contribution['id'],
+ 'total_amount' => round($totalAmount + $taxAmount, 2),
+ 'payment_instrument_id' => 'Check',
+ ]);
+ $mailUtil->checkMailLog([\Civi::format()->money(337.55), 'Tax Rate', 'Subtotal']);
}
}