CRM-19587, Added test
authorPradeep Nayak <pradpnayak@gmail.com>
Tue, 1 Nov 2016 12:21:41 +0000 (17:51 +0530)
committerPradeep Nayak <pradpnayak@gmail.com>
Wed, 2 Nov 2016 08:10:05 +0000 (13:40 +0530)
----------------------------------------
* CRM-19587: DB Error when trying to delete FInancial Account
  https://issues.civicrm.org/jira/browse/CRM-19587

tests/phpunit/CRM/Financial/BAO/FinancialAccountTest.php

index 9a31b1c3a68f5d89aebd0a30478fd35479cbb0f7..f2fb46402ed9310e441f24e61fe153fd78b9956a 100644 (file)
@@ -119,6 +119,39 @@ class CRM_Financial_BAO_FinancialAccountTest extends CiviUnitTestCase {
     $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.');
   }
 
+  /**
+   * Check method del()
+   */
+  public function testdelIfHasContribution() {
+    $params = array(
+      'name' => 'Donation Test',
+      'is_active' => 1,
+      'is_deductible' => 1,
+      'is_reserved' => 1,
+    );
+    $financialType = CRM_Financial_BAO_FinancialType::add($params);
+    $defaults = array();
+    $params = array(
+      'name' => 'Donation Test',
+      'is_active' => 1,
+    );
+    $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
+
+    $contactId = $this->individualCreate();
+    $contributionParams = array(
+      'total_amount' => 300,
+      'currency' => 'USD',
+      'contact_id' => $contactId,
+      'financial_type_id' => $financialType->id,
+      'contribution_status_id' => 1,
+    );
+    $contributions = CRM_Contribute_BAO_Contribution::create($contributionParams);
+    CRM_Financial_BAO_FinancialAccount::del($result->id);
+    $params = array('id' => $result->id);
+    $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults);
+    $this->assertEquals(empty($result), FALSE, 'Verify financial account record deletion.');
+  }
+
   /**
    * Check method getAccountingCode()
    */