* @throws \CiviCRM_API3_Exception
*/
public function testContributionFormStatusUpdate() {
- $form = new CRM_Contribute_Form_Contribution();
- //Create a membership with status = 'New'.
$this->_individualId = $this->createLoggedInUser();
- $memParams = [
+ $membershipId = $this->contactMembershipCreate([
'contact_id' => $this->_individualId,
'membership_type_id' => $this->membershipTypeAnnualFixedID,
- 'status_id' => array_search('New', CRM_Member_PseudoConstant::membershipStatus()),
- ];
- $cancelledStatusId = $this->callAPISuccessGetValue('OptionValue', [
- 'return' => 'value',
- 'option_group_id' => 'contribution_status',
- 'name' => 'Cancelled',
+ 'status_id' => 'New',
]);
+
$params = [
'total_amount' => 50,
'financial_type_id' => 2,
'contact_id' => $this->_individualId,
- 'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
- 'contribution_status_id' => $cancelledStatusId,
+ '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'),
];
- $membershipId = $this->contactMembershipCreate($memParams);
$contriParams = [
'membership_id' => $membershipId,
$contribution = CRM_Member_BAO_Membership::recordMembershipContribution($contriParams);
//Update Contribution to Cancelled.
+ $form = new CRM_Contribute_Form_Contribution();
$form->_id = $params['id'] = $contribution->id;
$form->_mode = NULL;
$form->_contactID = $this->_individualId;
//Assert membership status overrides when the contribution cancelled.
$this->assertEquals($membership['is_override'], TRUE);
$this->assertEquals($membership['status_id'], $this->callAPISuccessGetValue('MembershipStatus', [
- 'return' => "id",
- 'name' => "Cancelled",
+ 'return' => 'id',
+ 'name' => 'Cancelled',
]));
}
}
/**
+ * Create membership.
+ *
* @param array $params
*
- * @return mixed
+ * @return int
+ * @throws \CRM_Core_Exception
*/
public function contactMembershipCreate($params) {
$params = array_merge([
], $params);
if (!is_numeric($params['membership_type_id'])) {
$membershipTypes = $this->callAPISuccess('Membership', 'getoptions', ['action' => 'create', 'field' => 'membership_type_id']);
- if (!in_array($params['membership_type_id'], $membershipTypes['values'])) {
+ if (!in_array($params['membership_type_id'], $membershipTypes['values'], TRUE)) {
$this->membershipTypeCreate(['name' => $params['membership_type_id']]);
}
}