From fee15d2a6faf76da57bce8d764294a20d76eb44a Mon Sep 17 00:00:00 2001 From: Eileen Date: Mon, 6 Jan 2014 18:46:39 +1300 Subject: [PATCH] CRM-13918 report_template api - add test generated examples ---------------------------------------- * CRM-13918: Add Report.getrows api http://issues.civicrm.org/jira/browse/CRM-13918 --- api/v3/examples/ReportTemplate/Getrows.php | 76 ++++++++++++++++++ .../examples/ReportTemplate/Getstatistics.php | 79 +++++++++++++++++++ tests/phpunit/api/v3/ReportTemplateTest.php | 10 ++- 3 files changed, 161 insertions(+), 4 deletions(-) create mode 100644 api/v3/examples/ReportTemplate/Getrows.php create mode 100644 api/v3/examples/ReportTemplate/Getstatistics.php diff --git a/api/v3/examples/ReportTemplate/Getrows.php b/api/v3/examples/ReportTemplate/Getrows.php new file mode 100644 index 0000000000..6b29966390 --- /dev/null +++ b/api/v3/examples/ReportTemplate/Getrows.php @@ -0,0 +1,76 @@ + 'contact/summary', +); + +try{ + $result = civicrm_api3('report_template', 'getrows', $params); +} +catch (CiviCRM_API3_Exception $e) { + // handle error here + $errorMessage = $e->getMessage(); + $errorCode = $e->getErrorCode(); + $errorData = $e->getExtraParams(); + return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); +} + +return $result; +} + +/** + * Function returns array of result expected from previous function + */ +function report_template_getrows_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 2, + 'values' => array( + '0' => array( + 'civicrm_contact_sort_name' => 'Default Organization', + 'civicrm_contact_id' => '1', + 'civicrm_address_street_address' => '', + 'civicrm_address_city' => '', + 'civicrm_country_name' => '', + ), + '1' => array( + 'civicrm_contact_sort_name' => 'Second Domain', + 'civicrm_contact_id' => '2', + 'civicrm_address_street_address' => '15 Main St', + 'civicrm_address_city' => 'Collinsville', + 'civicrm_country_name' => 'United States', + ), + ), +); + + return $expectedResult; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testReportTemplateGetRowsContactSummary and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ReportTemplateTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ diff --git a/api/v3/examples/ReportTemplate/Getstatistics.php b/api/v3/examples/ReportTemplate/Getstatistics.php new file mode 100644 index 0000000000..701779ea1d --- /dev/null +++ b/api/v3/examples/ReportTemplate/Getstatistics.php @@ -0,0 +1,79 @@ + 'member/contributionDetail', +); + +try{ + $result = civicrm_api3('report_template', 'getstatistics', $params); +} +catch (CiviCRM_API3_Exception $e) { + // handle error here + $errorMessage = $e->getMessage(); + $errorCode = $e->getErrorCode(); + $errorData = $e->getExtraParams(); + return array('error' => $errorMessage, 'error_code' => $errorCode, 'error_data' => $errorData); +} + +return $result; +} + +/** + * Function returns array of result expected from previous function + */ +function report_template_getstatistics_expectedresult(){ + + $expectedResult = array( + 'is_error' => 0, + 'version' => 3, + 'count' => 2, + 'values' => array( + 'counts' => array( + 'rowCount' => array( + 'title' => 'Row(s) Listed', + 'value' => 0, + ), + 'amount' => array( + 'title' => 'Total Amount', + 'value' => '', + 'type' => 2, + ), + 'avg' => array( + 'title' => 'Average', + 'value' => '', + 'type' => 2, + ), + ), + 'filters' => array(), + ), +); + + return $expectedResult; +} + + +/* +* This example has been generated from the API test suite. The test that created it is called +* +* testReportTemplateGetStatisticsAllReports and can be found in +* http://svn.civicrm.org/civicrm/trunk/tests/phpunit/CiviTest/api/v3/ReportTemplateTest.php +* +* You can see the outcome of the API tests at +* http://tests.dev.civicrm.org/trunk/results-api_v3 +* +* To Learn about the API read +* http://book.civicrm.org/developer/current/techniques/api/ +* +* and review the wiki at +* http://wiki.civicrm.org/confluence/display/CRMDOC/CiviCRM+Public+APIs +* +* Read more about testing here +* http://wiki.civicrm.org/confluence/display/CRM/Testing +* +* API Standards documentation: +* http://wiki.civicrm.org/confluence/display/CRM/API+Architecture+Standards +*/ diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index 0674387cff..cc25e90dce 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -114,9 +114,10 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { * */ function testReportTemplateGetRowsContactSummary() { - $result = $this->callAPISuccess('report_template', 'getrows', array( + $description = "Retrieve rows from a report template (optionally providing the instance_id)"; + $result = $this->callAPIAndDocument('report_template', 'getrows', array( 'report_id' => 'contact/summary', - )); + ), __FUNCTION__, __FILE__, $description, 'Getrows', 'getrows'); //the second part of this test has been commented out because it relied on the db being reset to // it's base state @@ -153,9 +154,10 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { if(in_array($reportID , array('contribute/softcredit', 'contribute/bookkeeping'))) { $this->markTestIncomplete($reportID . " has non enotices when calling statistics fn"); } - $result = $this->callAPISuccess('report_template', 'getstatistics', array( + $description = "Get Statistics from a report (note there isn't much data to get in the test DB :-("; + $result = $this->callAPIAndDocument('report_template', 'getstatistics', array( 'report_id' => $reportID, - )); + ), __FUNCTION__, __FILE__, $description, 'Getstatistics', 'getstatistics'); } /** -- 2.25.1