From 5c1174d31b09ac92f62dbb8e749498661a95c7bc Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 20 Nov 2013 20:33:17 -0800 Subject: [PATCH] CRM-13807 - Add comments and null test --- api/v3/utils.php | 4 ++++ tests/phpunit/api/v3/UtilsTest.php | 2 ++ 2 files changed, 6 insertions(+) diff --git a/api/v3/utils.php b/api/v3/utils.php index b0b2900b1e..b257fcc3a7 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -307,8 +307,12 @@ function _civicrm_api3_get_DAO($name) { */ function _civicrm_api3_get_BAO($name) { $dao = _civicrm_api3_get_DAO($name); + if (!$dao) { + return NULL; + } $bao = str_replace("DAO", "BAO", $dao); $file = strtr($bao, '_', '/') . '.php'; + // Check if this entity actually has a BAO. Fall back on the DAO if not. 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 9d903b3ffb..a343fceb2b 100644 --- a/tests/phpunit/api/v3/UtilsTest.php +++ b/tests/phpunit/api/v3/UtilsTest.php @@ -201,6 +201,8 @@ class api_v3_UtilsTest extends CiviUnitTestCase { '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', + // Make sure we get null back with nonexistant entities + 'civicrm_this_does_not_exist' => NULL, ); foreach ($params as $input => $expected) { $result = _civicrm_api3_get_BAO($input); -- 2.25.1