* @throws \CiviCRM_API3_Exception
*/
public function testSubmit(): void {
- $form = $this->getForm();
$loggedInUserID = $this->createLoggedInUser();
$loggedInUserDisplayName = Contact::get()->addWhere('id', '=', $loggedInUserID)->addSelect('display_name')->execute()->first()['display_name'];
$params = $this->getBaseSubmitParams();
+ $form = $this->getForm(array_merge($params, ['total_amount' => 50]));
$form->_contactID = $this->_individualId;
$form->testSubmit(array_merge($params, ['total_amount' => 50]));
public function testSubmitWithTax(): void {
$this->enableTaxAndInvoicing();
$this->addTaxAccountToFinancialType($this->financialTypeID);
- $form = $this->getForm();
- $form->testSubmit(array_merge($this->getBaseSubmitParams(), [
+ $form = $this->getForm(array_merge($this->getBaseSubmitParams(), [
'total_amount' => '50.00',
]));
+ $form->testSubmit();
$contribution = $this->callAPISuccessGetSingle('Contribution', ['contact_id' => $this->_individualId, 'is_test' => TRUE, 'return' => ['total_amount', 'tax_amount']]);
$this->assertEquals(50, $contribution['total_amount']);
$this->assertEquals(4.55, $contribution['tax_amount']);
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitRecur(): void {
- $form = $this->getForm();
$this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'duration_interval' => 1,
'auto_renew' => TRUE,
]);
- $form->preProcess();
- $this->createLoggedInUser();
- $params = [
- 'cid' => $this->_individualId,
+ $form = $this->getForm([
+ 'contact_id' => $this->_individualId,
'price_set_id' => 0,
'join_date' => CRM_Utils_Time::date('m/d/Y'),
'start_date' => '',
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '9',
- 'Y' => CRM_Utils_Time::date('Y') + 1,
+ 'Y' => (int) CRM_Utils_Time::date('Y') + 1,
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
'send_receipt' => 1,
- ];
+ ]);
+ $this->createLoggedInUser();
$form->_mode = 'test';
$form->_contactID = $this->_individualId;
- $form->testSubmit($params);
+ $form->testSubmit();
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals(1, $contributionRecur['is_email_receipt']);
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitRecurCompleteInstant(): void {
- $form = $this->getForm();
/** @var \CRM_Core_Payment_Dummy $processor */
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
$processor->setDoDirectPaymentResult([
'auto_renew' => TRUE,
]);
$this->createLoggedInUser();
- $form->preProcess();
+ $form = $this->getForm(array_merge($this->getBaseSubmitParams(), ['is_recur' => 1, 'auto_renew' => '1']));
$form->_contactID = $this->_individualId;
- $params = array_merge($this->getBaseSubmitParams(), ['is_recur' => 1, 'auto_renew' => '1']);
$form->_mode = 'test';
- $form->testSubmit($params);
+ $form->testSubmit();
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals('2020-04-13', $membership['join_date']);
$this->assertEquals(CRM_Utils_Time::date('Y-01-01'), $membership['start_date']);
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
- * @throws \Civi\API\Exception\UnauthorizedException
* @dataProvider getThousandSeparators
*/
public function testSubmitRecurCompleteInstantWithMail(string $thousandSeparator): void {
// Visibility is 'Public Pages and Listings' in order to try to get to a specific line
// of code to ensure it's tested - it might not be a 'real' use case.
$this->createCustomGroupWithFieldOfType(['extends' => 'Membership'], 'multi_country', NULL, ['visibility' => 'Public Pages and Listings']);
- $form = $this->getForm();
$this->mut = new CiviMailUtils($this, TRUE);
/** @var \CRM_Core_Payment_Dummy $processor */
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
'auto_renew' => TRUE,
]);
$this->createLoggedInUser();
- $form->preProcess();
-
- $form->_contactID = $this->_individualId;
- $form->_mode = 'live';
-
- $form->testSubmit(array_merge($this->getBaseSubmitParams(), [
+ $form = $this->getForm(array_merge($this->getBaseSubmitParams(), [
'is_recur' => 1,
'send_receipt' => 1,
'auto_renew' => 1,
$this->getCustomFieldName('multi_country') => [1006, 1007],
]));
+
+ $form->_contactID = $this->_individualId;
+ $form->_mode = 'live';
+
+ $form->testSubmit();
$contributionRecur = $this->callAPISuccessGetSingle('ContributionRecur', ['contact_id' => $this->_individualId]);
$this->assertEquals(1, $contributionRecur['is_email_receipt']);
$this->mut->checkMailLog([
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitPayLater(): void {
- $form = $this->getForm(NULL);
$this->createLoggedInUser();
$originalMembership = $this->callAPISuccessGetSingle('membership', []);
- $params = [
- 'cid' => $this->_individualId,
+ $form = $this->getForm([
+ 'contact_id' => $this->_individualId,
'join_date' => CRM_Utils_Time::date('m/d/Y'),
'start_date' => '',
'end_date' => '',
'record_contribution' => TRUE,
'trxn_id' => 777,
'contribution_status_id' => 2,
- ];
+ ], NULL);
$form->_contactID = $this->_individualId;
- $form->testSubmit($params);
+ $form->testSubmit();
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date']));
$contribution = $this->callAPISuccessGetSingle('Contribution', [
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitPayLaterWithBilling(): void {
- $form = $this->getForm(NULL);
$this->createLoggedInUser();
$originalMembership = $this->callAPISuccessGetSingle('membership', []);
- $params = [
- 'cid' => $this->_individualId,
+ $form = $this->getForm([
+ 'contact_id' => $this->_individualId,
'start_date' => '',
'end_date' => '',
// This format reflects the first value being the organisation & the second being the type.
'billing_state_province_id-5' => '1003',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
- ];
+ ], NULL);
$form->_contactID = $this->_individualId;
- $form->testSubmit($params);
+ $form->testSubmit();
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals(strtotime($membership['end_date']), strtotime($originalMembership['end_date']));
$this->assertEquals(10, $membership['max_related']);
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitComplete(): void {
- $form = $this->getForm(NULL);
$this->createLoggedInUser();
$originalMembership = $this->callAPISuccessGetSingle('membership', []);
- $params = [
- 'cid' => $this->_individualId,
+ $form = $this->getForm([
+ 'contact_id' => $this->_individualId,
'join_date' => CRM_Utils_Time::date('m/d/Y'),
'start_date' => '',
'end_date' => '',
'trxn_id' => 777,
'contribution_status_id' => 1,
'fee_amount' => .5,
- ];
+ ], NULL);
$form->_contactID = $this->_individualId;
- $form->testSubmit($params);
+ $form->testSubmit();
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->assertEquals(strtotime($membership['end_date']), strtotime('+ 2 years',
strtotime($originalMembership['end_date'])));
*
* We need to instantiate the form to run preprocess, which means we have to trick it about the request method.
*
+ * @param array $formValues
* @param string $mode
*
* @return \CRM_Member_Form_MembershipRenewal
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- protected function getForm($mode = 'test'): CRM_Member_Form_MembershipRenewal {
- $form = new CRM_Member_Form_MembershipRenewal();
- $_SERVER['REQUEST_METHOD'] = 'GET';
- $form->controller = new CRM_Core_Controller();
+ protected function getForm($formValues = [], $mode = 'test'): CRM_Member_Form_MembershipRenewal {
+ /* @var CRM_Member_Form_MembershipRenewal $form */
+ $form = $this->getFormObject('CRM_Member_Form_MembershipRenewal', $formValues);
+
$form->_bltID = 5;
$form->_mode = $mode;
$form->setEntityId($this->_membershipID);
protected function getBaseSubmitParams(): array {
return [
'cid' => $this->_individualId,
+ 'contact_id' => $this->_individualId,
// This format reflects the key being the organisation & the value being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'num_terms' => '1',
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '9',
- 'Y' => CRM_Utils_Time::date('Y') + 1,
+ 'Y' => (int) CRM_Utils_Time::date('Y') + 1,
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitRenewExpired(): void {
- $form = $this->getForm(NULL);
+ $form = $this->getForm([], NULL);
$this->createLoggedInUser();
$originalMembership = $this->callAPISuccessGetSingle('membership', []);
$this->callAPISuccess('Membership', 'create', [
*
* @dataProvider getThousandSeparators
*/
- public function testSubmit(string $thousandSeparator) {
+ public function testSubmit(string $thousandSeparator): void {
CRM_Core_Session::singleton()->getStatus(TRUE);
$this->setCurrencySeparators($thousandSeparator);
$form = $this->getForm();
$this->createLoggedInUser();
$params = [
'cid' => $this->_individualId,
+ 'contact_id' => $this->_individualId,
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
$params = $this->getBaseSubmitParams();
// Change financial_type_id to test our override flows through to the line item.
$params['financial_type_id'] = FinancialType::get(FALSE)->addWhere('id', '!=', $params['financial_type_id'])->addSelect('id')->execute()->first()['id'];
- $form = $this->getForm();
+ $form = $this->getForm($params);
$this->createLoggedInUser();
$form->_mode = 'test';
$form->_contactID = $this->_individualId;
*
* @throws \CRM_Core_Exception
*/
- public function testSubmitPayLaterWithBilling() {
+ public function testSubmitPayLaterWithBilling(): void {
$form = $this->getForm();
- $form->preProcess();
$this->createLoggedInUser();
$params = [
- 'cid' => $this->_individualId,
+ 'contact_id' => $this->_individualId,
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
'trxn_id' => 777,
'contribution_status_id' => 2,
'billing_first_name' => 'Test',
- 'billing_middlename' => 'Last',
+ 'billing_middle_name' => 'Last',
'billing_street_address-5' => '10 Test St',
'billing_city-5' => 'Test',
'billing_state_province_id-5' => '1003',
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
*/
- public function testSubmitRecurCompleteInstant() {
- $form = $this->getForm();
+ public function testSubmitRecurCompleteInstant(): void {
$mut = new CiviMailUtils($this, TRUE);
+ /* @var \CRM_Core_Payment_Dummy $processor */
$processor = Civi\Payment\System::singleton()->getById($this->_paymentProcessorID);
$processor->setDoDirectPaymentResult([
'payment_status_id' => 1,
'duration_interval' => 1,
'auto_renew' => TRUE,
]);
- $form->preProcess();
+ $form = $this->getForm($this->getBaseSubmitParams());
$this->createLoggedInUser();
- $params = $this->getBaseSubmitParams();
$form->_mode = 'test';
$form->_contactID = $this->_individualId;
- $form->testSubmit($params);
+ $form->testSubmit();
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
$this->callAPISuccessGetCount('ContributionRecur', ['contact_id' => $this->_individualId], 1);
'===========================================================
Billing Name and Address
===========================================================
-Test
+Test Last
10 Test St
Test, AR 90210
US',
* We need to instantiate the form to run preprocess, which means we have to
* trick it about the request method.
*
+ * @param array $formValues
+ *
* @return \CRM_Member_Form_Membership
* @throws \CRM_Core_Exception
- * @throws \CiviCRM_API3_Exception
*/
- protected function getForm() {
+ protected function getForm($formValues = []) {
if (isset($_REQUEST['cid'])) {
unset($_REQUEST['cid']);
}
- $form = $this->getFormObject('CRM_Member_Form_Membership');
+ $form = $this->getFormObject('CRM_Member_Form_Membership', $formValues);
$form->preProcess();
return $form;
}
/**
* @return array
*/
- protected function getBaseSubmitParams() {
- $params = [
+ protected function getBaseSubmitParams(): array {
+ return [
+ 'contact_id' => $this->_individualId,
'cid' => $this->_individualId,
'price_set_id' => 0,
'join_date' => date('Y-m-d'),
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
- 'billing_middlename' => 'Last',
+ 'billing_middle_name' => 'Last',
'billing_street_address-5' => '10 Test St',
'billing_city-5' => 'Test',
'billing_state_province_id-5' => '1003',
'billing_country_id-5' => '1228',
'send_receipt' => 1,
];
- return $params;
}
/**