Merge pull request #15669 from eileenmcnaughton/yesno
authorYashodha Chaku <yashodha@cividesk.com>
Thu, 31 Oct 2019 08:29:55 +0000 (13:59 +0530)
committerGitHub <noreply@github.com>
Thu, 31 Oct 2019 08:29:55 +0000 (13:59 +0530)
Use Yes-No radio instead of checkbox on search form.

CRM/Case/BAO/Query.php
CRM/Contact/BAO/Query.php
CRM/Contact/Form/Search.php
CRM/Price/BAO/LineItem.php
tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php
tests/phpunit/CRM/Event/BAO/ChangeFeeSelectionTest.php
tests/phpunit/CRM/Event/Form/ParticipantTest.php

index 55e32bd99e4c7eff3161595ff67e17e1071a1d01..f14466306732670caeb4d7c45fce5ac20173c002 100644 (file)
@@ -291,7 +291,7 @@ class CRM_Case_BAO_Query extends CRM_Core_BAO_Query {
         }
 
         $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.{$name}", $op, $value, "Integer");
-        $query->_qill[$grouping][] = self::getQillValue('CRM_Case_DAO_Case', $name, $value, $op, $label);
+        $query->_qill[$grouping][] = CRM_Contact_BAO_Query::getQillValue('CRM_Case_DAO_Case', $name, $value, $op, $label);
         $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
         return;
 
@@ -332,7 +332,7 @@ class CRM_Case_BAO_Query extends CRM_Core_BAO_Query {
 
       case 'case_subject':
         $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_case.subject", $op, $value, 'String');
-        $query->_qill[$grouping][] = self::getQillValue('CRM_Case_DAO_Case', $name, $value, $op, 'Case Subject');
+        $query->_qill[$grouping][] = CRM_Contact_BAO_Query::getQillValue('CRM_Case_DAO_Case', $name, $value, $op, 'Case Subject');
         $query->_tables['civicrm_case'] = $query->_whereTables['civicrm_case'] = 1;
         $query->_tables['civicrm_case_contact'] = $query->_whereTables['civicrm_case_contact'] = 1;
         return;
@@ -588,25 +588,6 @@ case_relation_type.id = case_relationship.relationship_type_id )";
     return $from;
   }
 
-  /**
-   * Get the qill (search description for field) for the specified field.
-   *
-   * @todo this is private because it is the first step towards generalising rather than
-   * the final product IMHO.
-   *
-   * @param string $daoName
-   * @param string $name
-   * @param string $value
-   * @param string|array $op
-   * @param string $label
-   *
-   * @return string
-   */
-  private static function getQillValue($daoName, string $name, $value, $op, string $label) {
-    list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue($daoName, $name, $value, $op);
-    return ts('%1 %2 %3', [1 => $label, 2 => $op, 3 => $value]);
-  }
-
   /**
    * Getter for the qill object.
    *
index bb5665b259d0cb125d4d09262514387c47d6fb0f..d67f250dc038f58c391975b22803d74edab61185 100644 (file)
@@ -6247,6 +6247,22 @@ AND   displayRelType.is_active = 1
     return [CRM_Utils_Array::value($op, $qillOperators, $op), $fieldValue];
   }
 
+  /**
+   * Get the qill (search description for field) for the specified field.
+   *
+   * @param string $daoName
+   * @param string $name
+   * @param string $value
+   * @param string|array $op
+   * @param string $label
+   *
+   * @return string
+   */
+  public static function getQillValue($daoName, string $name, $value, $op, string $label) {
+    list($op, $value) = self::buildQillForFieldValue($daoName, $name, $value, $op);
+    return ts('%1 %2 %3', [1 => $label, 2 => $op, 3 => $value]);
+  }
+
   /**
    * Alter value to reflect wildcard settings.
    *
@@ -6651,7 +6667,7 @@ AND   displayRelType.is_active = 1
         FROM (
       SELECT civicrm_contribution.total_amount, civicrm_contribution.currency
       $from
-      $where  AND civicrm_contribution.cancel_date IS NOT NULL 
+      $where  AND civicrm_contribution.cancel_date IS NOT NULL
       GROUP BY civicrm_contribution.id
     ) as conts
     GROUP BY currency";
index 4db0e2ea0efa2cdde870e7dafb77319263103b3e..a225db12254f19d231da25f4858ffce7a8248ee2 100644 (file)
@@ -302,7 +302,8 @@ class CRM_Contact_Form_Search extends CRM_Core_Form_Search {
     }
 
     self::setModeValues();
-    if (!array_key_exists($mode, self::$_modeValues)) {
+    // Note $mode might === FALSE because array_search above failed, e.g. for searchPane='location'
+    if (empty(self::$_modeValues[$mode])) {
       $mode = CRM_Contact_BAO_Query::MODE_CONTACTS;
     }
 
index cd9145d6ccf35461bc2d26cd254791734a94c4f8..042e2dbc2fb6d35a272ab61f4630e7a19570cf75 100644 (file)
@@ -669,6 +669,7 @@ WHERE li.contribution_id = %1";
    * @param $feeBlock
    * @param array $lineItems
    *
+   * @throws \CiviCRM_API3_Exception
    */
   public static function changeFeeSelections(
     $params,
@@ -1046,7 +1047,6 @@ WHERE li.contribution_id = %1";
         'entity_id' => $entityID,
         'contribution_id' => $contributionID,
       ]);
