Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06a1bc01 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06a1bc01 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | require_once 'CiviTest/CiviUnitTestCase.php'; | |
29 | ||
30 | ||
31 | /** | |
32 | * Test APIv3 civicrm_report_instance_* functions | |
33 | * | |
34 | * @package CiviCRM_APIv3 | |
35 | * @subpackage API_Report | |
36 | */ | |
37 | ||
38 | class api_v3_ReportTemplateTest extends CiviUnitTestCase { | |
e2779f6e | 39 | protected $_apiversion = 3; |
b7c9bc4c | 40 | |
6a488035 | 41 | function setUp() { |
6a488035 TO |
42 | parent::setUp(); |
43 | } | |
44 | ||
45 | function tearDown() {} | |
46 | ||
47 | public function testReportTemplate() { | |
7fbb4198 | 48 | $result = $this->callAPISuccess('ReportTemplate', 'create', array( |
6a488035 TO |
49 | 'label' => 'Example Form', |
50 | 'description' => 'Longish description of the example form', | |
51 | 'class_name' => 'CRM_Report_Form_Examplez', | |
52 | 'report_url' => 'example/path', | |
53 | 'component' => 'CiviCase', | |
54 | )); | |
1cbea43e | 55 | $this->assertAPISuccess($result); |
6a488035 TO |
56 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
57 | $entityId = $result['id']; | |
58 | $this->assertTrue(is_numeric($entityId), 'In line ' . __LINE__); | |
59 | $this->assertEquals(7, $result['values'][$entityId]['component_id'], 'In line ' . __LINE__); | |
60 | $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value | |
61 | WHERE name = "CRM_Report_Form_Examplez" | |
0201b57f | 62 | AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") '); |
6a488035 TO |
63 | $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value |
64 | WHERE name = "CRM_Report_Form_Examplez"'); | |
65 | ||
66 | // change component to null | |
7fbb4198 | 67 | $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId, |
6a488035 TO |
68 | 'component' => '', |
69 | )); | |
1cbea43e | 70 | $this->assertAPISuccess($result); |
6a488035 TO |
71 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
72 | $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value | |
73 | WHERE name = "CRM_Report_Form_Examplez" | |
0201b57f | 74 | AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") '); |
6a488035 TO |
75 | $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value |
76 | WHERE name = "CRM_Report_Form_Examplez" | |
77 | AND component_id IS NULL'); | |
78 | ||
79 | // deactivate | |
7fbb4198 | 80 | $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId, |
6a488035 TO |
81 | 'is_active' => 0, |
82 | )); | |
1cbea43e | 83 | $this->assertAPISuccess($result); |
6a488035 TO |
84 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
85 | $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value | |
86 | WHERE name = "CRM_Report_Form_Examplez" | |
0201b57f | 87 | AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") '); |
6a488035 TO |
88 | $this->assertDBQuery(0, 'SELECT is_active FROM civicrm_option_value |
89 | WHERE name = "CRM_Report_Form_Examplez"'); | |
90 | ||
91 | // activate | |
7fbb4198 | 92 | $result = $this->callAPISuccess('ReportTemplate', 'create', array( 'id' => $entityId, |
6a488035 TO |
93 | 'is_active' => 1, |
94 | )); | |
1cbea43e | 95 | $this->assertAPISuccess($result); |
6a488035 TO |
96 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
97 | $this->assertDBQuery(1, 'SELECT count(*) FROM civicrm_option_value | |
98 | WHERE name = "CRM_Report_Form_Examplez" | |
0201b57f | 99 | AND option_group_id IN (SELECT id from civicrm_option_group WHERE name = "report_template") '); |
6a488035 TO |
100 | $this->assertDBQuery(1, 'SELECT is_active FROM civicrm_option_value |
101 | WHERE name = "CRM_Report_Form_Examplez"'); | |
102 | ||
7fbb4198 | 103 | $result = $this->callAPISuccess('ReportTemplate', 'delete', array( 'id' => $entityId, |
6a488035 | 104 | )); |
1cbea43e | 105 | $this->assertAPISuccess($result); |
6a488035 TO |
106 | $this->assertEquals(1, $result['count'], 'In line ' . __LINE__); |
107 | $this->assertDBQuery(0, 'SELECT count(*) FROM civicrm_option_value | |
108 | WHERE name = "CRM_Report_Form_Examplez" | |
109 | '); | |
110 | } | |
e2779f6e E |
111 | |
112 | /** | |
113 | * | |
114 | */ | |
115 | function testReportTemplateGetRowsContactSummary() { | |
fee15d2a E |
116 | $description = "Retrieve rows from a report template (optionally providing the instance_id)"; |
117 | $result = $this->callAPIAndDocument('report_template', 'getrows', array( | |
e2779f6e | 118 | 'report_id' => 'contact/summary', |
781d91c8 | 119 | 'options' => array('metadata' => array('labels', 'title')) |
fee15d2a | 120 | ), __FUNCTION__, __FILE__, $description, 'Getrows', 'getrows'); |
781d91c8 | 121 | $this->assertEquals('Contact Name', $result['metadata']['labels']['civicrm_contact_sort_name']); |
e2779f6e E |
122 | |
123 | //the second part of this test has been commented out because it relied on the db being reset to | |
124 | // it's base state | |
125 | //wasn't able to get that to work consistently | |
126 | // however, when the db is in the base state the tests do pass | |
127 | // and because the test covers 'all' contacts we can't create our own & assume the others don't exist | |
128 | /* | |
129 | $this->assertEquals(2, $result['count']); | |
130 | $this->assertEquals('Default Organization', $result[0]['civicrm_contact_sort_name']); | |
131 | $this->assertEquals('Second Domain', $result[1]['civicrm_contact_sort_name']); | |
132 | $this->assertEquals('15 Main St', $result[1]['civicrm_address_street_address']); | |
133 | */ | |
134 | } | |
135 | ||
136 | /** | |
137 | * @dataProvider getReportTemplates | |
138 | */ | |
139 | function testReportTemplateGetRowsAllReports($reportID) { | |
140 | if(stristr($reportID, 'has existing issues')) { | |
141 | $this->markTestIncomplete($reportID); | |
142 | } | |
143 | $result = $this->callAPISuccess('report_template', 'getrows', array( | |
144 | 'report_id' => $reportID, | |
145 | )); | |
146 | } | |
147 | ||
148 | /** | |
149 | * @dataProvider getReportTemplates | |
150 | */ | |
151 | function testReportTemplateGetStatisticsAllReports($reportID) { | |
152 | if(stristr($reportID, 'has existing issues')) { | |
153 | $this->markTestIncomplete($reportID); | |
154 | } | |
155 | if(in_array($reportID , array('contribute/softcredit', 'contribute/bookkeeping'))) { | |
156 | $this->markTestIncomplete($reportID . " has non enotices when calling statistics fn"); | |
157 | } | |
fee15d2a E |
158 | $description = "Get Statistics from a report (note there isn't much data to get in the test DB :-("; |
159 | $result = $this->callAPIAndDocument('report_template', 'getstatistics', array( | |
e2779f6e | 160 | 'report_id' => $reportID, |
fee15d2a | 161 | ), __FUNCTION__, __FILE__, $description, 'Getstatistics', 'getstatistics'); |
e2779f6e E |
162 | } |
163 | ||
164 | /** | |
165 | * Data provider function for getting all templates, note that the function needs to | |
166 | * be static so cannot use $this->callAPISuccess | |
167 | */ | |
168 | public static function getReportTemplates() { | |
169 | $reportsToSkip = array( | |
170 | 'activity' => 'does not respect function signature on from clause', | |
171 | 'walklist' => 'Notice: Undefined index: type in CRM_Report_Form_Walklist_Walklist line 155. | |
172 | (suspect the select function should be removed in favour of the parent (state province field) | |
173 | also, type should be added to state province & others? & potentially getAddressColumns fn should be | |
174 | used per other reports', | |
175 | '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', | |
176 | 'contribute/organizationSummary' => 'Failure in api call for report_template getrows: Only variables should be assigned by reference line 381', | |
177 | 'contribute/householdSummary' => '(see contribute/repeat) Undefined property: CRM_Report_Form_Contribute_HouseholdSummary::$householdContact LINE 260, property should be declared on class, for api accessibility should be set in beginPreProcess common', | |
178 | 'contribute/topDonor' => 'construction of query in postprocess makes inaccessible ', | |
179 | 'contribute/sybunt' => 'e notice - (ui gives fatal error at civicrm/report/contribute/sybunt&reset=1&force=1 | |
180 | e-notice is on yid_valueContribute/Sybunt.php(214) because at the force url "yid_relative" not "yid_value" is defined', | |
181 | 'contribute/lybunt' => 'same as sybunt - fatals on force url & test identifies why', | |
182 | 'event/income' => 'I do no understant why but error is Call to undefined method CRM_Report_Form_Event_Income::from() in CRM/Report/Form.php on line 2120', | |
183 | 'contact/relationship' => '(see contribute/repeat), property declaration issue, Undefined property: CRM_Report_Form_Contact_Relationship::$relationType in /Contact/Relationship.php(486):', | |
e2779f6e E |
184 | 'logging/contact/summary' => '(likely to be test releated) probably logging off Undefined index: Form/Contact/LoggingSummary.php(231): PHP', |
185 | 'logging/contact/detail' => '(likely to be test releated) probably logging off DB Error: no such table', | |
186 | 'logging/contribute/summary' => '(likely to be test releated) probably logging off DB Error: no such table', | |
187 | 'logging/contribute/detail' => '(likely to be test releated) probably logging off DB Error: no such table', | |
188 | 'survey/detail' => '(likely to be test releated) Undefined index: CiviCampaign civicrm CRM/Core/Component.php(196)', | |
189 | 'contribute/history' => 'Declaration of CRM_Report_Form_Contribute_History::buildRows() should be compatible with CRM_Report_Form::buildRows($sql, &$rows)', | |
190 | ); | |
191 | ||
192 | $reports = civicrm_api3('report_template', 'get', array('return' => 'value', 'options' => array('limit' => 500))); | |
193 | foreach ($reports['values'] as $report) { | |
194 | if(empty($reportsToSkip[$report['value']])) { | |
195 | $reportTemplates[] = array($report['value']); | |
196 | } | |
197 | else { | |
198 | $reportTemplates[] = array($report['value']. " has existing issues : " . $reportsToSkip[$report['value']]); | |
199 | } | |
200 | } | |
201 | ||
202 | ||
203 | ||
204 | return $reportTemplates; | |
205 | } | |
6a488035 | 206 | } |