From: eileen Date: Thu, 9 Jan 2020 04:54:31 +0000 (+1300) Subject: [NFC] Minor cleanup in test class X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c6ede1be0d3774ad474bc3c2976a932ff3941440;p=civicrm-core.git [NFC] Minor cleanup in test class --- diff --git a/tests/phpunit/CRM/Member/Form/MembershipTest.php b/tests/phpunit/CRM/Member/Form/MembershipTest.php index a34c3cfa58..0435fe9029 100644 --- a/tests/phpunit/CRM/Member/Form/MembershipTest.php +++ b/tests/phpunit/CRM/Member/Form/MembershipTest.php @@ -1304,28 +1304,21 @@ Expires: ', * @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, @@ -1336,6 +1329,7 @@ Expires: ', $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; @@ -1345,8 +1339,8 @@ Expires: ', //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', ])); } diff --git a/tests/phpunit/CiviTest/CiviUnitTestCase.php b/tests/phpunit/CiviTest/CiviUnitTestCase.php index 27808ed109..8d416d4a02 100644 --- a/tests/phpunit/CiviTest/CiviUnitTestCase.php +++ b/tests/phpunit/CiviTest/CiviUnitTestCase.php @@ -575,9 +575,12 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { } /** + * Create membership. + * * @param array $params * - * @return mixed + * @return int + * @throws \CRM_Core_Exception */ public function contactMembershipCreate($params) { $params = array_merge([ @@ -589,7 +592,7 @@ class CiviUnitTestCase extends PHPUnit\Framework\TestCase { ], $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']]); } }