From: Coleman Watts Date: Thu, 21 Nov 2013 04:25:15 +0000 (-0800) Subject: CRM-13807 - Fix last to commit to getBAO and add unit test X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=49e101d07f07b0ffe3a61c8ac1c88b7c50bc34f1;p=civicrm-core.git CRM-13807 - Fix last to commit to getBAO and add unit test --- diff --git a/api/v3/utils.php b/api/v3/utils.php index 4c7d369978..b0b2900b1e 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -308,8 +308,8 @@ function _civicrm_api3_get_DAO($name) { function _civicrm_api3_get_BAO($name) { $dao = _civicrm_api3_get_DAO($name); $bao = str_replace("DAO", "BAO", $dao); - $file = str_replace('_', '/', $dao) . '.php'; - return file_exists($file) ? $bao : $dao; + $file = strtr($bao, '_', '/') . '.php'; + return stream_resolve_include_path($file) ? $bao : $dao; } /** diff --git a/tests/phpunit/api/v3/UtilsTest.php b/tests/phpunit/api/v3/UtilsTest.php index 8cbd5fa448..9d903b3ffb 100644 --- a/tests/phpunit/api/v3/UtilsTest.php +++ b/tests/phpunit/api/v3/UtilsTest.php @@ -175,33 +175,37 @@ class api_v3_UtilsTest extends CiviUnitTestCase { * Test GET DAO function returns DAO */ function testGetDAO() { - $DAO = _civicrm_api3_get_DAO('civicrm_api3_custom_group_get'); - $this->assertEquals('CRM_Core_DAO_CustomGroup', $DAO); - $DAO = _civicrm_api3_get_DAO('custom_group'); - $this->assertEquals('CRM_Core_DAO_CustomGroup', $DAO); - $DAO = _civicrm_api3_get_DAO('CustomGroup'); - $this->assertEquals('CRM_Core_DAO_CustomGroup', $DAO); - $DAO = _civicrm_api3_get_DAO('civicrm_api3_custom_field_get'); - $this->assertEquals('CRM_Core_DAO_CustomField', $DAO); - $DAO = _civicrm_api3_get_DAO('civicrm_api3_survey_get'); - $this->assertEquals('CRM_Campaign_DAO_Survey', $DAO); - $DAO = _civicrm_api3_get_DAO('civicrm_api3_pledge_payment_get'); - $this->assertEquals('CRM_Pledge_DAO_PledgePayment', $DAO); - $DAO = _civicrm_api3_get_DAO('civicrm_api3_website_get'); - $this->assertEquals('CRM_Core_DAO_Website', $DAO); - $DAO = _civicrm_api3_get_DAO('Membership'); - $this->assertEquals('CRM_Member_DAO_Membership', $DAO); + $params = array( + 'civicrm_api3_custom_group_get' => 'CRM_Core_DAO_CustomGroup', + 'custom_group' => 'CRM_Core_DAO_CustomGroup', + 'CustomGroup' => 'CRM_Core_DAO_CustomGroup', + 'civicrm_api3_custom_field_get' => 'CRM_Core_DAO_CustomField', + 'civicrm_api3_survey_get' => 'CRM_Campaign_DAO_Survey', + 'civicrm_api3_pledge_payment_get' => 'CRM_Pledge_DAO_PledgePayment', + 'civicrm_api3_website_get' => 'CRM_Core_DAO_Website', + 'Membership' => 'CRM_Member_DAO_Membership', + ); + foreach ($params as $input => $expected) { + $result = _civicrm_api3_get_DAO($input); + $this->assertEquals($expected, $result); + } } /* - * Test GET DAO function returns DAO + * Test GET BAO function returns BAO when it exists */ function testGetBAO() { - $BAO = _civicrm_api3_get_BAO('civicrm_api3_website_get'); - $this->assertEquals('CRM_Core_BAO_Website', $BAO); - $BAO = _civicrm_api3_get_BAO('civicrm_api3_survey_get'); - $this->assertEquals('CRM_Campaign_BAO_Survey', $BAO); - $BAO = _civicrm_api3_get_BAO('civicrm_api3_pledge_payment_get'); - $this->assertEquals('CRM_Pledge_BAO_PledgePayment', $BAO); + $params = array( + 'civicrm_api3_website_get' => 'CRM_Core_BAO_Website', + 'civicrm_api3_survey_get' => 'CRM_Campaign_BAO_Survey', + 'civicrm_api3_pledge_payment_get' => 'CRM_Pledge_BAO_PledgePayment', + 'Household' => 'CRM_Contact_BAO_Contact', + // Note this one DOES NOT have a BAO so we expect to fall back on returning the DAO + 'mailing_group' => 'CRM_Mailing_DAO_MailingGroup', + ); + foreach ($params as $input => $expected) { + $result = _civicrm_api3_get_BAO($input); + $this->assertEquals($expected, $result); + } } function test_civicrm_api3_validate_fields() {