Skip to content
Snippets Groups Projects
Unverified Commit 36c2072c authored by Eileen McNaughton's avatar Eileen McNaughton Committed by GitHub
Browse files

Merge pull request #19404 from eileenmcnaughton/mem_deb

[Test] Extend new membership form to cover multi-line renew + minor cleanup
parents 93457205 e659743e
Branches
Tags
No related merge requests found
......@@ -466,7 +466,7 @@ class CRM_Member_Form extends CRM_Contribute_Form_AbstractEditPayment {
*
* @param array $formValues
*/
public function testSubmit($formValues) {
public function testSubmit(array $formValues): void {
$this->setContextVariables($formValues);
$this->_memType = $formValues['membership_type_id'][1];
$this->_params = $formValues;
......
......@@ -1935,13 +1935,10 @@ DESC limit 1");
* @param array $params
* @param int $contactID
*
* @return int|null
* @return int
*/
protected function legacyProcessRecurringContribution(&$params, $contactID) {
protected function legacyProcessRecurringContribution(array $params, $contactID): int {
$form = $this;
if (empty($params['is_recur'])) {
return NULL;
}
$recurParams = ['contact_id' => $contactID];
$recurParams['amount'] = $params['amount'] ?? NULL;
......@@ -1974,12 +1971,7 @@ DESC limit 1");
$campaignId = $params['campaign_id'] ?? $form->_values['campaign_id'] ?? NULL;
$recurParams['campaign_id'] = $campaignId;
$recurring = CRM_Contribute_BAO_ContributionRecur::add($recurParams);
if (is_a($recurring, 'CRM_Core_Error')) {
throw new CRM_Core_Exception(CRM_Core_Error::getMessages($recurring));
}
return $recurring->id;
return CRM_Contribute_BAO_ContributionRecur::add($recurParams)->id;
}
}
......@@ -769,17 +769,15 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
'label' => 'PendingEdited',
]);
$form = $this->getForm();
$this->callAPISuccess('MembershipType', 'create', [
'id' => $this->ids['membership_type']['AnnualFixed'],
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
]);
$form->preProcess();
$this->createLoggedInUser();
$params = $this->getBaseSubmitParams();
$form = $this->getForm();
$this->createLoggedInUser();
$form->_mode = 'test';
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
......@@ -813,9 +811,33 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
], CRM_Core_Session::singleton()->getStatus());
}
public function testSubmitRecurTwoRows() {
$this->createMembershipPriceSet();
/**
* Test submit recurring with two line items.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitRecurTwoRows(): void {
$pfvIDs = $this->createMembershipPriceSet();
$form = $this->getForm();
$form->_mode = 'live';
$priceParams = [
'price_' . $this->getPriceFieldID() => $pfvIDs,
'price_set_id' => $this->getPriceSetID(),
'frequency_interval' => 1,
'frequency_unit' => 'month',
'membership_type_id' => NULL,
];
$form->testSubmit(array_merge($this->getBaseSubmitParams(), $priceParams));
$memberships = $this->callAPISuccess('Membership', 'get')['values'];
$this->assertCount(2, $memberships);
$this->callAPISuccessGetSingle('Contribution', []);
$this->callAPISuccessGetCount('MembershipPayment', [], 2);
$lines = $this->callAPISuccess('LineItem', 'get', ['sequential' => 1])['values'];
$this->assertCount(2, $lines);
$this->assertEquals('civicrm_membership', $lines[0]['entity_table']);
$this->assertEquals('civicrm_membership', $lines[1]['entity_table']);
}
/**
......@@ -1177,10 +1199,12 @@ Expires: ',
/**
* Get a membership form object.
*
* We need to instantiate the form to run preprocess, which means we have to trick it about the request method.
* We need to instantiate the form to run preprocess, which means we have to
* trick it about the request method.
*
* @return \CRM_Member_Form_Membership
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected function getForm() {
if (isset($_REQUEST['cid'])) {
......@@ -1189,6 +1213,7 @@ Expires: ',
$form = new CRM_Member_Form_Membership();
$_SERVER['REQUEST_METHOD'] = 'GET';
$form->controller = new CRM_Core_Controller();
$form->preProcess();
return $form;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment