Skip to content
Snippets Groups Projects
Commit 49e101d0 authored by colemanw's avatar colemanw
Browse files

CRM-13807 - Fix last to commit to getBAO and add unit test

parent d9f036bb
Branches
Tags
No related merge requests found
......@@ -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;
}
/**
......
......@@ -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() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment