[NFC] Minor cleanup in test class
authoreileen <emcnaughton@wikimedia.org>
Thu, 9 Jan 2020 04:54:31 +0000 (17:54 +1300)
committereileen <emcnaughton@wikimedia.org>
Thu, 9 Jan 2020 04:54:31 +0000 (17:54 +1300)
tests/phpunit/CRM/Member/Form/MembershipTest.php
tests/phpunit/CiviTest/CiviUnitTestCase.php

index a34c3cfa5802a8a0bb78872a7fadf198f6e6b69c..0435fe90290378591d5a316a67bb0c5554921a6d 100644 (file)
@@ -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',
     ]));
   }
 
index 27808ed1096682da5fbd675efb2a076afd4b3feb..8d416d4a0232ef7f918df2fd6ae007cf5b3fe386 100644 (file)
@@ -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']]);
       }
     }