Skip to content

Commit

Permalink
Reduce calls to CRM_Member_PseudoConstant::membershipType
Browse files Browse the repository at this point in the history
This function defaults to not using the cached version so that's a pretty good argument for making a more
active effort to deprecate it. The createMembership function flushes it so we don't need to do that
so much in tests now either. I also included swapping status over in the test
  • Loading branch information
eileenmcnaughton committed Jul 29, 2020
1 parent aa328fc commit a89e0a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 21 deletions.
12 changes: 5 additions & 7 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -1783,16 +1783,14 @@ public static function addActivity(
* particular component object.
*
* @return string
* @throws \CRM_Core_Exception
*/
public static function getActivitySubject($entityObj) {
// @todo determine the subject on the appropriate entity rather than from the activity.
switch ($entityObj->__table) {
case 'civicrm_membership':
$membershipType = CRM_Member_PseudoConstant::membershipType($entityObj->membership_type_id);
$subject = $membershipType ? $membershipType : ts('Membership');

if (is_array($subject)) {
$subject = implode(", ", $subject);
}
$membershipType = CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'membership_type_id', $entityObj->membership_type_id);
$subject = $membershipType ?: ts('Membership');

if (!CRM_Utils_System::isNull($entityObj->source)) {
$subject .= " - {$entityObj->source}";
Expand All @@ -1803,7 +1801,7 @@ public static function getActivitySubject($entityObj) {
$subject .= sprintf(' (by %s)', $displayName);
}

$subject .= " - Status: " . CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $entityObj->status_id, 'label');
$subject .= ' - Status: ' . CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'status_id', $entityObj->status_id);
return $subject;

case 'civicrm_participant':
Expand Down
4 changes: 2 additions & 2 deletions CRM/Member/BAO/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ private static function addToRecentItems($membership) {
// ie in an update situation.
$membership->find(TRUE);
}
$membershipTypes = CRM_Member_PseudoConstant::membershipType();
$title = CRM_Contact_BAO_Contact::displayName($membership->contact_id) . ' - ' . ts('Membership Type:') . ' ' . $membershipTypes[$membership->membership_type_id];
$title = CRM_Contact_BAO_Contact::displayName($membership->contact_id) . ' - ' . ts('Membership Type:')
. ' ' . CRM_Core_PseudoConstant::getLabel('CRM_Member_BAO_Membership', 'membership_type_id', $membership->membership_type_id);

$recentOther = [];
if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/CRM/Core/Payment/BaseIPNTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ public function setUp() {
*/
public function tearDown() {
$this->quickCleanUpFinancialEntities();
CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
}

Expand Down
22 changes: 11 additions & 11 deletions tests/phpunit/api/v3/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public function setUp() {
]);
$this->_membershipStatusID = $this->membershipStatusCreate('test status');

CRM_Member_PseudoConstant::membershipType(NULL, TRUE);
CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'name', TRUE);
CRM_Core_PseudoConstant::activityType(TRUE, TRUE, TRUE, 'name');

Expand Down Expand Up @@ -114,7 +113,7 @@ public function testMembershipDeletePreserveContribution() {
'total_amount' => 100,
'contact_id' => $this->_params['contact_id'],
]);
$membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', [
$this->callAPISuccess('MembershipPayment', 'create', [
'sequential' => 1,
'contribution_id' => $ContributionCreate['values'][0]['id'],
'membership_id' => $membershipID,
Expand All @@ -139,37 +138,38 @@ public function testMembershipDeletePreserveContribution() {
public function testActivityForCancelledContribution() {
$contactId = $this->createLoggedInUser();
$membershipID = $this->contactMembershipCreate($this->_params);
$this->assertDBRowExist('CRM_Member_DAO_Membership', $membershipID);

$ContributionCreate = $this->callAPISuccess('Contribution', 'create', [
'financial_type_id' => "Member Dues",
'financial_type_id' => 'Member Dues',
'total_amount' => 100,
'contact_id' => $this->_params['contact_id'],
]);
$membershipPaymentCreate = $this->callAPISuccess('MembershipPayment', 'create', [
$this->callAPISuccess('MembershipPayment', 'create', [
'sequential' => 1,
'contribution_id' => $ContributionCreate['id'],
'membership_id' => $membershipID,
]);
$instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->paymentInstruments = $instruments['values'];

$form = new CRM_Contribute_Form_Contribution();
$form->_id = $ContributionCreate['id'];
$form->testSubmit([
'total_amount' => 100,
'financial_type_id' => 1,
'contact_id' => $contactId,
'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
'payment_instrument_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'payment_instrument_id', 'Check'),
'contribution_status_id' => 3,
],
CRM_Core_Action::UPDATE);

$activity = $this->callAPISuccess('Activity', 'get', [
'activity_type_id' => "Change Membership Status",
$this->callAPISuccessGetSingle('Activity', [
'activity_type_id' => 'Membership Signup',
'source_record_id' => $membershipID,
'subject' => 'General - Payment - Status: test status',
]);
$this->callAPISuccessGetSingle('Activity', [
'activity_type_id' => 'Change Membership Status',
'source_record_id' => $membershipID,
]);
$this->assertNotEmpty($activity['values']);
}

/**
Expand Down

0 comments on commit a89e0a3

Please sign in to comment.