CRM-16188, modified code to add exception and also changed test to check exception...
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 26 Jan 2016 22:15:47 +0000 (03:45 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Tue, 26 Jan 2016 22:15:47 +0000 (03:45 +0530)
----------------------------------------
* CRM-16188: Create an order API
  https://issues.civicrm.org/jira/browse/CRM-16188

CRM/Contribute/BAO/Contribution.php
tests/phpunit/CRM/Contribute/BAO/ContributionTest.php

index 763f9b629dd2b108de4b6a786f175ddbc4506343..ae31ac8a909df44af8f7dbc6eea7352b956fd0aa 100644 (file)
@@ -4824,7 +4824,6 @@ LIMIT 1;";
    * @param array $params
    *  array of order params.
    *
-   * @return string
    */
   public static function checkLineItems(&$params) {
     $totalAmount = CRM_Utils_Array::value('total_amount', $params);
@@ -4841,9 +4840,8 @@ LIMIT 1;";
       $params['total_amount'] = $lineItemAmount;
     }
     elseif ($totalAmount != $lineItemAmount) {
-      return "Line item total doesn't match with total amount.";
+      throw new API_Exception("Line item total doesn't match with total amount.");
     }
-    return NULL;
   }
 
 }
index c481d63ee9f4c50cf056f85a3dbcb018704667b2..4061b0f7bc63a4a255360361edf9fbd0cd6f9aad 100644 (file)
@@ -819,12 +819,16 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2";
         ),
       ),
     );
-    $error = CRM_Contribute_BAO_Contribution::checkLineItems($params);
-    $this->assertEquals("Line item total doesn't match with total amount.", $error);
+    try {
+      $error = CRM_Contribute_BAO_Contribution::checkLineItems($params);
+      $this->fail("Missed expected exception");
+    }
+    catch (Exception $e) {
+      $this->assertEquals("Line item total doesn't match with total amount.", $e->getMessage());
+    }
     $this->assertEquals(3, $params['line_items'][0]['line_item'][0]['financial_type_id']);
     $params['total_amount'] = 300;
-    $error = CRM_Contribute_BAO_Contribution::checkLineItems($params);
-    $this->assertEquals(NULL, $error);
+    CRM_Contribute_BAO_Contribution::checkLineItems($params);
   }
 
 }