3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
28 require_once 'CiviTest/CiviUnitTestCase.php';
32 * Test APIv3 civicrm_report_instance_* functions
34 * @package CiviCRM_APIv3
35 * @subpackage API_Report
38 class api_v3_ReportTemplateTest
extends CiviUnitTestCase
{
39 protected $_apiversion = 3;
43 $this->useTransaction(TRUE);
46 public function testReportTemplate() {
47 $result = $this->callAPISuccess('ReportTemplate', 'create', array(
48 'label' => 'Example Form',
49 'description' => 'Longish description of the example form',
50 'class_name' => 'CRM_Report_Form_Examplez',
51 'report_url' => 'example/path',
52 'component' => 'CiviCase',
54 $this->assertAPISuccess($result);
55 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
56 $entityId = $result['id'];
57 $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__
);
58 $this->assertEquals(7, $result['values'][$entityId]['component_id'], 'In line ' . __LINE__
);
59 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
60 WHERE name = "CRM_Report_Form_Examplez"
61 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") ');
62 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
63 WHERE name = "CRM_Report_Form_Examplez"');
65 // change component to null
66 $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId,
69 $this->assertAPISuccess($result);
70 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
71 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
72 WHERE name = "CRM_Report_Form_Examplez"
73 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") ');
74 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
75 WHERE name = "CRM_Report_Form_Examplez"
76 AND component_id IS NULL');
79 $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId,
82 $this->assertAPISuccess($result);
83 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
84 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
85 WHERE name = "CRM_Report_Form_Examplez"
86 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") ');
87 $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value
88 WHERE name = "CRM_Report_Form_Examplez"');
91 $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId,
94 $this->assertAPISuccess($result);
95 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
96 $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value
97 WHERE name = "CRM_Report_Form_Examplez"
98 AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") ');
99 $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value
100 WHERE name = "CRM_Report_Form_Examplez"');
102 $result = $this->callAPISuccess('ReportTemplate', 'delete', array( 'id' => $entityId,
104 $this->assertAPISuccess($result);
105 $this->assertEquals(1, $result['count'], 'In line ' . __LINE__
);
106 $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value
107 WHERE name = "CRM_Report_Form_Examplez"
114 function testReportTemplateGetRowsContactSummary() {
115 $description = "Retrieve rows from a report template (optionally providing the instance_id)";
116 $result = $this->callAPIAndDocument('report_template', 'getrows', array(
117 'report_id' => 'contact/summary',
118 'options' => array('metadata' => array('labels', 'title'))
119 ), __FUNCTION__
, __FILE__
, $description, 'Getrows', 'getrows');
120 $this->assertEquals('Contact Name', $result['metadata']['labels']['civicrm_contact_sort_name']);
122 //the second part of this test has been commented out because it relied on the db being reset to
124 //wasn't able to get that to work consistently
125 // however, when the db is in the base state the tests do pass
126 // and because the test covers 'all' contacts we can't create our own & assume the others don't exist
128 $this->assertEquals(2, $result['count']);
129 $this->assertEquals('Default Organization', $result[0]['civicrm_contact_sort_name']);
130 $this->assertEquals('Second Domain', $result[1]['civicrm_contact_sort_name']);
131 $this->assertEquals('15 Main St', $result[1]['civicrm_address_street_address']);
136 * @dataProvider getReportTemplates
138 function testReportTemplateGetRowsAllReports($reportID) {
139 if(stristr($reportID, 'has existing issues')) {
140 $this->markTestIncomplete($reportID);
142 $result = $this->callAPISuccess('report_template', 'getrows', array(
143 'report_id' => $reportID,
148 * @dataProvider getReportTemplates
150 function testReportTemplateGetStatisticsAllReports($reportID) {
151 if(stristr($reportID, 'has existing issues')) {
152 $this->markTestIncomplete($reportID);
154 if(in_array($reportID , array('contribute/softcredit', 'contribute/bookkeeping'))) {
155 $this->markTestIncomplete($reportID . " has non enotices when calling statistics fn");
157 $description = "Get Statistics from a report (note there isn't much data to get in the test DB :-(";
158 $result = $this->callAPIAndDocument('report_template', 'getstatistics', array(
159 'report_id' => $reportID,
160 ), __FUNCTION__
, __FILE__
, $description, 'Getstatistics', 'getstatistics');
164 * Data provider function for getting all templates, note that the function needs to
165 * be static so cannot use $this->callAPISuccess
167 public static function getReportTemplates() {
168 $reportsToSkip = array(
169 'activity' => 'does not respect function signature on from clause',
170 'walklist' => 'Notice: Undefined index: type in CRM_Report_Form_Walklist_Walklist line 155.
171 (suspect the select function should be removed in favour of the parent (state province field)
172 also, type should be added to state province & others? & potentially getAddressColumns fn should be
173 used per other reports',
174 'contribute/repeat' => 'Reports with important functionality in postProcess are not callable via the api. For variable setting recommend beginPostProcessCommon, for temp table creation recommend From fn',
175 'contribute/topDonor' => 'construction of query in postProcess makes inaccessible ',
176 'contribute/sybunt' => 'e notice - (ui gives fatal error at civicrm/report/contribute/sybunt&reset=1&force=1
177 e-notice is on yid_valueContribute/Sybunt.php(214) because at the force url "yid_relative" not "yid_value" is defined',
178 'contribute/lybunt' => 'same as sybunt - fatals on force url & test identifies why',
179 'event/income' => 'I do no understand why but error is Call to undefined method CRM_Report_Form_Event_Income::from() in CRM/Report/Form.php on line 2120',
180 'contact/relationship' => '(see contribute/repeat), property declaration issue, Undefined property: CRM_Report_Form_Contact_Relationship::$relationType in /Contact/Relationship.php(486):',
181 'logging/contact/summary' => '(likely to be test related) probably logging off Undefined index: Form/Contact/LoggingSummary.php(231): PHP',
182 'logging/contact/detail' => '(likely to be test related) probably logging off DB Error: no such table',
183 'logging/contribute/summary' => '(likely to be test related) probably logging off DB Error: no such table',
184 'logging/contribute/detail' => '(likely to be test related) probably logging off DB Error: no such table',
185 'survey/detail' => '(likely to be test related) Undefined index: CiviCampaign civicrm CRM/Core/Component.php(196)',
186 'contribute/history' => 'Declaration of CRM_Report_Form_Contribute_History::buildRows() should be compatible with CRM_Report_Form::buildRows($sql, &$rows)',
189 $reports = civicrm_api3('report_template', 'get', array('return' => 'value', 'options' => array('limit' => 500)));
190 foreach ($reports['values'] as $report) {
191 if(empty($reportsToSkip[$report['value']])) {
192 $reportTemplates[] = array($report['value']);
195 $reportTemplates[] = array($report['value']. " has existing issues : " . $reportsToSkip[$report['value']]);
201 return $reportTemplates;