-      $financialTypeChangeTrxnID = $this->addFinancialItemsOnLineItemChange($trxnID, $lineParams, $updatedContribution);
       $lineObj = CRM_Price_BAO_LineItem::retrieve($lineParams);
       // insert financial items
       // ensure entity_financial_trxn table has a linking of it.
@@ -1248,46 +1248,6 @@ WHERE li.contribution_id = %1";
     return $adjustedTrxn;
   }
 
-  /**
-   * Add financial items to reflect line item change.
-   *
-   * @param bool $isCreateAdditionalFinancialTrxn
-   * @param array $lineParams
-   * @param \CRM_Contribute_BAO_Contribution $updatedContribution
-   */
-  protected function addFinancialItemsOnLineItemChange($isCreateAdditionalFinancialTrxn, $lineParams, $updatedContribution) {
-    $tempFinancialTrxnID = NULL;
-    // don't add financial item for cancelled line item
-    if ($lineParams['qty'] == 0) {
-      return NULL;
-    }
-    elseif ($isCreateAdditionalFinancialTrxn) {
-      // This routine & the return below is super uncomfortable.
-      // I have refactored to here and it is hit from
-      // testSubmitUnpaidPriceChangeWhileStillPending
-      // but I'm still skeptical it's not covered elsewhere.
-      // original comment : add financial item if ONLY financial type is changed
-      if ($lineParams['financial_type_id'] != $updatedContribution->financial_type_id) {
-        $changedFinancialTypeID = (int) $lineParams['financial_type_id'];
-        $adjustedTrxnValues = [
-          'from_financial_account_id' => NULL,
-          'to_financial_account_id' => CRM_Financial_BAO_FinancialTypeAccount::getInstrumentFinancialAccount($updatedContribution->payment_instrument_id),
-          'total_amount' => $lineParams['line_total'],
-          'net_amount' => $lineParams['line_total'],
-          'status_id' => $updatedContribution->contribution_status_id,
-          'payment_instrument_id' => $updatedContribution->payment_instrument_id,
-          'contribution_id' => $updatedContribution->id,
-          'is_payment' => TRUE,
-          // since balance is 0, which means contribution is completed
-          'trxn_date' => date('YmdHis'),
-          'currency' => $updatedContribution->currency,
-        ];
-        $adjustedTrxn = CRM_Core_BAO_FinancialTrxn::create($adjustedTrxnValues);
-        return $adjustedTrxn->id;
-      }
-    }
-  }
-
   /**
    * Get Financial items, culling out any that have already been reversed.
    *
index 5ce2ed417831ba0c6b307f7b563672a2f1cde2a1..7c3e9e40cdb856b6102189c5fe24664c07c59b2e 100644 (file)
@@ -85,6 +85,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Setup function.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function setUp() {
     parent::setUp();
@@ -119,19 +122,24 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Clean up after each test.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function tearDown() {
     $this->quickCleanUpFinancialEntities();
-    CRM_Core_DAO::executeQuery('DELETE FROM civicrm_mailing_spool ORDER BY id DESC');
+    $this->quickCleanup(['civicrm_mailing_spool']);
     parent::tearDown();
   }
 
   /**
    * Test the submit function that completes the partially paid Contribution using Credit Card.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
-  public function testAddPaymentUsingCreditCardForPartialyPaidContribution() {
+  public function testAddPaymentUsingCreditCardForPartiallyPaidContribution() {
     $mut = new CiviMailUtils($this, TRUE);
-    $this->createContribution('Partially paid');
+    $this->createPartiallyPaidOrder();
 
     // pay additional amount by using Credit Card
     $this->submitPayment(70, 'live', TRUE);
@@ -157,9 +165,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the submit function that completes the partially paid Contribution.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
-  public function testAddPaymentForPartialyPaidContribution() {
-    $this->createContribution('Partially paid');
+  public function testAddPaymentForPartiallyPaidContribution() {
+    $this->createPartiallyPaidOrder();
 
     // pay additional amount
     $this->submitPayment(70);
@@ -168,9 +179,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the submit function that completes the partially paid Contribution with multiple payments.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testMultiplePaymentForPartiallyPaidContribution() {
-    $this->createContribution('Partially paid');
+    $this->createPartiallyPaidOrder();
 
     // pay additional amount
     $this->submitPayment(50);
@@ -187,9 +201,9 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
       'sequential' => 1,
       'return' => ['target_contact_id', 'assignee_contact_id', 'subject'],
     ])['values'];
-    $this->assertEquals(2, count($activities));
-    $this->assertEquals('$ 50.00 - Offline Payment for Contribution', $activities[0]['subject']);
-    $this->assertEquals('$ 20.00 - Offline Payment for Contribution', $activities[1]['subject']);
+    $this->assertCount(3, $activities);
+    $this->assertEquals('$ 50.00 - Offline Payment for Contribution', $activities[1]['subject']);
+    $this->assertEquals('$ 20.00 - Offline Payment for Contribution', $activities[2]['subject']);
     $this->assertEquals(CRM_Core_Session::singleton()->getLoggedInContactID(), $activities[0]['source_contact_id']);
     $this->assertEquals([$this->_individualId], $activities[0]['target_contact_id']);
     $this->assertEquals([], $activities[0]['assignee_contact_id']);
@@ -199,10 +213,11 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
    * Test the submit function that completes the partially paid Contribution with multiple payments.
    *
    * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testMultiplePaymentForPartiallyPaidContributionWithOneCreditCardPayment() {
     $mut = new CiviMailUtils($this, TRUE);
-    $this->createContribution('Partially paid');
+    $this->createPartiallyPaidOrder();
     // In general when there is tpl leakage we try to fix. At the moment, however,
     // the tpl leakage on credit card related things is kind of 'by-design' - or
     // at least we haven't found a way to replace the way in with Payment.send_confirmation
@@ -242,10 +257,11 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
    * Test the submit function that completes the pending pay later Contribution using Credit Card.
    *
    * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testAddPaymentUsingCreditCardForPendingPayLaterContribution() {
     $mut = new CiviMailUtils($this, TRUE);
-    $this->createContribution('Pending');
+    $this->createPendingOrder();
 
     // pay additional amount by using Credit Card
     $this->submitPayment(100, 'live', TRUE);
@@ -269,9 +285,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the submit function that completes the pending pay later Contribution.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testAddPaymentForPendingPayLaterContribution() {
-    $this->createContribution('Pending');
+    $this->createPendingOrder();
 
     // pay additional amount
     $this->submitPayment(70);
@@ -285,45 +304,55 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the Membership status after completing the pending pay later Contribution.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testMembershipStatusAfterCompletingPayLaterContribution() {
-    $this->createContribution('Pending');
+    $this->createPendingOrder();
     $membership = $this->createPendingMembershipAndRecordContribution($this->_contributionId);
     // pay additional amount
     $this->submitPayment(100);
-    $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
-    $contributionMembership = $this->callAPISuccessGetSingle('Membership', ['id' => $membership["id"]]);
-    $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['id' => $contributionMembership["status_id"]]);
+    $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
+    $contributionMembership = $this->callAPISuccessGetSingle('Membership', ['id' => $membership['id']]);
+    $membershipStatus = $this->callAPISuccessGetSingle('MembershipStatus', ['id' => $contributionMembership['status_id']]);
     $this->assertEquals('New', $membershipStatus['name']);
   }
 
+  /**
+   * @param $contributionId
+   *
+   * @return array|int
+   *
+   * @throws \CRM_Core_Exception
+   */
   private function createPendingMembershipAndRecordContribution($contributionId) {
     $this->_individualId = $this->individualCreate();
     $membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', [
       'domain_id' => 1,
-      'name' => "AnnualFixed",
+      'name' => 'AnnualFixed',
       'member_of_contact_id' => 1,
-      'duration_unit' => "year",
+      'duration_unit' => 'year',
       'duration_interval' => 1,
-      'period_type' => "fixed",
-      'fixed_period_start_day' => "101",
-      'fixed_period_rollover_day' => "1231",
+      'period_type' => 'fixed',
+      'fixed_period_start_day' => '101',
+      'fixed_period_rollover_day' => '1231',
       'relationship_type_id' => 20,
       'financial_type_id' => 2,
     ]);
     $membershipStatuses = CRM_Member_PseudoConstant::membershipStatus();
