From: Pradeep Nayak Date: Wed, 22 Jun 2016 21:20:42 +0000 (+0530) Subject: CRM-16189, moved the function from PseudoConstant to BAO X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ce7fc91ac8516cd8d527efbdd1d6f8953ffd593d;p=civicrm-core.git CRM-16189, moved the function from PseudoConstant to BAO ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index c30c4b8cb3..28ad9988b9 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -5028,4 +5028,22 @@ LIMIT 1;"; return $values; } + /** + * Get values of CiviContribute Settings + * and check if its enabled or not. + * + * + * @param string $name + * @return string + * + */ + public static function checkContributeSettings($name = NULL) { + $contributeSettings = Civi::settings()->get('contribution_invoice_settings'); + + if ($name) { + return CRM_Utils_Array::value($name, $contributeSettings); + } + return $contributeSettings; + } + } diff --git a/CRM/Contribute/PseudoConstant.php b/CRM/Contribute/PseudoConstant.php index 350181e4a9..f5f79750b5 100644 --- a/CRM/Contribute/PseudoConstant.php +++ b/CRM/Contribute/PseudoConstant.php @@ -101,12 +101,6 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant { */ private static $batch; - /** - * Get values of CiviContribute Settings - * @var array - */ - private static $contributeSettings; - /** * DEPRECATED. Please use the buildOptions() method in the appropriate BAO object. * @@ -446,24 +440,4 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant { return self::$batch; } - /** - * Get values of CiviContribute Settings - * and check if its enabled or not - * - * - * @param string $name - * @return string - * - */ - public static function checkContributeSettings($name = NULL) { - if (empty(self::$contributeSettings)) { - self::$contributeSettings = Civi::settings()->get('contribution_invoice_settings'); - } - - if ($name) { - return CRM_Utils_Array::value($name, self::$contributeSettings); - } - return self::$contributeSettings; - } - } diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index cc42f0c69a..b2173e5e42 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -830,4 +830,20 @@ WHERE eft.entity_id = %1 AND ft.to_financial_account_id <> %2"; $this->assertEquals("$ 200.00 - STUDENT", $activity->subject, 'Check for total amount in activity.'); } + /** + * Test checkContributeSettings. + */ + public function testCheckContributeSettings() { + $settings = CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled'); + $this->assertNull($settings); + $params = array( + 'contribution_invoice_settings' => array( + 'deferred_revenue_enabled' => '1', + ), + ); + $this->callAPISuccess('Setting', 'create', $params); + $settings = CRM_Contribute_BAO_Contribution::checkContributeSettings('deferred_revenue_enabled'); + $this->assertEquals($settings, 1, 'Check for settings has failed'); + } + } diff --git a/tests/phpunit/CRM/Contribute/PseudoConstantTest.php b/tests/phpunit/CRM/Contribute/PseudoConstantTest.php deleted file mode 100644 index f402fe03ac..0000000000 --- a/tests/phpunit/CRM/Contribute/PseudoConstantTest.php +++ /dev/null @@ -1,55 +0,0 @@ -assertNull($settings); - CRM_Contribute_PseudoConstant::flush('contributeSettings'); - $params = array( - 'contribution_invoice_settings' => array( - 'deferred_revenue_enabled' => '1', - ), - ); - $this->callAPISuccess('Setting', 'create', $params); - $settings = CRM_Contribute_PseudoConstant::checkContributeSettings('deferred_revenue_enabled'); - $this->assertEquals($settings, 1, "Check for settings has failed"); - } - -}