*/
class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
+ use CRMTraits_Financial_OrderTrait;
+
protected $_individualId;
protected $_contribution;
protected $_financialTypeId = 1;
*
* @param string $thousandSeparator
*
- * @dataProvider getThousandSeparators
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
+ *
+ * @dataProvider getThousandSeparators
*/
- public function testSubmit($thousandSeparator) {
+ public function testSubmit(string $thousandSeparator) {
CRM_Core_Session::singleton()->getStatus(TRUE);
$this->setCurrencySeparators($thousandSeparator);
$form = $this->getForm();
'cvv2' => '123',
'credit_card_exp_date' => [
'M' => '9',
- // TODO: Future proof
- 'Y' => '2024',
+ 'Y' => date('Y', strtotime('+ 2 years')),
],
'credit_card_type' => 'Visa',
'billing_first_name' => 'Test',
}
- /**
- * Test membership form with Failed Contribution.
- *
- * @throws \CRM_Core_Exception
- */
- public function testFormWithFailedContribution() {
- $form = $this->getForm();
- $form->preProcess();
- $this->createLoggedInUser();
- $params = $this->getBaseSubmitParams();
- unset($params['price_set_id']);
- unset($params['credit_card_number']);
- unset($params['cvv2']);
- unset($params['credit_card_exp_date']);
- unset($params['credit_card_type']);
- unset($params['send_receipt']);
- unset($params['is_recur']);
-
- $params['record_contribution'] = TRUE;
- $params['contribution_status_id'] = array_search('Failed', CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'));
- $form->_mode = NULL;
- $form->_contactID = $this->_individualId;
-
- $form->testSubmit($params);
- $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
- $form->testSubmit($params);
- $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
- $this->assertEquals($membership['status_id'], array_search('Pending', CRM_Member_PseudoConstant::membershipStatus(), TRUE));
- }
-
/**
* CRM-20955, CRM-20966:
* Test creating two memberships with inheritance via price set in the back end,
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
- public function testContributionFormStatusUpdate() {
+ public function testContributionFormStatusUpdate(): void {
- $this->_individualId = $this->createLoggedInUser();
- $membershipId = $this->contactMembershipCreate([
- 'contact_id' => $this->_individualId,
- 'membership_type_id' => $this->membershipTypeAnnualFixedID,
- 'status_id' => 'New',
- ]);
+ $this->_contactID = $this->createLoggedInUser();
+ $this->createContributionAndMembershipOrder();
$params = [
'total_amount' => 50,
'financial_type_id' => 2,
- 'contact_id' => $this->_individualId,
+ 'contact_id' => $this->_contactID,
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'),
'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'),
];
- $contriParams = [
- 'membership_id' => $membershipId,
- 'total_amount' => 50,
- 'financial_type_id' => 2,
- 'contact_id' => $this->_individualId,
- ];
- $contribution = CRM_Member_BAO_Membership::recordMembershipContribution($contriParams);
-
//Update Contribution to Cancelled.
$form = new CRM_Contribute_Form_Contribution();
- $form->_id = $params['id'] = $contribution->id;
+ $form->_id = $params['id'] = $this->ids['Contribution'][0];
$form->_mode = NULL;
$form->_contactID = $this->_individualId;
$form->testSubmit($params, CRM_Core_Action::UPDATE);
- $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);
+ $membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_contactID]);
//Assert membership status overrides when the contribution cancelled.
- $this->assertEquals($membership['is_override'], TRUE);
+ $this->assertEquals(TRUE, $membership['is_override']);
$this->assertEquals($membership['status_id'], $this->callAPISuccessGetValue('MembershipStatus', [
'return' => 'id',
'name' => 'Cancelled',
*/
public function testCreatePendingWithMultipleTerms() {
CRM_Core_Session::singleton()->getStatus(TRUE);
- $form = $this->getForm();
- $form->preProcess();
$this->mut = new CiviMailUtils($this, TRUE);
$this->createLoggedInUser();
$membershipTypeAnnualRolling = $this->callAPISuccess('membership_type', 'create', [
'from_email_address' => '"Demonstrators Anonymous" <info@example.org>',
'receipt_text' => '',
];
+ $form = $this->getForm();
+ $form->preProcess();
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
$membership = $this->callAPISuccessGetSingle('Membership', ['contact_id' => $this->_individualId]);