-    $pendingStatusId = array_search('Pending', $membershipStatuses);
+    $pendingStatusId = array_search('Pending', $membershipStatuses, TRUE);
     $membership = $this->callAPISuccess('Membership', 'create', [
       'contact_id' => $this->_individualId,
       'membership_type_id' => $membershipTypeAnnualFixed['id'],
     ]);
     // Updating Membership status to Pending
     $membership = $this->callAPISuccess('Membership', 'create', [
-      'id' => $membership["id"],
+      'id' => $membership['id'],
       'status_id' => $pendingStatusId,
     ]);
-    $membershipPayment = $this->callAPISuccess('MembershipPayment', 'create', [
-      'membership_id' => $membership["id"],
+    $this->callAPISuccess('MembershipPayment', 'create', [
+      'membership_id' => $membership['id'],
       'contribution_id' => $contributionId,
     ]);
     return $membership;
@@ -331,9 +360,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the submit function that completes the pending pay later Contribution with multiple payments.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testMultiplePaymentForPendingPayLaterContribution() {
-    $this->createContribution('Pending');
+    $this->createPendingOrder();
 
     // pay additional amount
     $this->submitPayment(40);
@@ -354,9 +386,12 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
 
   /**
    * Test the submit function that completes the pending pay later Contribution with multiple payments.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testMultiplePaymentForPendingPayLaterContributionWithOneCreditCardPayment() {
-    $this->createContribution('Pending');
+    $this->createPendingOrder();
 
     // pay additional amount
     $this->submitPayment(50);
@@ -375,34 +410,6 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
     $this->checkResults([50, 20, 20, 10], 4);
   }
 
-  /**
-   * Function to create pending pay later or partially paid conntribution.
-   *
-   * @param string $typeofContribution
-   *
-   * @throws \CRM_Core_Exception
-   */
-  public function createContribution($typeofContribution = 'Pending') {
-    if ($typeofContribution == 'Partially paid') {
-      $contributionParams = array_merge($this->_params, [
-        'partial_payment_total' => 100.00,
-        'partial_amount_to_pay' => 30,
-        'contribution_status_id' => 1,
-      ]);
-    }
-    elseif ($typeofContribution == 'Pending') {
-      $contributionParams = array_merge($this->_params, [
-        'contribution_status_id' => 2,
-        'is_pay_later' => 1,
-      ]);
-    }
-    $contribution = $this->callAPISuccess('Contribution', 'create', $contributionParams);
-    $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
-    $this->assertNotEmpty($contribution);
-    $this->assertEquals($typeofContribution, CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution['contribution_status_id']));
-    $this->_contributionId = $contribution['id'];
-  }
-
   /**
    * Function to submit payments for contribution.
    *
@@ -411,6 +418,8 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
    * @param string $mode
    *  Mode of Payment
    * @param bool $isEmailReceipt
+   *
+   * @throws \CiviCRM_API3_Exception
    */
   public function submitPayment($amount, $mode = NULL, $isEmailReceipt = FALSE) {
     $form = new CRM_Contribute_Form_AdditionalPayment();
@@ -430,7 +439,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
     ];
     if ($mode) {
       $submitParams += [
-        'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments),
+        'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments, TRUE),
         'payment_processor_id' => $this->paymentProcessorID,
         'credit_card_exp_date' => ['M' => 5, 'Y' => 2025],
         'credit_card_number' => '411111111111111',
@@ -444,7 +453,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
     }
     else {
       $submitParams += [
-        'payment_instrument_id' => array_search('Check', $this->paymentInstruments),
+        'payment_instrument_id' => array_search('Check', $this->paymentInstruments, TRUE),
         'check_number' => 'check-12345',
       ];
     }
@@ -460,6 +469,7 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
    * @param int $count
    *   Number payment for contribution
    *
+   * @throws \CRM_Core_Exception
    */
   public function checkResults($amounts, $count) {
     $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $this->_contributionId]);
@@ -467,11 +477,44 @@ class CRM_Contribute_Form_AdditionalPaymentTest extends CiviUnitTestCase {
     $this->assertEquals('Completed', $contribution['contribution_status']);
 
     $this->callAPISuccessGetCount('EntityFinancialTrxn', [
-      'entity_table' => "civicrm_contribution",
+      'entity_table' => 'civicrm_contribution',
       'entity_id' => $this->_contributionId,
       'financial_trxn_id.is_payment' => 1,
       'financial_trxn_id.total_amount' => ['IN' => $amounts],
     ], $count);
   }
 
+  /**
+   * Create a pending order.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  protected function createPendingOrder() {
+    $orderParams = array_merge($this->_params, [
+      'contribution_status_id' => 'Pending',
+      'is_pay_later' => 1,
+    ]);
+    $contribution = $this->callAPISuccess('Order', 'create', $orderParams);
+    $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
+    $this->assertEquals('Pending', CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution['contribution_status_id']));
+    $this->_contributionId = $contribution['id'];
+  }
+
+  /**
+   * Create a partially paid order.
+   *
+   * @throws \CRM_Core_Exception
+   */
+  protected function createPartiallyPaidOrder() {
+    $orderParams = array_merge($this->_params, [
+      'total_amount' => 100.00,
+      'contribution_status_id' => 'Pending',
+      'api.Payment.create' => ['total_amount' => 30],
+    ]);
+    $contribution = $this->callAPISuccess('Order', 'create', $orderParams);
+    $contribution = $this->callAPISuccessGetSingle('Contribution', ['id' => $contribution['id']]);
+    $this->assertEquals('Partially paid', CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution['contribution_status_id']));
+    $this->_contributionId = $contribution['id'];
+  }
+
 }
