Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some more variable variables + some test cleanup #19208

Merged
merged 2 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -1379,17 +1379,12 @@ public function submit() {
// unset send-receipt option, since receipt will be sent when ipn is received.
unset($formValues['send_receipt'], $formValues['send_receipt']);
//as membership is pending set dates to null.
$memberDates = [
'join_date' => 'joinDate',
'start_date' => 'startDate',
'end_date' => 'endDate',
];
foreach ($memberDates as $dv) {
$$dv = NULL;
foreach ($this->_memTypeSelected as $memType) {
$membershipTypeValues[$memType][$dv] = NULL;
}
foreach ($this->_memTypeSelected as $memType) {
$membershipTypeValues[$memType]['joinDate'] = NULL;
$membershipTypeValues[$memType]['startDate'] = NULL;
$membershipTypeValues[$memType]['endDate'] = NULL;
}
$endDate = $startDate = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no $joinDate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because the ide suggested it wasn't used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

}
$now = date('YmdHis');
$params['receive_date'] = date('Y-m-d H:i:s');
Expand Down
8 changes: 5 additions & 3 deletions Civi/Test/ContactTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public function createLoggedInUser() {
*
* @return int
* id of Organisation created
*
* @throws \CiviCRM_API3_Exception
*/
public function organizationCreate($params = [], $seq = 0) {
public function organizationCreate($params = [], $seq = 0): int {
if (!$params) {
$params = [];
}
Expand All @@ -76,7 +78,7 @@ public function organizationCreate($params = [], $seq = 0) {
*
* @throws \CiviCRM_API3_Exception
*/
public function individualCreate($params = [], $seq = 0, $random = FALSE) {
public function individualCreate($params = [], $seq = 0, $random = FALSE): int {
$params = array_merge($this->sampleContact('Individual', $seq, $random), $params);
return $this->_contactCreate($params);
}
Expand Down Expand Up @@ -160,7 +162,7 @@ public function sampleContact($contact_type, $seq = 0, $random = FALSE) {
*
* @throws \CiviCRM_API3_Exception
*/
private function _contactCreate($params) {
private function _contactCreate($params): int {
$result = civicrm_api3('contact', 'create', $params);
return (int) $result['id'];
}
Expand Down
96 changes: 35 additions & 61 deletions tests/phpunit/CRM/Member/Form/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@
class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {

use CRMTraits_Financial_OrderTrait;
use CRMTraits_Financial_PriceSetTrait;

/**
* @var int
*/
protected $_individualId;
protected $_contribution;
protected $_financialTypeId = 1;
Expand Down Expand Up @@ -75,6 +79,7 @@ class CRM_Member_Form_MembershipTest extends CiviUnitTestCase {
* and redirect stdin to a temporary file.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function setUp() {
$this->_apiversion = 3;
Expand All @@ -93,7 +98,7 @@ public function setUp() {
'contact_type_a' => 'Individual',
'contact_type_b' => 'Organization',
])['id'];
$membershipTypeAnnualFixed = $this->callAPISuccess('MembershipType', 'create', [
$this->ids['membership_type']['AnnualFixed'] = $this->callAPISuccess('MembershipType', 'create', [
'domain_id' => 1,
'name' => 'AnnualFixed',
'member_of_contact_id' => $this->ids['contact']['organization'],
Expand All @@ -106,8 +111,7 @@ public function setUp() {
'relationship_type_id' => [$this->ids['relationship_type']['member']],
'relationship_direction' => ['b_a'],
'financial_type_id' => 2,
]);
$this->membershipTypeAnnualFixedID = $membershipTypeAnnualFixed['id'];
])['id'];

$this->ids['membership_type']['AnnualRolling'] = $this->callAPISuccess('MembershipType', 'create', [
'name' => 'AnnualRolling',
Expand Down Expand Up @@ -288,7 +292,7 @@ public function testFormRuleRollingLifetimeEnd() {
public function testFormRulePermanentOverrideWithNoStatus() {
$params = [
'join_date' => date('Y-m-d'),
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'is_override' => TRUE,
];
$files = [];
Expand All @@ -301,7 +305,7 @@ public function testFormRulePermanentOverrideWithNoStatus() {
public function testFormRuleUntilDateOverrideWithValidOverrideEndDate() {
$params = [
'join_date' => date('Y-m-d'),
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'is_override' => TRUE,
'status_id' => 1,
'status_override_end_date' => date('Y-m-d'),
Expand All @@ -315,7 +319,7 @@ public function testFormRuleUntilDateOverrideWithValidOverrideEndDate() {
public function testFormRuleUntilDateOverrideWithNoOverrideEndDate() {
$params = [
'join_date' => date('Y-m-d'),
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'is_override' => CRM_Member_StatusOverrideTypes::UNTIL_DATE,
'status_id' => 1,
];
Expand Down Expand Up @@ -461,7 +465,7 @@ public function testFormRuleFixedJoin6MonthsAgo() {
'join_date' => date('Y-m-d', $unix6MAgo),
'start_date' => '',
'end_date' => '',
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
];
$files = [];
$obj = new CRM_Member_Form_Membership();
Expand Down Expand Up @@ -495,7 +499,7 @@ public function testSubmit(string $thousandSeparator) {
'start_date' => '',
'end_date' => '',
// This format reflects the organisation & then the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '1',
Expand Down Expand Up @@ -596,8 +600,8 @@ public function testContributionUpdateOnMembershipTypeChange(): void {
'join_date' => date('Y-m-d'),
'start_date' => '',
'end_date' => '',
// This format reflects the first being the organisation & the $this->membershipTypeAnnualFixedID being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
// This format reflects the first being the organisation & the $this->ids['membership_type']['AnnualFixed'] being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'record_contribution' => 1,
'total_amount' => 50,
'receive_date' => date('Y-m-d', time()) . ' 20:36:00',
Expand Down Expand Up @@ -697,7 +701,7 @@ public function testSubmitPartialPayment(string $thousandSeparator): void {
'start_date' => '',
'end_date' => '',
// This format reflects the first number being the organisation & the second being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'receive_date' => date('Y-m-d', time()) . ' 20:36:00',
'record_contribution' => 1,
'total_amount' => $this->formatMoneyInput(50),
Expand Down Expand Up @@ -752,7 +756,7 @@ public function testSubmitPartialPayment(string $thousandSeparator): void {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testSubmitRecur() {
public function testSubmitRecur(): void {
CRM_Core_Session::singleton()->getStatus(TRUE);
$pendingVal = $this->callAPISuccessGetValue('OptionValue', [
'return' => 'id',
Expand All @@ -768,7 +772,7 @@ public function testSubmitRecur() {
$form = $this->getForm();

$this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'id' => $this->ids['membership_type']['AnnualFixed'],
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
Expand Down Expand Up @@ -809,13 +813,19 @@ public function testSubmitRecur() {
], CRM_Core_Session::singleton()->getStatus());
}

public function testSubmitRecurTwoRows() {
$this->createMembershipPriceSet();
$form = $this->getForm();
}

/**
* CRM-20946: Test the financial entires especially the reversed amount,
* after related Contribution is cancelled
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testFinancialEntiriesOnCancelledContribution() {
public function testFinancialEntriesOnCancelledContribution(): void {
// Create two memberships for individual $this->_individualId, via a price set in the back end.
$this->createTwoMembershipsViaPriceSetInBackEnd($this->_individualId);

Expand Down Expand Up @@ -845,8 +855,8 @@ public function testFinancialEntiriesOnCancelledContribution() {
]);
// compare the reversed amounts of respective memberships after cancelling contribution
$cancelledMembershipAmounts = [
-259.00,
-20.00,
-10.00,
];
$count = 0;
foreach ($result['values'] as $record) {
Expand All @@ -870,7 +880,7 @@ public function testSubmitPayLaterWithBilling() {
'start_date' => '',
'end_date' => '',
// This format reflects the first number being the organisation & the second being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'auto_renew' => '0',
'max_related' => '',
'num_terms' => '2',
Expand Down Expand Up @@ -976,7 +986,7 @@ public function testSubmitRecurCompleteInstant() {
]);
$processorDetail = $processor->getPaymentProcessor();
$this->callAPISuccess('MembershipType', 'create', [
'id' => $this->membershipTypeAnnualFixedID,
'id' => $this->ids['membership_type']['AnnualFixed'],
'duration_unit' => 'month',
'duration_interval' => 1,
'auto_renew' => TRUE,
Expand Down Expand Up @@ -1038,7 +1048,7 @@ public function testSubmitRecurCompleteInstant() {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testTwoInheritedMembershipsViaPriceSetInBackend() {
public function testTwoInheritedMembershipsViaPriceSetInBackend(): void {
// Create an organization and give it a "Member of" relationship to $this->_individualId.
$orgID = $this->organizationCreate();
$relationship = $this->callAPISuccess('Relationship', 'create', [
Expand Down Expand Up @@ -1118,7 +1128,7 @@ public function testTwoInheritedMembershipsViaPriceSetInBackend() {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function testTwoMembershipsViaPriceSetInBackendWithDiscount() {
public function testTwoMembershipsViaPriceSetInBackendWithDiscount(): void {
// Register buildAmount hook to apply discount.
$this->hookClass->setHook('civicrm_buildAmount', [$this, 'buildAmountMembershipDiscount']);

Expand Down Expand Up @@ -1194,7 +1204,7 @@ protected function getBaseSubmitParams() {
'end_date' => '',
'campaign_id' => '',
// This format reflects the first number being the organisation & the second being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'auto_renew' => '1',
'is_recur' => 1,
'max_related' => 0,
Expand Down Expand Up @@ -1236,47 +1246,11 @@ protected function getBaseSubmitParams() {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected function createTwoMembershipsViaPriceSetInBackEnd($contactId) {
protected function createTwoMembershipsViaPriceSetInBackEnd($contactId): void {
$form = $this->getForm();
$form->preProcess();
$this->createLoggedInUser();

// create a price-set of price-field of type checkbox and each price-option corresponds to a membership type
$priceSet = $this->callAPISuccess('price_set', 'create', [
'is_quick_config' => 0,
'extends' => 'CiviMember',
'financial_type_id' => 1,
'title' => 'my Page',
]);
$priceSetID = $priceSet['id'];
// create respective checkbox price-field
$priceField = $this->callAPISuccess('price_field', 'create', [
'price_set_id' => $priceSetID,
'label' => 'Memberships',
'html_type' => 'Checkbox',
]);
$priceFieldID = $priceField['id'];
// create two price options, each represent a membership type of amount 20 and 10 respectively
$priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Long Haired Goat',
'amount' => 20,
'financial_type_id' => 'Donation',
'membership_type_id' => $this->ids['membership_type']['AnnualRolling'],
'membership_num_terms' => 1,
]);
$pfvIDs = [$priceFieldValue['id'] => 1];
$priceFieldValue = $this->callAPISuccess('price_field_value', 'create', [
'price_set_id' => $priceSetID,
'price_field_id' => $priceField['id'],
'label' => 'Shoe-eating Goat',
'amount' => 10,
'financial_type_id' => 'Donation',
'membership_type_id' => $this->ids['membership_type']['AnnualRollingOrg2'],
'membership_num_terms' => 2,
]);
$pfvIDs[$priceFieldValue['id']] = 1;
$pfvIDs = $this->createMembershipPriceSet();

// register for both of these memberships via backoffice membership form submission
$params = [
Expand All @@ -1285,8 +1259,8 @@ protected function createTwoMembershipsViaPriceSetInBackEnd($contactId) {
'start_date' => '',
'end_date' => '',
// This format reflects the 23 being the organisation & the 25 being the type.
"price_$priceFieldID" => $pfvIDs,
'price_set_id' => $priceSetID,
"price_" . $this->getPriceFieldID() => $pfvIDs,
'price_set_id' => $this->getPriceSetID(),
'membership_type_id' => [1 => 0],
'auto_renew' => '0',
'max_related' => '',
Expand Down Expand Up @@ -1381,7 +1355,7 @@ public function testLineItemAmountOnSalesTax() {
'start_date' => '',
'end_date' => '',
// This format reflects the first number being the organisation & the second being the type.
'membership_type_id' => [$this->ids['contact']['organization'], $this->membershipTypeAnnualFixedID],
'membership_type_id' => [$this->ids['contact']['organization'], $this->ids['membership_type']['AnnualFixed']],
'record_contribution' => 1,
'total_amount' => 55,
'receive_date' => date('Y-m-d') . ' 20:36:00',
Expand Down
Loading