add test enforcing automatic chaining for financial type/account create
authordemeritcowboy <demeritcowboy@hotmail.com>
Thu, 13 May 2021 20:22:57 +0000 (16:22 -0400)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Thu, 13 May 2021 20:22:57 +0000 (16:22 -0400)
tests/phpunit/api/v3/FinancialTypeTest.php

index 0a96e4247aed4de8c75da96a9e053633d3b38d80..4b9a65312389e6798757401b8b4ba0abee9f95f2 100644 (file)
@@ -92,4 +92,26 @@ class api_v3_FinancialTypeTest extends CiviUnitTestCase {
     }
   }
 
+  /**
+   * Enforce the creation of an associated financial account when a financial
+   * type is created through the api.
+   * @dataProvider versionThreeAndFour
+   */
+  public function testAssociatedFinancialAccountGetsCreated($apiVersion) {
+    $this->callAPISuccess('FinancialType', 'create', [
+      'version' => $apiVersion,
+      'name' => 'Lottery Tickets',
+      'is_deductible' => FALSE,
+      'is_reserved' => FALSE,
+      'is_active' => TRUE,
+    ]);
+    // There should be an account (as opposed to type) with the same name that gets autocreated.
+    $result = $this->callAPISuccess('FinancialAccount', 'getsingle', [
+      'version' => $apiVersion,
+      'name' => 'Lottery Tickets',
+    ]);
+    $this->assertNotEmpty($result['id'], 'Financial account with same name as type did not get created.');
+    $this->assertEquals('INC', $result['account_type_code'], 'Financial account created is not an income account.');
+  }
+
 }