index 622d37612a82f4776d6176d7411f928898ad5c72..7c7b3defb5c145faec857d824bd33617e2d19873 100644 (file)
@@ -59,6 +59,9 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   /**
    * Set up for test.
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function setUp() {
     parent::setUp();
@@ -86,11 +89,11 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
    * @param string $type
    *
    * @return int
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    * @todo resolve this with parent function.
    */
   protected function priceSetCreate($type = 'Radio') {
-    $feeTotal = 55;
-    $minAmt = 0;
     $paramsSet['title'] = 'Two Options' . substr(sha1(rand()), 0, 4);
     $paramsSet['name'] = CRM_Utils_String::titleToVar('Two Options') . substr(sha1(rand()), 0, 4);
     $paramsSet['is_active'] = FALSE;
@@ -98,7 +101,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
     $priceSet = CRM_Price_BAO_PriceSet::create($paramsSet);
 
-    if ($type == 'Text') {
+    if ($type === 'Text') {
       $paramsField = [
         'label' => 'Text Price Field',
         'name' => CRM_Utils_String::titleToVar('text_price_field'),
@@ -118,14 +121,15 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
       ];
     }
     else {
+      /** @noinspection UnNecessaryDoubleQuotesInspection */
       $paramsField = [
         'label' => 'Price Field',
         'name' => CRM_Utils_String::titleToVar('Two Options'),
         'html_type' => 'Radio',
         //'price' => $feeTotal,
-        'option_label' => ['1' => 'Expensive Room', '2' => "Cheap Room", '3' => 'Very Expensive', '4' => 'No Fee'],
+        'option_label' => ['1' => 'Expensive Room', '2' => 'Cheap Room', '3' => 'Very Expensive', '4' => 'No Fee'],
         'option_value' => ['1' => 'E', '2' => 'C', '3' => 'V', '4' => 'N'],
-        'option_name' => ['1' => 'Expensive', '2' => "Cheap", "3" => "Very Expensive", '3' => 'No Fee'],
+        'option_name' => ['1' => 'Expensive', '2' => 'Cheap', '3' => 'Very Expensive'],
         'option_weight' => ['1' => 1, '2' => 2, '3' => 3, '4' => 4],
         'option_amount' => ['1' => $this->_expensiveFee, '2' => $this->_cheapFee, '3' => $this->_veryExpensive, '4' => $this->_noFee],
         'option_count' => [1 => 1, 2 => 1, 3 => 1, 4 => 1],
@@ -182,7 +186,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
          WHERE  contribution_id = {$contributionId}";
     $dao = CRM_Core_DAO::executeQuery($query);
 
-    $this->assertTrue($dao->fetch(), "Succeeded retrieving invoicetotal");
+    $this->assertTrue($dao->fetch(), 'Succeeded retrieving invoice total');
     return $dao->total;
   }
 
@@ -202,7 +206,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
     ";
     $dao = CRM_Core_DAO::executeQuery($query);
 
-    $this->assertTrue($dao->fetch(), "Succeeded retrieving total Income");
+    $this->assertTrue($dao->fetch(), 'Succeeded retrieving total Income');
     return $dao->total;
   }
 
@@ -218,6 +222,10 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   /**
    * Prepare records for editing.
+   *
+   * @param null $actualPaidAmt
+   *
+   * @throws \CRM_Core_Exception
    */
   public function registerParticipantAndPay($actualPaidAmt = NULL) {
     $params = [
@@ -225,7 +233,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
       'is_test' => 0,
       'is_pay_later' => 0,
       'event_id' => $this->_eventId,
-      'register_date' => date('Y-m-d') . " 00:00:00",
+      'register_date' => date('Y-m-d') . ' 00:00:00',
       'role_id' => 1,
       'status_id' => 1,
       'source' => 'Event_' . $this->_eventId,
@@ -235,18 +243,18 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
     $participant = $this->callAPISuccess('Participant', 'create', $params);
     $this->_participantId = $participant['id'];
 
-    $actualPaidAmt = $actualPaidAmt ? $actualPaidAmt : $this->_expensiveFee;
+    $actualPaidAmt = $actualPaidAmt ?: $this->_expensiveFee;
 
     $contributionParams = [
       'total_amount' => $actualPaidAmt,
-      'source' => 'Testset with information',
+      'source' => 'Test set with information',
       'currency' => 'USD',
-      'receipt_date' => date('Y-m-d') . " 00:00:00",
+      'receipt_date' => date('Y-m-d') . ' 00:00:00',
       'contact_id' => $this->_contactId,
       'financial_type_id' => 4,
       'payment_instrument_id' => 4,
       'contribution_status_id' => 1,
-      'receive_date' => date('Y-m-d') . " 00:00:00",
+      'receive_date' => date('Y-m-d') . ' 00:00:00',
       'skipLineItem' => 1,
       'partial_payment_total' => $this->_expensiveFee,
       'partial_amount_to_pay' => $actualPaidAmt,
@@ -271,43 +279,50 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   }
 
+  /**
+   * @throws \CRM_Core_Exception
+   */
   public function testCRM19273() {
     $this->registerParticipantAndPay();
 
     $priceSetParams['price_' . $this->priceSetFieldID] = $this->cheapFeeValueID;
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
-    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee);
+    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
     $this->balanceCheck($this->_cheapFee);
 
     $priceSetParams['price_' . $this->priceSetFieldID] = $this->expensiveFeeValueID;
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
 
-    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee);
+    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
 
     $this->balanceCheck($this->_expensiveFee);
 
     $priceSetParams['price_' . $this->priceSetFieldID] = $this->veryExpensiveFeeValueID;
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
-    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, $this->_expensiveFee);
+    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
     $this->balanceCheck($this->_veryExpensive);
   }
 
   /**
    * CRM-21245: Test that Contribution status doesn't changed to 'Pending Refund' from 'Partially Paid' if the partially paid amount is lower then newly selected fee amount
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testCRM21245() {
     $this->registerParticipantAndPay(50);
-    $partiallyPaidContribuitonStatus = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid');
-    $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContribuitonStatus);
+    $partiallyPaidContributionStatus = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Partially paid');
+    $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContributionStatus);
 
     $priceSetParams['price_' . $this->priceSetFieldID] = $this->veryExpensiveFeeValueID;
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_participantId, 'participant');
     CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $this->_participantId, 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
-    $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContribuitonStatus);
+    $this->assertEquals($this->callAPISuccessGetValue('Contribution', ['id' => $this->_contributionId, 'return' => 'contribution_status_id']), $partiallyPaidContributionStatus);
   }
 
   /**
    * Test that proper financial items are recorded for cancelled line items
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testCRM20611() {
     $this->registerParticipantAndPay();
@@ -360,6 +375,9 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   /**
    * Test to ensure that correct financial records are entered on text price field fee change on event registration
+   *
+   * @throws \CRM_Core_Exception
+   * @throws \CiviCRM_API3_Exception
    */
   public function testCRM21513() {
     $this->_priceSetID = $this->priceSetCreate('Text');
@@ -373,7 +391,7 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
       'is_test' => 0,
       'is_pay_later' => 0,
       'event_id' => $this->_eventId,
-      'register_date' => date('Y-m-d') . " 00:00:00",
+      'register_date' => date('Y-m-d') . ' 00:00:00',
       'role_id' => 1,
       'status_id' => 1,
       'source' => 'Event_' . $this->_eventId,
@@ -383,14 +401,14 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
     $this->_participantId = $participant['id'];
     $contributionParams = [
       'total_amount' => 10,
-      'source' => 'Testset with information',
+      'source' => 'Test set with information',
       'currency' => 'USD',
-      'receipt_date' => date('Y-m-d') . " 00:00:00",
+      'receipt_date' => date('Y-m-d') . ' 00:00:00',
       'contact_id' => $this->_contactId,
       'financial_type_id' => 4,
       'payment_instrument_id' => 4,
       'contribution_status_id' => CRM_Core_PseudoConstant::getKey('CRM_Contribute_DAO_Contribution', 'contribution_status_id', 'Pending'),
-      'receive_date' => date('Y-m-d') . " 00:00:00",
+      'receive_date' => date('Y-m-d') . ' 00:00:00',
       'skipLineItem' => 1,
     ];
 
@@ -412,12 +430,12 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
     // CASE 2: Choose text price qty 3 (x$10 = $30 amount)
     $priceSetParams['price_' . $this->priceSetFieldID] = 3;
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id'], 'participant');
-    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, 0);
+    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
 
     // CASE 3: Choose text price qty 2 (x$10 = $20 amount)
     $priceSetParams['price_' . $this->priceSetFieldID] = 2;
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($participant['id'], 'participant');
-    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem, 0);
+    CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participant['id'], 'participant', $this->_contributionId, $this->_feeBlock, $lineItem);
 
     $financialItems = $this->callAPISuccess('FinancialItem', 'Get', [
       'entity_table' => 'civicrm_line_item',
@@ -462,6 +480,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   /**
    * CRM-17151: Test that Contribution status change to 'Completed' if balance is zero.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testCRM17151() {
     $this->registerParticipantAndPay();
@@ -487,6 +507,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   /**
    * Test that recording a refund when fee selection is 0 works
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testRefundWithFeeAmount0() {
     $this->registerParticipantAndPay();
@@ -540,6 +562,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   /**
    * dev-financial-40: Test that partial payment entries in entity-financial-trxn table to ensure that reverse transaction is entered
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testPartialPaymentEntries() {
     $this->registerParticipantAndPay($this->_expensiveFee);
@@ -579,6 +603,8 @@ class CRM_Event_BAO_ChangeFeeSelectionTest extends CiviUnitTestCase {
 
   /**
    * dev-financial-40: Test that refund payment entries in entity-financial-trxn table to ensure that reverse transaction is entered on fee change to lesser amount
+   *
+   * @throws \CRM_Core_Exception
    */
   public function testRefundPaymentEntries() {
     $this->registerParticipantAndPay($this->_expensiveFee);
index 5a86cfcbb00eeaeee604fd817dc8908b292375f3..851481de221bb9d2b6aa8646ec14c62f93c8813d 100644 (file)
@@ -102,6 +102,10 @@ class CRM_Event_Form_ParticipantTest extends CiviUnitTestCase {
     $this->assertEquals(55, $sum);
 
     CRM_Price_BAO_LineItem::changeFeeSelections($priceSetParams, $participants['id'], 'participant', $contribution['id'], $this->eventFeeBlock, $lineItem);
+    // Check that no payment records have been created.
+    // In https://lab.civicrm.org/dev/financial/issues/94 we had an issue where payments were created when none happend.
+    $payments = $this->callAPISuccess('Payment', 'get', [])['values'];
+    $this->assertCount(0, $payments);
     $lineItem = CRM_Price_BAO_LineItem::getLineItems($participants['id'], 'participant');
     // Participants is updated to 0 but line remains.
     $this->assertEquals(0, $lineItem[1]['subTotal']);