use Civi\Api4\PriceField;
use Civi\Api4\PriceSet;
use Civi\Api4\PriceSetEntity;
+use Civi\Payment\Exception\PaymentProcessorException;
+use Civi\Test\FormTrait;
+use Civi\Test\FormWrapper;
/**
* Test APIv3 civicrm_contribute_* functions
*/
class CRM_Contribute_Form_ContributionTest extends CiviUnitTestCase {
use CRMTraits_PCP_PCPTestTrait;
+ use FormTrait;
protected $_individualId;
protected $_contribution;
protected $_entity = 'Contribution';
protected $_params;
protected $_ids = [];
- protected $_userId;
-
- /**
- * Parameters to create payment processor.
- *
- * @var array
- */
- protected $_processorParams = [];
-
- /**
- * ID of created event.
- *
- * @var int
- */
- protected $_eventID;
-
- /**
- * Payment instrument mapping.
- *
- * @var array
- */
- protected $paymentInstruments = [];
/**
* Products.
/**
* Setup function.
- *
- * @throws \CRM_Core_Exception
*/
public function setUp(): void {
- $this->_apiversion = 3;
parent::setUp();
- $this->_userId = $this->createLoggedInUser();
+ $this->createLoggedInUser();
$this->_individualId = $this->ids['contact'][0] = $this->individualCreate();
$this->_params = [
'source' => 'SSF',
'contribution_status_id' => 1,
];
- $this->_processorParams = [
- 'domain_id' => 1,
- 'name' => 'Dummy',
- 'payment_processor_type_id' => 10,
- 'financial_account_id' => 12,
- 'is_active' => 1,
- 'user_name' => '',
- 'url_site' => 'http://dummy.com',
- 'url_recur' => 'http://dummy.com',
- 'billing_mode' => 1,
- ];
- $instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
- $this->paymentInstruments = $instruments['values'];
- $product1 = $this->callAPISuccess('product', 'create', [
+ $product1 = $this->callAPISuccess('Product', 'create', [
'name' => 'Smurf',
'options' => 'brainy smurf, clumsy smurf, papa smurf',
]);
/**
* Test the submit function on the contribution page.
- *
- * @throws \CRM_Core_Exception
*/
public function testSubmitCreditCardPayPal(): void {
- $mut = new CiviMailUtils($this, TRUE);
- $mut->clearMessages();
$paymentProcessorID = $this->paymentProcessorCreate(['is_test' => 0]);
$error = FALSE;
try {
- $this->submitContributionForm([
+ $form = $this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'billing_middle_name' => '',
'billing_last_name' => 'Adams',
'billing_street_address-5' => '790L Lincoln St S',
- 'billing_city-5' => 'Maryknoll',
+ 'billing_city-5' => 'Mary Knoll',
'billing_state_province_id-5' => 1031,
'billing_postal_code-5' => 10545,
'billing_country_id-5' => 1228,
'currency' => 'USD',
'source' => 'bob sled race',
], NULL, 'Live');
+ $this->assertEquals(1, $form->getMailCount());
}
- catch (Civi\Payment\Exception\PaymentProcessorException $e) {
+ catch (PaymentProcessorException $e) {
$error = TRUE;
}
]);
$this->assertEquals(1, $contribution['count'], 'Contribution count should be one.');
- $this->assertNotTrue(empty($contribution['values'][$contribution['id']]['receipt_date']), 'Receipt date should not be blank.');
+ $this->assertNotEmpty($contribution['values'][$contribution['id']]['receipt_date'], 'Receipt date should not be blank.');
$contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]);
- $this->assertTrue(empty($contact['source']));
- if (!$error) {
- $msgs = $mut->getAllMessages();
- $this->assertCount(1, $msgs);
- }
- $mut->clearMessages();
- $mut->stop();
+ $this->assertArrayNotHasKey('source', $contact);
}
/**
* Test the submit function on the contribution page
- *
- * @throws \CRM_Core_Exception
*/
public function testSubmitCreditCardWithEmailReceipt(): void {
- $mut = new CiviMailUtils($this, TRUE);
- $mut->clearMessages();
-
- $this->submitContributionForm([
+ $form = $this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'billing_middle_name' => '',
'billing_last_name' => 'Adams',
'billing_street_address-5' => '790L Lincoln St S',
- 'billing_city-5' => 'Maryknoll',
+ 'billing_city-5' => 'Mary Knoll',
'billing_state_province_id-5' => 1031,
'billing_postal_code-5' => 10545,
'billing_country_id-5' => 1228,
], 1);
$contact = $this->callAPISuccessGetSingle('Contact', ['id' => $this->_individualId]);
$this->assertArrayNotHasKey('source', $contact);
- $this->assertCount(1, $mut->getAllMessages());
- $mut->stop();
+ $this->assertEquals(1, $form->getMailCount());
}
/**
* Test the submit function on the contribution page.
- *
- * @throws \CRM_Core_Exception
*/
public function testSubmitCreditCardNoReceipt(): void {
$mut = new CiviMailUtils($this, TRUE);
* - 1 Contribution with status = Pending
* - 1 Line item
* - 1 civicrm_financial_item. This is linked to the line item and has a status of 3
- *
- * @throws \CRM_Core_Exception
*/
public function testSubmitCreditCardInvalid(): void {
- $form = new CRM_Contribute_Form_Contribution();
$this->paymentProcessor->setDoDirectPaymentResult(['is_error' => 1]);
try {
$this->submitContributionForm([
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2012],
'credit_card_number' => '411111111111111',
+ 'credit_card_type' => 'Visa',
], NULL, 'live');
}
catch (CRM_Core_Exception_PrematureExitException $e) {
/**
* Test the submit function creates a billing address if provided.
- *
- * @throws \CRM_Core_Exception
*/
public function testSubmitCreditCardWithBillingAddress(): void {
$this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
- 'contact_id' => $this->_individualId,
- 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
+ 'contact_id' => $this->individualCreate(),
+ 'payment_instrument_id' => $this->getPaymentInstrumentID('Credit Card'),
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
+ 'credit_card_type' => 'Visa',
'billing_city-5' => 'Vancouver',
], NULL, 'live');
$contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'address_id']);
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
+ 'credit_card_type' => 'Visa',
'billing_city-5' => 'Vancouver',
], NULL, 'live');
$contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'receive_date']);
$this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
- 'contact_id' => $this->_individualId,
- 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
+ 'contact_id' => $this->individualCreate(),
+ 'payment_instrument_id' => $this->getPaymentInstrumentID('Credit Card'),
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
+ 'credit_card_type' => 'Visa',
], NULL, 'live');
$contribution = $this->callAPISuccessGetSingle('Contribution', ['return' => 'address_id']);
$this->assertEmpty($contribution['address_id']);
* Test the submit function on the contribution page.
*/
public function testSubmitEmailReceipt(): void {
- $mut = new CiviMailUtils($this, TRUE);
- $this->submitContributionForm([
+ $contactID = $this->individualCreate();
+ $form = $this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
- 'contact_id' => $this->_individualId,
+ 'contact_id' => $contactID,
'is_email_receipt' => TRUE,
'from_email_address' => 'test@test.com',
'contribution_status_id' => 1,
]);
- $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
- $mut->checkMailLog([
- 'Contribution Information',
- ]);
- $mut->stop();
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $contactID], 1);
+ $this->assertStringContainsString('Contribution Information', $form->getFirstMailBody());
}
/**
*/
public function testSubmitEmailReceiptUserEmailFromAddress(): void {
$email = $this->callAPISuccess('Email', 'create', [
- 'contact_id' => $this->_userId,
+ 'contact_id' => $this->ids['Contact']['logged_in'],
'email' => 'testLoggedIn@example.com',
]);
- $mut = new CiviMailUtils($this, TRUE);
+
$this->submitContributionForm([
'contribution_status_id' => 1,
'total_amount' => 50,
]);
$this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
- $mut->checkMailLog([
- 'Below you will find a receipt for this contribution.',
- '<testloggedin@example.com>',
- ]);
- $mut->stop();
+ $this->assertMailSentContainingString('Below you will find a receipt for this contribution.');
+ $this->assertMailSentTo(['<testloggedin@example.com>']);
}
/**
* Test functions involving premiums.
*/
public function testPremiumUpdate(): void {
- $mut = new CiviMailUtils($this, TRUE);
$this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
]);
$contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', []);
$this->assertEquals('clumsy smurf', $contributionProduct['product_option']);
- $mut->checkMailLog([
+ $this->assertMailSentContainingStrings([
'Premium Information',
'Smurf',
'clumsy smurf',
]);
- $mut->stop();
+ $this->assertMailSentContainingStrings(['Smurf', 'clumsy smurf']);
}
/**
* Test functions involving premiums.
*/
public function testPremiumUpdateCreditCard(): void {
- $mut = new CiviMailUtils($this, TRUE);
- $this->submitContributionForm([
+ $form = $this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
'contact_id' => $this->_individualId,
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2026],
'credit_card_number' => '411111111111111',
+ 'credit_card_type' => 'Visa',
'hidden_Premium' => 1,
], NULL, 'live');
$contributionProduct = $this->callAPISuccess('contribution_product', 'getsingle', []);
$this->assertEquals('clumsy smurf', $contributionProduct['product_option']);
- $mut->checkMailLog([
- 'Premium Information',
- 'Smurf',
- 'clumsy smurf',
- ]);
- $mut->stop();
+ $this->assertStringContainsString('Premium Information', $form->getFirstMailBody());
+ $this->assertStringContainsString('Smurf', $form->getFirstMailBody());
+ $this->assertStringContainsString('clumsy smurf', $form->getFirstMailBody());
}
/**
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function testSubmitWithPCP(): void {
- $mut = new CiviMailUtils($this, TRUE);
- $mut->clearMessages();
$params = $this->pcpParams();
$pcpID = $this->createPCPBlock($params);
$this->submitContributionForm([
]);
$softCredit = $this->callAPISuccessGetSingle('ContributionSoft', []);
$this->assertEquals('Dobby', $softCredit['pcp_roll_nickname']);
- $mut->checkMailLog(['Personal Campaign Page Owner Notification']);
+ $this->assertMailSentContainingStrings(['Personal Campaign Page Owner Notification']);
}
/**
$this->submitContributionForm([
'total_amount' => 50,
'financial_type_id' => 1,
- 'contact_id' => $this->_individualId,
- 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
+ 'contact_id' => $this->individualCreate([], 'with_note'),
+ 'payment_instrument_id' => $this->getPaymentInstrumentID('Check'),
'contribution_status_id' => 1,
'note' => 'Super cool and interesting stuff',
]);
- $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->_individualId], 1);
+ $this->callAPISuccessGetCount('Contribution', ['contact_id' => $this->ids['Contact']['with_note']], 1);
$note = $this->callAPISuccessGetSingle('note', ['entity_table' => 'civicrm_contribution']);
$this->assertEquals('Super cool and interesting stuff', $note['note']);
}
* @dataProvider getThousandSeparators
*/
public function testSubmitUpdate(string $thousandSeparator): void {
+ $contactID = $this->individualCreate();
$this->setCurrencySeparators($thousandSeparator);
$this->submitContributionForm([
'total_amount' => $this->formatMoneyInput(6100.10),
'financial_type_id' => 1,
- 'contact_id' => $this->_individualId,
+ 'contact_id' => $contactID,
'payment_instrument_id' => $this->getPaymentInstrumentID('Check'),
'contribution_status_id' => 1,
]);
- $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $contactID]);
$this->submitContributionForm([
'total_amount' => $this->formatMoneyInput(5200.20),
'net_amount' => $this->formatMoneyInput(5200.20),
'financial_type_id' => 1,
- 'contact_id' => $this->_individualId,
+ 'contact_id' => $contactID,
'payment_instrument_id' => $this->getPaymentInstrumentID('Check'),
'contribution_status_id' => 1,
], $contribution['id']);
- $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
+ $contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $contactID]);
$this->assertEquals(5200.20, $contribution['total_amount'], 2);
- $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', ['sequential' => TRUE]);
- $this->assertEquals(2, $financialTransactions['count']);
- $this->assertEquals(6100.10, $financialTransactions['values'][0]['total_amount']);
- $this->assertEquals(-899.90, $financialTransactions['values'][1]['total_amount']);
- $this->assertEquals(-899.90, $financialTransactions['values'][1]['net_amount']);
+ $financialTransactions = $this->callAPISuccess('FinancialTrxn', 'get', ['sequential' => TRUE])['values'];
+ $this->assertCount(2, $financialTransactions);
+ $this->assertEquals(6100.10, $financialTransactions[0]['total_amount']);
+ $this->assertEquals(-899.90, $financialTransactions[1]['total_amount']);
+ $this->assertEquals(-899.90, $financialTransactions[1]['net_amount']);
$lineItem = $this->callAPISuccessGetSingle('LineItem', []);
$this->assertEquals(5200.20, $lineItem['line_total']);
}
$this->assertEquals(1200.55, $oldTrxn['total_amount']);
$this->assertEquals('123AX', $oldTrxn['check_number']);
- $this->assertEquals(array_search('Check', $this->paymentInstruments), $oldTrxn['payment_instrument_id']);
+ $this->assertEquals($this->getPaymentInstrumentID('Check'), $oldTrxn['payment_instrument_id']);
$this->assertEquals(-1200.55, $reversedTrxn['total_amount']);
$this->assertEquals('123AX', $reversedTrxn['check_number']);
- $this->assertEquals(array_search('Check', $this->paymentInstruments), $reversedTrxn['payment_instrument_id']);
+ $this->assertEquals($this->getPaymentInstrumentID('Check'), $reversedTrxn['payment_instrument_id']);
$this->assertEquals(1200.55, $latestTrxn['total_amount']);
$this->assertEquals('1011', $latestTrxn['pan_truncation']);
- $this->assertEquals(array_search('Credit Card', $this->paymentInstruments), $latestTrxn['payment_instrument_id']);
+ $this->assertEquals($this->getPaymentInstrumentID('Credit Card'), $latestTrxn['payment_instrument_id']);
$this->callAPISuccessGetSingle('LineItem', []);
}
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2012],
'credit_card_number' => '411111111111111',
+ 'credit_card_type' => 'Visa',
];
}
'total_amount' => 40,
'currency' => 'USD',
'financial_type_id' => 1,
- 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
+ 'payment_instrument_id' => $this->getPaymentInstrumentID('Credit Card'),
'payment_processor_id' => $this->paymentProcessorID,
'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
'credit_card_number' => '411111111111111',
* @group locale
*/
public function testSubmitSaleTax(string $thousandSeparator): void {
- $mailUtil = new CiviMailUtils($this, TRUE);
$this->setCurrencySeparators($thousandSeparator);
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($this->financialTypeID);
'from_email_address' => 'demo@example.com',
]);
- $mailUtil->checkAllMailLog([
+ $this->assertMailSentContainingStrings([
'Total Tax Amount : $' . $this->formatMoneyInput(100),
'Total Amount : $' . $this->formatMoneyInput(1100),
'Paid By: Check',
- ], []);
- $mailUtil->clearMessages();
+ ]);
$contribution = $this->callAPISuccessGetSingle('Contribution',
[
'from_email_address' => 'demo@example.com',
], $contribution['id']);
- $mailUtil->checkAllMailLog([
+ $this->assertMailSentContainingStrings([
'Total Tax Amount : $' . $this->formatMoneyInput(100),
'Total Amount : $' . $this->formatMoneyInput(1100),
'Paid By: Check',
- ], []);
+ ]);
$contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId]);
// Check if total amount is unchanged
$this->assertEquals(1100, $contribution['total_amount']);
}
/**
- * Test the submit function for FT without tax.
- *
- * @throws \CRM_Core_Exception
- * @throws \Civi\Payment\Exception\PaymentProcessorException
+ * Test the submit function for Financial Type without tax.
*/
public function testSubmitWithOutSaleTax(): void {
$this->enableTaxAndInvoicing();
$this->assertEquals(1000, $contribution['tax_amount']);
$this->assertEquals(11000, $contribution['net_amount']);
- $mut = new CiviMailUtils($this, TRUE);
// Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same:
$this->submitContributionForm([
'id' => $contribution['id'],
$this->assertEquals(1000, $contribution['tax_amount']);
$this->assertEquals(11000, $contribution['net_amount']);
- $strings = [
+ $this->assertMailSentContainingStrings([
'Total Tax Amount : $' . $this->formatMoneyInput(1000.00),
'Total Amount : $' . $this->formatMoneyInput(11000.00),
'Contribution Date: 04/21/2015',
'Paid By: Check',
'Check Number: 12345',
- ];
+ ]);
- $mut->checkMailLog($strings);
$this->callAPISuccessGetCount('FinancialTrxn', [], 3);
$items = $this->callAPISuccess('FinancialItem', 'get', ['sequential' => 1])['values'];
$this->assertCount(2, $items);
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($this->financialTypeID);
$contribution = $this->doInitialSubmit();
-
- $mut = new CiviMailUtils($this, TRUE);
// Testing here if when we edit something trivial like adding a check_number tax, net, total amount stay the same:
$this->submitContributionForm([
'id' => $contribution['id'],
$this->assertEquals(2000, $contribution['tax_amount']);
$this->assertEquals(22000, $contribution['net_amount']);
- $strings = [
+ $this->assertMailSentContainingStrings([
'Total Tax Amount : $' . $this->formatMoneyInput(2000),
'Total Amount : $' . $this->formatMoneyInput(22000.00),
'Contribution Date: 04/21/2015',
'Paid By: Check',
'Check Number: 12345',
'Financial Type: Donation',
- ];
+ ]);
- $mut->checkMailLog($strings);
$this->callAPISuccessGetCount('FinancialTrxn', [], 4);
$items = $this->callAPISuccess('FinancialItem', 'get', ['sequential' => 1]);
$this->assertEquals(4, $items['count']);
*
* @throws \Exception
*/
- protected function doInitialSubmit() {
+ protected function doInitialSubmit(): array {
$this->submitContributionForm([
'total_amount' => $this->formatMoneyInput(10000),
'financial_type_id' => $this->financialTypeID,
'total_amount' => 100,
'financial_type_id' => 3,
'contact_id' => $this->_individualId,
- 'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
+ 'payment_instrument_id' => $this->getPaymentInstrumentID('Credit Card'),
'contribution_status_id' => 1,
'credit_card_type' => 'Visa',
'pan_truncation' => 4567,
//Disable all the payment processor for the contribution page.
$params['is_pay_later'] = 0;
- $page2 = $this->callAPISuccess('ContributionPage', 'create', $params);
-
- // @todo - these lines were supposed to assert an exception is thrown on loading the contribution page.
- // However the test has been quietly passing with that not happening.
- /* @var \CRM_Contribute_Form_Contribution_Main $form */
- // $form = $this->getFormObject('CRM_Contribute_Form_Contribution_Main', ['payment_processor_id' => 0]);
- // $_REQUEST['id'] = $page2['id'];
- // $form->preProcess();
+ $this->callAPISuccess('ContributionPage', 'create', $params);
}
/**
$form = new CRM_Contribute_Form_Contribution_Confirm();
$form->_params = [
'id' => $contribPage1,
- 'qfKey' => 'donotcare',
+ 'qfKey' => 'abc',
"custom_{$membershipCustomField['id']}" => 'Hello',
'priceSetId' => $priceSet['id'],
'price_set_id' => $priceSet['id'],
$form->controller = new CRM_Core_Controller();
$form->_params = [
'id' => $this->_ids['contribution_page'],
- 'qfKey' => 'donotcare',
+ 'qfKey' => 'abc',
'priceSetId' => $this->_ids['price_set'],
'price_set_id' => $this->_ids['price_set'],
'price_' . $this->_ids['price_field'][0] => $this->_ids['price_field_value']['cont'],
$form->_action = CRM_Core_Action::UPDATE;
$form->preProcess();
- // Check something while we're here
+ // Check something while we're here.
$this->assertEquals($contribution['id'], $form->_values['contribution_id']);
-
- unset($_REQUEST['cid']);
- unset($_REQUEST['id']);
}
/**
* @param array $input
* @param array $expectedFormatted
*/
- public function testAdditionalInfoPostProcessCommon(array $input, array $expectedFormatted) {
+ public function testAdditionalInfoPostProcessCommon(array $input, array $expectedFormatted): void {
$formatted = [];
$dummy = new CRM_Contribute_Form_AdditionalInfo();
CRM_Contribute_Form_AdditionalInfo::postProcessCommon($input, $formatted, $dummy);
}
/**
- * Dataprovider for testAdditionalInfoPostProcessCommon
+ * Data provider for testAdditionalInfoPostProcessCommon.
+ *
* @return array
*/
public function additionalInfoProvider(): array {
return [
'no-date' => [
'input' => [
- 'qfKey' => 'CRMContributeFormContributionu2pbzqqmz74oscck4ss4osccw4wgccc884wkk4ws0o8wgss4w_8953',
- 'entryURL' => 'http://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution',
+ 'qfKey' => 'CRMContributeFormContribution1u2pbzqqmz74oscck4ss4osccw4wgccc884wkk4ws0o8wgss4w_8953',
+ 'entryURL' => 'https://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution',
'check_number' => '',
'frequency_interval' => '1',
'hidden_AdditionalDetail' => '1',
'trxn_id' => '',
'from_email_address' => '2',
'contribution_status_id' => '1',
- // This is unused here but is iffy to put in a dataprovider
+ // This is unused here but is iffy to put in a Data Provider
'receive_date' => '2021-01-14 11:12:13',
'receipt_date' => '',
'cancel_date' => '',
'date-no-time' => [
'input' => [
- 'qfKey' => 'CRMContributeFormContributionu2pbzqqmz74oscck4ss4osccw4wgccc884wkk4ws0o8wgss4w_8953',
- 'entryURL' => 'http://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution',
+ 'qfKey' => 'abc',
+ 'entryURL' => 'https://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution',
'id' => '40',
'frequency_interval' => '1',
'hidden_AdditionalDetail' => '1',
'financial_type_id' => '1',
'from_email_address' => '2',
'contribution_status_id' => '1',
- // This is unused here but is iffy to put in a dataprovider
'receive_date' => '2021-01-14 11:12:13',
'receipt_date' => '',
'cancel_date' => '',
'date-and-time' => [
'input' => [
- 'qfKey' => 'CRMContributeFormContributionu2pbzqqmz74oscck4ss4osccw4wgccc884wkk4ws0o8wgss4w_8953',
- 'entryURL' => 'http://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution',
+ 'qfKey' => 'abc',
+ 'entryURL' => 'https://example.org/civicrm/contact/view/contribution?reset=1&action=add&cid=1&context=contribution',
'id' => '40',
'frequency_interval' => '1',
'hidden_AdditionalDetail' => '1',
'financial_type_id' => '1',
'from_email_address' => '2',
'contribution_status_id' => '1',
- // This is unused here but is iffy to put in a dataprovider
'receive_date' => '2021-01-14 11:12:13',
'receipt_date' => '',
'cancel_date' => '',
/**
* Submit the contribution form.
*
- * @param array $formValues
+ * @param array $submittedValues
* @param int|null $contributionID
* @param string|null $cardMode
* Either 'test' or 'live' or NULL
* @param int|null $pledgePaymentID
+ *
+ * @return \Civi\Test\FormWrapper
*/
- protected function submitContributionForm(array $formValues, ?int $contributionID = NULL, ?string $cardMode = NULL, ?int $pledgePaymentID = NULL): void {
- if ($contributionID) {
- $_REQUEST['action'] = 'update';
- $_REQUEST['id'] = $contributionID;
- }
- if ($cardMode) {
- $_REQUEST['mode'] = $cardMode;
- }
- $_REQUEST['ppid'] = $pledgePaymentID;
- $form = $this->getContributionForm($formValues);
- $form->postProcess();
+ protected function submitContributionForm(array $submittedValues, ?int $contributionID = NULL, ?string $cardMode = NULL, ?int $pledgePaymentID = NULL): FormWrapper {
+ $form = $this->getTestForm('CRM_Contribute_Form_Contribution', $submittedValues,
+ [
+ 'id' => $contributionID,
+ 'mode' => $cardMode,
+ 'action' => $contributionID ? 'update' : 'add',
+ 'ppid' => $pledgePaymentID,
+ ]
+ );
+ $form->processForm();
+ return $form;
}
}