From 1cbea43e879b79d8f5e2a7184920798f219273db Mon Sep 17 00:00:00 2001 From: CiviCRM Date: Wed, 20 Mar 2013 08:42:25 -0400 Subject: [PATCH] CRM-12133 - api/v3/ReportTemplate - Fix option_group_id and component_id errors --- api/v3/ReportTemplate.php | 6 ++++++ tests/phpunit/api/v3/ReportTemplateTest.php | 10 +++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/api/v3/ReportTemplate.php b/api/v3/ReportTemplate.php index 1ad88c2a47..84cb499a25 100644 --- a/api/v3/ReportTemplate.php +++ b/api/v3/ReportTemplate.php @@ -38,6 +38,9 @@ function civicrm_api3_report_template_create($params) { $params['option_group_id'] = CRM_Core_DAO::getFieldValue( 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name' ); + if (!empty($params['component_id']) && !is_numeric($params['component_id'])) { + $params['component_id'] = array_search($params['component_id'], CRM_Core_PseudoConstant::component()); + } return civicrm_api3_option_value_create($params); } @@ -52,6 +55,9 @@ function _civicrm_api3_report_template_create_spec(&$params) { _civicrm_api3_option_value_create_spec($params); $params['value']['api.aliases'] = array('report_url'); $params['name']['api.aliases'] = array('class_name'); + $params['option_group_id']['api.default'] = CRM_Core_DAO::getFieldValue( + 'CRM_Core_DAO_OptionGroup', 'report_template', 'id', 'name' + ); // $params['component']['api.required'] = TRUE; } diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index d190ec1b13..c6601e85f2 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -54,7 +54,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'report_url' => 'example/path', 'component' => 'CiviCase', )); - $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); + $this->assertAPISuccess($result); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $entityId = $result['id']; $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__); @@ -71,7 +71,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'id' => $entityId, 'component' => '', )); - $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); + $this->assertAPISuccess($result); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Report_Form_Examplez" @@ -86,7 +86,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'id' => $entityId, 'is_active' => 0, )); - $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); + $this->assertAPISuccess($result); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Report_Form_Examplez" @@ -100,7 +100,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'id' => $entityId, 'is_active' => 1, )); - $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); + $this->assertAPISuccess($result); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Report_Form_Examplez" @@ -112,7 +112,7 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { 'version' => $this->_apiversion, 'id' => $entityId, )); - $this->assertEquals(0, $result['is_error'], 'In line ' . __LINE__); + $this->assertAPISuccess($result); $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value WHERE name = "CRM_Report_Form_Examplez" -- 2.25.1