From 02e9e3153c45694a19db0a3ec63593262a885520 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Thu, 27 Feb 2020 17:51:29 +1100 Subject: [PATCH] [NFC] Extend unit tests to ensure that entity financial account is correctly deleted when financial type is deleted --- .../CRM/Financial/BAO/FinancialTypeTest.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php index 3ee26b5c45..c468d61527 100644 --- a/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php +++ b/tests/phpunit/CRM/Financial/BAO/FinancialTypeTest.php @@ -21,6 +21,10 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { } public function teardown() { + global $dbLocale; + if ($dbLocale) { + CRM_Core_I18n_Schema::makeSinglelingual('en_US'); + } $this->financialAccountDelete('Donations'); } @@ -88,10 +92,29 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { $this->assertEquals($isActive, 0, 'Verify financial types is_active.'); } + /** + * Data provider for testGitLabIssue1108 + * + * First we run it without multiLingual mode, then with. + * + * This is because we test table names, which may have been translated in a + * multiLingual context. + * + */ + public function multiLingual() { + return [[0], [1]]; + } + /** * Check method del() + * + * @dataProvider multiLingual */ - public function testDel() { + public function testDel($isMultiLingual) { + if ($isMultiLingual) { + $this->enableMultilingual(); + CRM_Core_I18n_Schema::addLocale('fr_FR', 'en_US'); + } $params = [ 'name' => 'Donations', 'is_deductible' => 0, @@ -100,10 +123,20 @@ class CRM_Financial_BAO_FinancialTypeTest extends CiviUnitTestCase { $ids = []; $financialType = CRM_Financial_BAO_FinancialType::add($params, $ids); + if ($isMultiLingual) { + global $dbLocale; + $dbLocale = '_fr_FR'; + } CRM_Financial_BAO_FinancialType::del($financialType->id); $params = ['id' => $financialType->id]; $result = CRM_Financial_BAO_FinancialType::retrieve($params, $defaults); $this->assertEquals(empty($result), TRUE, 'Verify financial types record deletion.'); + $results = CRM_Core_DAO::executeQuery("SELECT * FROM civicrm_entity_financial_account WHERE entity_id = %1", [1 => [$financialType->id, 'Positive']])->fetchAll(); + $this->assertEquals(empty($results), TRUE, 'Assert related entity financial account has been deleted as well'); + if ($isMultiLingual) { + global $dbLocale; + $dbLocale = '_en_US'; + } } /** -- 2.25.1