[REF] export code simplification
[civicrm-core.git] / tests / phpunit / CRM / Export / BAO / ExportTest.php
CommitLineData
ef51caa8 1<?php
ef51caa8 2
3/**
4 * Class CRM_Core_DAOTest
46312f7d 5 *
acb109b7 6 * @group headless
ef51caa8 7 */
8class CRM_Export_BAO_ExportTest extends CiviUnitTestCase {
9
12a36993 10 /**
11 * Contact IDs created for testing.
12 *
13 * @var array
14 */
c7224305 15 protected $contactIDs = [];
12a36993 16
17 /**
18 * Contribution IDs created for testing.
19 *
20 * @var array
21 */
c7224305 22 protected $contributionIDs = [];
23
24 /**
25 * Contribution IDs created for testing.
26 *
27 * @var array
28 */
29 protected $activityIDs = [];
12a36993 30
0a3b035f 31 /**
32 * Contribution IDs created for testing.
33 *
34 * @var array
35 */
36 protected $membershipIDs = [];
37
77544f6f
SV
38 /**
39 * Master Address ID created for testing.
40 *
41 * @var int
42 */
43 protected $masterAddressID;
44
a16a432a 45 protected $locationTypes = [];
46
68989e71 47 /**
48 * Processor generated in test.
49 *
50 * @var \CRM_Export_BAO_ExportProcessor
51 */
52 protected $processor;
53
54 /**
55 * Cleanup data.
56 *
57 * @throws \Exception
58 */
4d251131 59 public function tearDown() {
68989e71 60 $this->quickCleanUpFinancialEntities();
0a3b035f 61 $this->quickCleanup([
62 'civicrm_contact',
63 'civicrm_email',
64 'civicrm_address',
65 'civicrm_relationship',
66 'civicrm_membership',
67 'civicrm_case',
68 'civicrm_case_contact',
69 'civicrm_case_activity',
70 ]);
68989e71 71
a16a432a 72 if (!empty($this->locationTypes)) {
73 $this->callAPISuccess('LocationType', 'delete', ['id' => $this->locationTypes['Whare Kai']['id']]);
74 $this->callAPISuccess('LocationType', 'create', ['id' => $this->locationTypes['Main']['id'], 'name' => 'Main']);
75 }
68989e71 76 if ($this->processor && $this->processor->getTemporaryTable()) {
77 // delete the export temp table
78 CRM_Core_DAO::executeQuery("DROP TABLE IF EXISTS " . $this->processor->getTemporaryTable());
79 }
4d251131 80 parent::tearDown();
81 }
82
ef51caa8 83 /**
84 * Basic test to ensure the exportComponents function completes without error.
46312f7d 85 *
86 * @throws \CRM_Core_Exception
68989e71 87 * @throws \League\Csv\Exception
ef51caa8 88 */
12a36993 89 public function testExportComponentsNull() {
12a6fdef 90 $this->doExportTest([]);
ef51caa8 91 }
12a36993 92
93 /**
94 * Basic test to ensure the exportComponents function can export selected fields for contribution.
95 */
96 public function testExportComponentsContribution() {
97 $this->setUpContributionExportData();
46312f7d 98 $selectedFields = [
99 ['Individual', 'first_name'],
100 ['Individual', 'last_name'],
101 ['Contribution', 'receive_date'],
102 ['Contribution', 'contribution_source'],
103 ['Individual', 'street_address', 1],
104 ['Individual', 'city', 1],
105 ['Individual', 'country', 1],
106 ['Individual', 'email', 1],
107 ['Contribution', 'trxn_id'],
108 ];
994a070c 109
704e3e9a 110 list($tableName) = CRM_Export_BAO_Export::exportComponents(
12a36993 111 TRUE,
112 $this->contributionIDs,
46312f7d 113 [],
12a36993 114 'receive_date desc',
115 $selectedFields,
116 NULL,
117 CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
118 'civicrm_contribution.id IN ( ' . implode(',', $this->contributionIDs) . ')',
119 NULL,
120 FALSE,
121 FALSE,
46312f7d 122 [
12a36993 123 'exportOption' => CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
124 'suppress_csv_for_testing' => TRUE,
46312f7d 125 ]
12a36993 126 );
994a070c 127
128 // delete the export temp table and component table
129 $sql = "DROP TABLE IF EXISTS {$tableName}";
130 CRM_Core_DAO::executeQuery($sql);
12a36993 131 }
c7224305 132
8535cfc6 133 /**
134 * Basic test to ensure the exportComponents function can export with soft credits enabled.
135 *
136 * @throws \CRM_Core_Exception
137 * @throws \League\Csv\Exception
138 */
139 public function testExportComponentsContributionSoftCredits() {
140 $this->setUpContributionExportData();
141 $this->callAPISuccess('ContributionSoft', 'create', ['contact_id' => $this->contactIDs[1], 'contribution_id' => $this->contributionIDs[0], 'amount' => 5]);
142 $params = [
143 ['receive_date_low', '=', '20190101000000', 0, 0],
144 ['receive_date_high', '=', '20191231235959', 0, 0],
145 ['contribution_amount_low', '=', '1', 0, 0],
146 ['contribution_amount_high', '=', '10000000', 0, 0],
147 ['contribution_test', '=', '0', 0, 0],
148 ['contribution_or_softcredits', '=', 'both', 0, 0],
149 ];
150
151 $this->startCapturingOutput();
152 try {
153 CRM_Export_BAO_Export::exportComponents(
154 FALSE,
155 $this->contributionIDs,
156 $params,
157 'receive_date desc',
158 NULL,
159 NULL,
160 CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
161 'civicrm_contribution.id IN ( ' . implode(',', $this->contributionIDs) . ')',
162 NULL,
163 FALSE,
164 FALSE,
165 [
166 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT,
167 ]
168 );
169 }
170 catch (CRM_Core_Exception_PrematureExitException $e) {
171 }
172 $csv = $this->captureOutputToCSV();
173 $this->assertEquals(array_merge($this->getBasicHeaderDefinition(FALSE), $this->getContributeHeaderDefinition()), $csv->getHeader());
174 $rowNumber = 1;
175 $rows = $csv->getRecords();
176 foreach ($rows as $row) {
177 if ($rowNumber === 1) {
178 $this->assertEquals(95, $row['Net Amount']);
179 $this->assertEquals('', $row['Soft Credit Amount']);
180 }
181 if ($rowNumber === 2) {
182 $this->assertEquals(95, $row['Net Amount']);
183 $this->assertEquals(5, $row['Soft Credit Amount']);
184 $this->assertEquals('Anderson, Anthony', $row['Soft Credit For']);
185 $this->assertEquals($this->contributionIDs[0], $row['Soft Credit For Contribution ID']);
186 }
187 $rowNumber++;
188 }
189 $this->assertEquals(4, $rowNumber);
190 // Ideally we would use a randomised temp table name & use generic temp cleanup for cleanup - but
191 // for now just make sure we don't leave a mess.
192 CRM_Core_DAO::executeQuery('DROP TABLE IF EXISTS contribution_search_scredit_combined');
193
194 }
195
18711469 196 /**
197 * Basic test to ensure the exportComponents function can export selected fields for contribution.
198 */
199 public function testExportComponentsMembership() {
200 $this->setUpMembershipExportData();
201 list($tableName) = CRM_Export_BAO_Export::exportComponents(
202 TRUE,
203 $this->membershipIDs,
204 [],
205 NULL,
206 NULL,
207 NULL,
208 CRM_Export_Form_Select::MEMBER_EXPORT,
209 'civicrm_membership.id IN ( ' . implode(',', $this->membershipIDs) . ')',
210 NULL,
211 FALSE,
212 FALSE,
46312f7d 213 [
18711469 214 'exportOption' => CRM_Export_Form_Select::MEMBER_EXPORT,
215 'suppress_csv_for_testing' => TRUE,
46312f7d 216 ]
18711469 217 );
218
219 $dao = CRM_Core_DAO::executeQuery('SELECT * from ' . $tableName);
220 $dao->fetch();
221 $this->assertEquals('100.00', $dao->componentpaymentfield_total_amount);
222 $this->assertEquals('Completed', $dao->componentpaymentfield_contribution_status);
223 $this->assertEquals('Credit Card', $dao->componentpaymentfield_payment_instrument);
224 $this->assertEquals(1, $dao->N);
225
226 // delete the export temp table and component table
227 $sql = "DROP TABLE IF EXISTS {$tableName}";
228 CRM_Core_DAO::executeQuery($sql);
229 }
230
c7224305 231 /**
232 * Basic test to ensure the exportComponents function can export selected fields for contribution.
233 */
234 public function testExportComponentsActivity() {
235 $this->setUpActivityExportData();
46312f7d 236 $selectedFields = [
237 ['Individual', 'display_name'],
238 ['Individual', '5_a_b', 'display_name'],
239 ];
c7224305 240
241 list($tableName) = CRM_Export_BAO_Export::exportComponents(
242 FALSE,
243 $this->activityIDs,
46312f7d 244 [],
c7224305 245 '`activity_date_time` desc',
246 $selectedFields,
247 NULL,
248 CRM_Export_Form_Select::ACTIVITY_EXPORT,
249 'civicrm_activity.id IN ( ' . implode(',', $this->activityIDs) . ')',
250 NULL,
251 FALSE,
252 FALSE,
46312f7d 253 [
c7224305 254 'exportOption' => CRM_Export_Form_Select::ACTIVITY_EXPORT,
255 'suppress_csv_for_testing' => TRUE,
46312f7d 256 ]
c7224305 257 );
258
259 // delete the export temp table and component table
260 $sql = "DROP TABLE IF EXISTS {$tableName}";
261 CRM_Core_DAO::executeQuery($sql);
262 }
263
12a36993 264 /**
265 * Test the function that extracts the arrays used to structure the output.
266 *
267 * The keys in the output fields array should by matched by field aliases in the sql query (with
268 * exceptions of course - currently country is one - although maybe a future refactor can change that!).
269 *
270 * We are trying to move towards simpler processing in the per row iteration as that may be
271 * repeated 100,000 times and in general we should simply be able to match the query fields to
272 * our expected rows & do a little pseudoconstant mapping.
273 */
274 public function testGetExportStructureArrays() {
275 // This is how return properties are formatted internally within the function for passing to the BAO query.
46312f7d 276 $returnProperties = [
12a36993 277 'first_name' => 1,
278 'last_name' => 1,
279 'receive_date' => 1,
280 'contribution_source' => 1,
46312f7d 281 'location' => [
282 'Home' => [
12a36993 283 'street_address' => 1,
284 'city' => 1,
285 'country' => 1,
286 'email' => 1,
287 'im-1' => 1,
288 'im_provider' => 1,
289 'phone-1' => 1,
46312f7d 290 ],
291 ],
12a36993 292 'phone' => 1,
293 'trxn_id' => 1,
294 'contribution_id' => 1,
46312f7d 295 ];
efc76c0a 296
12a36993 297 $contactRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(
298 NULL,
299 NULL,
300 NULL,
301 NULL,
302 TRUE,
303 'name',
304 FALSE
305 );
306
46312f7d 307 $query = new CRM_Contact_BAO_Query([], $returnProperties, NULL,
12a36993 308 FALSE, FALSE, CRM_Contact_BAO_Query::MODE_CONTRIBUTE,
309 FALSE, TRUE, TRUE, NULL, 'AND'
310 );
311
312 list($select) = $query->query();
313 $pattern = '/as `?([^`,]*)/';
46312f7d 314 $queryFieldAliases = [];
12a36993 315 preg_match_all($pattern, $select, $queryFieldAliases, PREG_PATTERN_ORDER);
d41ab886 316 $processor = new CRM_Export_BAO_ExportProcessor(CRM_Contact_BAO_Query::MODE_CONTRIBUTE, NULL, 'AND');
adabfa40 317 $processor->setQueryFields($query->_fields);
12a36993 318
71464b73 319 list($outputFields) = CRM_Export_BAO_Export::getExportStructureArrays($returnProperties, $processor, $contactRelationshipTypes, '');
12a36993 320 foreach (array_keys($outputFields) as $fieldAlias) {
321 if ($fieldAlias == 'Home-country') {
322 $this->assertTrue(in_array($fieldAlias . '_id', $queryFieldAliases[1]), 'Country is subject to some funky translate so we make sure country id is present');
323 }
324 else {
325 $this->assertTrue(in_array($fieldAlias, $queryFieldAliases[1]), 'looking for field ' . $fieldAlias . ' in generaly the alias fields need to match the outputfields');
326 }
327 }
328
329 }
330
331 /**
332 * Set up some data for us to do testing on.
333 */
334 public function setUpContributionExportData() {
335 $this->setUpContactExportData();
46312f7d 336 $this->contributionIDs[] = $this->contributionCreate(['contact_id' => $this->contactIDs[0], 'trxn_id' => 'null', 'invoice_id' => 'null']);
337 $this->contributionIDs[] = $this->contributionCreate(['contact_id' => $this->contactIDs[1], 'trxn_id' => 'null', 'invoice_id' => 'null']);
12a36993 338 }
339
0a3b035f 340 /**
341 * Set up some data for us to do testing on.
342 */
343 public function setUpMembershipExportData() {
344 $this->setUpContactExportData();
18711469 345 // Create an extra so we don't get false passes due to 1
346 $this->contactMembershipCreate(['contact_id' => $this->contactIDs[0]]);
0a3b035f 347 $this->membershipIDs[] = $this->contactMembershipCreate(['contact_id' => $this->contactIDs[0]]);
18711469 348 $this->setUpContributionExportData();
46312f7d 349 $this->callAPISuccess('membership_payment', 'create', [
18711469 350 'contribution_id' => $this->contributionIDs[0],
351 'membership_id' => $this->membershipIDs[0],
46312f7d 352 ]);
18711469 353 $this->callAPISuccess('LineItem', 'get', [
30eab4c1 354 'entity_table' => 'civicrm_membership',
18711469 355 'membership_id' => $this->membershipIDs[0],
356 'api.LineItem.create' => ['contribution_id' => $this->contributionIDs[0]],
357 ]);
0a3b035f 358 }
359
360 /**
361 * Set up data to test case export.
362 */
363 public function setupCaseExportData() {
364 $contactID1 = $this->individualCreate();
46312f7d 365 $contactID2 = $this->individualCreate([], 1);
0a3b035f 366
46312f7d 367 $case = $this->callAPISuccess('case', 'create', [
0a3b035f 368 'case_type_id' => 1,
369 'subject' => 'blah',
370 'contact_id' => $contactID1,
46312f7d 371 ]);
0a3b035f 372 $this->callAPISuccess('CaseContact', 'create', [
373 'case_id' => $case['id'],
374 'contact_id' => $contactID2,
375 ]);
376 }
377
c7224305 378 /**
379 * Set up some data for us to do testing on.
380 */
381 public function setUpActivityExportData() {
382 $this->setUpContactExportData();
46312f7d 383 $this->activityIDs[] = $this->activityCreate(['contact_id' => $this->contactIDs[0]])['id'];
c7224305 384 }
385
12a36993 386 /**
387 * Set up some data for us to do testing on.
388 */
389 public function setUpContactExportData() {
bab4f15e 390 $this->contactIDs[] = $contactA = $this->individualCreate(['gender_id' => 'Female']);
4d251131 391 // Create address for contact A.
46312f7d 392 $params = [
994a070c 393 'contact_id' => $contactA,
394 'location_type_id' => 'Home',
395 'street_address' => 'Ambachtstraat 23',
396 'postal_code' => '6971 BN',
397 'country_id' => '1152',
398 'city' => 'Brummen',
399 'is_primary' => 1,
46312f7d 400 ];
994a070c 401 $result = $this->callAPISuccess('address', 'create', $params);
402 $addressId = $result['id'];
403
46312f7d 404 $this->callAPISuccess('email', 'create', [
4d251131 405 'id' => $this->callAPISuccessGetValue('Email', ['contact_id' => $params['contact_id'], 'return' => 'id']),
406 'location_type_id' => 'Home',
407 'email' => 'home@example.com',
408 'is_primary' => 1,
46312f7d 409 ]);
410 $this->callAPISuccess('email', 'create', ['contact_id' => $params['contact_id'], 'location_type_id' => 'Work', 'email' => 'work@example.com', 'is_primary' => 0]);
4d251131 411
412 $params['is_primary'] = 0;
413 $params['location_type_id'] = 'Work';
414 $this->callAPISuccess('address', 'create', $params);
415 $this->contactIDs[] = $contactB = $this->individualCreate();
416
46312f7d 417 $this->callAPISuccess('address', 'create', [
994a070c 418 'contact_id' => $contactB,
419 'location_type_id' => "Home",
420 'master_id' => $addressId,
46312f7d 421 ]);
77544f6f 422 $this->masterAddressID = $addressId;
994a070c 423
4d251131 424 }
425
426 /**
427 * Test variants of primary address exporting.
428 *
429 * @param int $isPrimaryOnly
430 *
ebebd629 431 * @dataProvider getBooleanDataProvider
432 * @throws \CRM_Core_Exception
4d251131 433 */
434 public function testExportPrimaryAddress($isPrimaryOnly) {
435 \Civi::settings()->set('searchPrimaryDetailsOnly', $isPrimaryOnly);
436 $this->setUpContactExportData();
437
438 $selectedFields = [['Individual', 'email', ' '], ['Individual', 'email', '1'], ['Individual', 'email', '2']];
439 list($tableName) = CRM_Export_BAO_Export::exportComponents(
440 TRUE,
441 [],
442 [['email', 'LIKE', 'c', 0, 1]],
443 NULL,
444 $selectedFields,
445 NULL,
446 CRM_Export_Form_Select::CONTACT_EXPORT,
447 "contact_a.id IN ({$this->contactIDs[0]}, {$this->contactIDs[1]})",
448 NULL,
449 FALSE,
450 FALSE,
46312f7d 451 [
4d251131 452 'suppress_csv_for_testing' => TRUE,
46312f7d 453 ]
4d251131 454 );
455
456 $dao = CRM_Core_DAO::executeQuery('SELECT * from ' . $tableName);
457 $dao->fetch();
458 $this->assertEquals('home@example.com', $dao->email);
459 $this->assertEquals('work@example.com', $dao->work_email);
460 $this->assertEquals('home@example.com', $dao->home_email);
461 $this->assertEquals(2, $dao->N);
462 \Civi::settings()->set('searchPrimaryDetailsOnly', FALSE);
463 }
464
bab4f15e 465 /**
466 * Test that when exporting a pseudoField it is reset for NULL entries.
467 *
468 * ie. we have a contact WITH a gender & one without - make sure the latter one
469 * does NOT retain the gender of the former.
46312f7d 470 *
471 * @throws \CRM_Core_Exception
bab4f15e 472 */
473 public function testExportPseudoField() {
474 $this->setUpContactExportData();
475 $selectedFields = [['Individual', 'gender_id']];
f797aeb8 476 list($tableName, $sqlColumns) = $this->doExport($selectedFields, $this->contactIDs);
bab4f15e 477 $this->assertEquals('Female,', CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT(gender_id) FROM {$tableName}"));
478 }
479
480 /**
481 * Test that when exporting a pseudoField it is reset for NULL entries.
482 *
483 * This is specific to the example in CRM-14398
484 */
485 public function testExportPseudoFieldCampaign() {
486 $this->setUpContributionExportData();
487 $campaign = $this->callAPISuccess('Campaign', 'create', ['title' => 'Big campaign']);
488 $this->callAPISuccess('Contribution', 'create', ['campaign_id' => 'Big_campaign', 'id' => $this->contributionIDs[0]]);
489 $selectedFields = [['Individual', 'gender_id'], ['Contribution', 'contribution_campaign_title']];
490 list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
491 TRUE,
492 $this->contactIDs[1],
46312f7d 493 [],
bab4f15e 494 NULL,
495 $selectedFields,
496 NULL,
497 CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
498 "contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
499 NULL,
500 FALSE,
501 FALSE,
46312f7d 502 [
bab4f15e 503 'suppress_csv_for_testing' => TRUE,
46312f7d 504 ]
bab4f15e 505 );
506 $this->assertEquals('Big campaign,', CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT(contribution_campaign_title) FROM {$tableName}"));
507 }
508
ce12a9e0 509 /**
510 * Test exporting relationships.
511 */
512 public function testExportRelationships() {
cedeaa5c 513 $organization1 = $this->organizationCreate(['organization_name' => 'Org 1', 'legal_name' => 'pretty legal', 'contact_source' => 'friend who took a law paper once']);
ce12a9e0 514 $organization2 = $this->organizationCreate(['organization_name' => 'Org 2', 'legal_name' => 'well dodgey']);
515 $contact1 = $this->individualCreate(['employer_id' => $organization1, 'first_name' => 'one']);
516 $contact2 = $this->individualCreate(['employer_id' => $organization2, 'first_name' => 'one']);
517 $employerRelationshipTypeID = $this->callAPISuccessGetValue('RelationshipType', ['return' => 'id', 'label_a_b' => 'Employee of']);
518 $selectedFields = [
519 ['Individual', 'first_name', ''],
520 ['Individual', $employerRelationshipTypeID . '_a_b', 'organization_name', ''],
521 ['Individual', $employerRelationshipTypeID . '_a_b', 'legal_name', ''],
cedeaa5c 522 ['Individual', $employerRelationshipTypeID . '_a_b', 'contact_source', ''],
ce12a9e0 523 ];
524 list($tableName, $sqlColumns, $headerRows) = CRM_Export_BAO_Export::exportComponents(
525 FALSE,
526 [$contact1, $contact2],
527 [],
528 NULL,
529 $selectedFields,
530 NULL,
531 CRM_Export_Form_Select::CONTACT_EXPORT,
532 "contact_a.id IN ( $contact1, $contact2 )",
533 NULL,
534 FALSE,
535 FALSE,
536 [
ce12a9e0 537 'suppress_csv_for_testing' => TRUE,
538 ]
539 );
540
541 $dao = CRM_Core_DAO::executeQuery("SELECT * FROM {$tableName}");
542 $dao->fetch();
543 $this->assertEquals('one', $dao->first_name);
544 $this->assertEquals('Org 1', $dao->{$employerRelationshipTypeID . '_a_b_organization_name'});
545 $this->assertEquals('pretty legal', $dao->{$employerRelationshipTypeID . '_a_b_legal_name'});
cedeaa5c 546 $this->assertEquals('friend who took a law paper once', $dao->{$employerRelationshipTypeID . '_a_b_contact_source'});
ce12a9e0 547
548 $dao->fetch();
549 $this->assertEquals('Org 2', $dao->{$employerRelationshipTypeID . '_a_b_organization_name'});
550 $this->assertEquals('well dodgey', $dao->{$employerRelationshipTypeID . '_a_b_legal_name'});
5359d42b 551
552 $this->assertEquals([
553 0 => 'First Name',
554 1 => 'Employee of-Organization Name',
555 2 => 'Employee of-Legal Name',
556 3 => 'Employee of-Contact Source',
557 ], $headerRows);
ce12a9e0 558 }
559
b0eb1d74 560 /**
561 * Test exporting relationships.
562 *
563 * This is to ensure that CRM-13995 remains fixed.
ebebd629 564 *
565 * @dataProvider getBooleanDataProvider
566 *
567 * @param bool $includeHouseHold
568 *
569 * @throws \CRM_Core_Exception
b0eb1d74 570 */
ebebd629 571 public function testExportRelationshipsMergeToHousehold($includeHouseHold) {
2593f7dc 572 list($householdID, $houseHoldTypeID) = $this->setUpHousehold();
b0eb1d74 573
ebebd629 574 if ($includeHouseHold) {
575 $this->contactIDs[] = $householdID;
576 }
b0eb1d74 577 $selectedFields = [
578 ['Individual', $houseHoldTypeID . '_a_b', 'state_province', ''],
579 ['Individual', $houseHoldTypeID . '_a_b', 'city', ''],
580 ['Individual', 'city', ''],
581 ['Individual', 'state_province', ''],
cedeaa5c 582 ['Individual', 'contact_source', ''],
b0eb1d74 583 ];
b7db6051 584 list($tableName, $sqlColumns, $headerRows) = CRM_Export_BAO_Export::exportComponents(
b0eb1d74 585 FALSE,
586 $this->contactIDs,
587 [],
588 NULL,
589 $selectedFields,
590 NULL,
591 CRM_Export_Form_Select::CONTACT_EXPORT,
592 "contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
593 NULL,
594 FALSE,
595 TRUE,
596 [
b0eb1d74 597 'suppress_csv_for_testing' => TRUE,
598 ]
599 );
600 $dao = CRM_Core_DAO::executeQuery("SELECT * FROM {$tableName}");
601 while ($dao->fetch()) {
ebebd629 602 $this->assertEquals(1, $dao->N);
81649c48 603 $this->assertEquals('Portland', $dao->city);
604 $this->assertEquals('ME', $dao->state_province);
605 $this->assertEquals($householdID, $dao->civicrm_primary_id);
606 $this->assertEquals($householdID, $dao->civicrm_primary_id);
cedeaa5c 607 $this->assertEquals('household sauce', $dao->contact_source);
b0eb1d74 608 }
609
b7db6051 610 $this->assertEquals([
611 0 => 'City',
612 1 => 'State',
cedeaa5c 613 2 => 'Contact Source',
614 3 => 'Household ID',
b7db6051 615 ], $headerRows);
616 $this->assertEquals(
617 [
618 'city' => 'city varchar(64)',
619 'state_province' => 'state_province varchar(64)',
620 'civicrm_primary_id' => 'civicrm_primary_id varchar(16)',
cedeaa5c 621 'contact_source' => 'contact_source varchar(255)',
b7db6051 622 ], $sqlColumns);
b0eb1d74 623 }
624
2593f7dc 625 /**
626 * Test exporting relationships.
627 */
628 public function testExportRelationshipsMergeToHouseholdAllFields() {
2593f7dc 629 list($householdID) = $this->setUpHousehold();
630 list($tableName) = CRM_Export_BAO_Export::exportComponents(
631 FALSE,
632 $this->contactIDs,
633 [],
634 NULL,
635 NULL,
636 NULL,
637 CRM_Export_Form_Select::CONTACT_EXPORT,
638 "contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
639 NULL,
640 FALSE,
641 TRUE,
642 [
2593f7dc 643 'suppress_csv_for_testing' => TRUE,
644 ]
645 );
646 $dao = CRM_Core_DAO::executeQuery("SELECT * FROM {$tableName}");
647 while ($dao->fetch()) {
136f69a8 648 $this->assertEquals('Unit Test household', $dao->display_name);
2593f7dc 649 $this->assertEquals('Portland', $dao->city);
650 $this->assertEquals('ME', $dao->state_province);
651 $this->assertEquals($householdID, $dao->civicrm_primary_id);
652 $this->assertEquals($householdID, $dao->civicrm_primary_id);
136f69a8 653 $this->assertEquals('Unit Test household', $dao->addressee);
654 $this->assertEquals(1, $dao->N);
2593f7dc 655 }
656 }
657
3663269c 658 /**
659 * Test master_address_id field.
660 */
661 public function testExportCustomData() {
662 $this->setUpContactExportData();
663
664 $customData = $this->entityCustomGroupWithSingleFieldCreate(__FUNCTION__, 'ContactTest.php');
665
666 $this->callAPISuccess('Contact', 'create', [
667 'id' => $this->contactIDs[1],
668 'custom_' . $customData['custom_field_id'] => 'BlahdeBlah',
669 'api.Address.create' => ['location_type_id' => 'Billing', 'city' => 'Waipu'],
670 ]);
671 $selectedFields = [
672 ['Individual', 'city', CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'location_type_id', 'Billing')],
673 ['Individual', 'custom_1'],
674 ];
675
676 list($tableName, $sqlColumns) = $this->doExport($selectedFields, $this->contactIDs[1]);
677 $this->assertEquals([
5ebd7d09 678 'billing_city' => 'billing_city varchar(64)',
3663269c 679 'custom_1' => 'custom_1 varchar(255)',
680 ], $sqlColumns);
681
682 $dao = CRM_Core_DAO::executeQuery('SELECT * FROM ' . $tableName);
683 while ($dao->fetch()) {
684 $this->assertEquals('BlahdeBlah', $dao->custom_1);
685 $this->assertEquals('Waipu', $dao->billing_city);
686 }
687 }
688
689 /**
690 * Attempt to do a fairly full export of location data.
691 */
692 public function testExportIMData() {
693 // Use default providers.
694 $providers = ['AIM', 'GTalk', 'Jabber', 'MSN', 'Skype', 'Yahoo'];
a16a432a 695 // Main sure labels are not all anglo chars.
696 $this->diversifyLocationTypes();
697
698 $locationTypes = ['Billing' => 'Billing', 'Home' => 'Home', 'Main' => 'Méin', 'Other' => 'Other', 'Whare Kai' => 'Whare Kai'];
3663269c 699
700 $this->contactIDs[] = $this->individualCreate();
701 $this->contactIDs[] = $this->individualCreate();
702 $this->contactIDs[] = $this->householdCreate();
703 $this->contactIDs[] = $this->organizationCreate();
704 foreach ($this->contactIDs as $contactID) {
705 foreach ($providers as $provider) {
a16a432a 706 foreach ($locationTypes as $locationName => $locationLabel) {
3663269c 707 $this->callAPISuccess('IM', 'create', [
708 'contact_id' => $contactID,
a16a432a 709 'location_type_id' => $locationName,
3663269c 710 'provider_id' => $provider,
a16a432a 711 'name' => $locationName . $provider . $contactID,
3663269c 712 ]);
713 }
714 }
715 }
716
717 $relationships = [
718 $this->contactIDs[1] => ['label' => 'Spouse of'],
719 $this->contactIDs[2] => ['label' => 'Household Member of'],
39b959db 720 $this->contactIDs[3] => ['label' => 'Employee of'],
3663269c 721 ];
722
723 foreach ($relationships as $contactID => $relationshipType) {
724 $relationshipTypeID = $this->callAPISuccess('RelationshipType', 'getvalue', ['label_a_b' => $relationshipType['label'], 'return' => 'id']);
725 $result = $this->callAPISuccess('Relationship', 'create', [
726 'contact_id_a' => $this->contactIDs[0],
727 'relationship_type_id' => $relationshipTypeID,
39b959db 728 'contact_id_b' => $contactID,
3663269c 729 ]);
730 $relationships[$contactID]['id'] = $result['id'];
731 $relationships[$contactID]['relationship_type_id'] = $relationshipTypeID;
732 }
733
734 $fields = [['Individual', 'contact_id']];
735 // ' ' denotes primary location type.
a16a432a 736 foreach (array_keys(array_merge($locationTypes, [' ' => ['Primary']])) as $locationType) {
3663269c 737 $fields[] = [
738 'Individual',
739 'im_provider',
740 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_IM', 'location_type_id', $locationType),
741 ];
742 foreach ($relationships as $contactID => $relationship) {
743 $fields[] = [
744 'Individual',
745 $relationship['relationship_type_id'] . '_a_b',
746 'im_provider',
747 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_IM', 'location_type_id', $locationType),
748 ];
749 }
750 foreach ($providers as $provider) {
751 $fields[] = [
752 'Individual',
753 'im',
754 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_IM', 'location_type_id', $locationType),
755 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_IM', 'provider_id', $provider),
756 ];
757 foreach ($relationships as $contactID => $relationship) {
758 $fields[] = [
759 'Individual',
760 $relationship['relationship_type_id'] . '_a_b',
761 'im',
762 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_IM', 'location_type_id', $locationType),
763 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_IM', 'provider_id', $provider),
764 ];
765 }
766 }
767 }
704e3e9a 768 list($tableName, $sqlColumns) = $this->doExport($fields, $this->contactIDs[0]);
3663269c 769
770 $dao = CRM_Core_DAO::executeQuery('SELECT * FROM ' . $tableName);
771 while ($dao->fetch()) {
772 $id = $dao->contact_id;
773 $this->assertEquals('AIM', $dao->billing_im_provider);
774 $this->assertEquals('BillingJabber' . $id, $dao->billing_im_screen_name_jabber);
775 $this->assertEquals('BillingSkype' . $id, $dao->billing_im_screen_name_skype);
776 foreach ($relationships as $relatedContactID => $relationship) {
777 $relationshipString = $field = $relationship['relationship_type_id'] . '_a_b';
778 $field = $relationshipString . '_billing_im_screen_name_yahoo';
779 $this->assertEquals('BillingYahoo' . $relatedContactID, $dao->$field);
780 // @todo efforts to output 'im_provider' for related contacts seem to be giving a blank field.
781 }
782 }
783
3663269c 784 $this->assertEquals([
785 'billing_im_provider' => 'billing_im_provider text',
5ebd7d09 786 'billing_im_screen_name' => 'billing_im_screen_name varchar(64)',
787 'billing_im_screen_name_jabber' => 'billing_im_screen_name_jabber varchar(64)',
788 'billing_im_screen_name_skype' => 'billing_im_screen_name_skype varchar(64)',
789 'billing_im_screen_name_yahoo' => 'billing_im_screen_name_yahoo varchar(64)',
3663269c 790 'home_im_provider' => 'home_im_provider text',
5ebd7d09 791 'home_im_screen_name' => 'home_im_screen_name varchar(64)',
792 'home_im_screen_name_jabber' => 'home_im_screen_name_jabber varchar(64)',
793 'home_im_screen_name_skype' => 'home_im_screen_name_skype varchar(64)',
794 'home_im_screen_name_yahoo' => 'home_im_screen_name_yahoo varchar(64)',
3663269c 795 'main_im_provider' => 'main_im_provider text',
5ebd7d09 796 'main_im_screen_name' => 'main_im_screen_name varchar(64)',
797 'main_im_screen_name_jabber' => 'main_im_screen_name_jabber varchar(64)',
798 'main_im_screen_name_skype' => 'main_im_screen_name_skype varchar(64)',
799 'main_im_screen_name_yahoo' => 'main_im_screen_name_yahoo varchar(64)',
3663269c 800 'other_im_provider' => 'other_im_provider text',
5ebd7d09 801 'other_im_screen_name' => 'other_im_screen_name varchar(64)',
802 'other_im_screen_name_jabber' => 'other_im_screen_name_jabber varchar(64)',
803 'other_im_screen_name_skype' => 'other_im_screen_name_skype varchar(64)',
804 'other_im_screen_name_yahoo' => 'other_im_screen_name_yahoo varchar(64)',
3663269c 805 'im_provider' => 'im_provider text',
5ebd7d09 806 'im_screen_name' => 'im_screen_name varchar(64)',
3663269c 807 'contact_id' => 'contact_id varchar(255)',
808 '2_a_b_im_provider' => '2_a_b_im_provider text',
5ebd7d09 809 '2_a_b_billing_im_screen_name' => '2_a_b_billing_im_screen_name varchar(64)',
810 '2_a_b_billing_im_screen_name_jabber' => '2_a_b_billing_im_screen_name_jabber varchar(64)',
811 '2_a_b_billing_im_screen_name_skype' => '2_a_b_billing_im_screen_name_skype varchar(64)',
812 '2_a_b_billing_im_screen_name_yahoo' => '2_a_b_billing_im_screen_name_yahoo varchar(64)',
813 '2_a_b_home_im_screen_name' => '2_a_b_home_im_screen_name varchar(64)',
814 '2_a_b_home_im_screen_name_jabber' => '2_a_b_home_im_screen_name_jabber varchar(64)',
815 '2_a_b_home_im_screen_name_skype' => '2_a_b_home_im_screen_name_skype varchar(64)',
816 '2_a_b_home_im_screen_name_yahoo' => '2_a_b_home_im_screen_name_yahoo varchar(64)',
817 '2_a_b_main_im_screen_name' => '2_a_b_main_im_screen_name varchar(64)',
818 '2_a_b_main_im_screen_name_jabber' => '2_a_b_main_im_screen_name_jabber varchar(64)',
819 '2_a_b_main_im_screen_name_skype' => '2_a_b_main_im_screen_name_skype varchar(64)',
820 '2_a_b_main_im_screen_name_yahoo' => '2_a_b_main_im_screen_name_yahoo varchar(64)',
821 '2_a_b_other_im_screen_name' => '2_a_b_other_im_screen_name varchar(64)',
822 '2_a_b_other_im_screen_name_jabber' => '2_a_b_other_im_screen_name_jabber varchar(64)',
823 '2_a_b_other_im_screen_name_skype' => '2_a_b_other_im_screen_name_skype varchar(64)',
824 '2_a_b_other_im_screen_name_yahoo' => '2_a_b_other_im_screen_name_yahoo varchar(64)',
825 '2_a_b_im_screen_name' => '2_a_b_im_screen_name varchar(64)',
3663269c 826 '8_a_b_im_provider' => '8_a_b_im_provider text',
5ebd7d09 827 '8_a_b_billing_im_screen_name' => '8_a_b_billing_im_screen_name varchar(64)',
828 '8_a_b_billing_im_screen_name_jabber' => '8_a_b_billing_im_screen_name_jabber varchar(64)',
829 '8_a_b_billing_im_screen_name_skype' => '8_a_b_billing_im_screen_name_skype varchar(64)',
830 '8_a_b_billing_im_screen_name_yahoo' => '8_a_b_billing_im_screen_name_yahoo varchar(64)',
831 '8_a_b_home_im_screen_name' => '8_a_b_home_im_screen_name varchar(64)',
832 '8_a_b_home_im_screen_name_jabber' => '8_a_b_home_im_screen_name_jabber varchar(64)',
833 '8_a_b_home_im_screen_name_skype' => '8_a_b_home_im_screen_name_skype varchar(64)',
834 '8_a_b_home_im_screen_name_yahoo' => '8_a_b_home_im_screen_name_yahoo varchar(64)',
835 '8_a_b_main_im_screen_name' => '8_a_b_main_im_screen_name varchar(64)',
836 '8_a_b_main_im_screen_name_jabber' => '8_a_b_main_im_screen_name_jabber varchar(64)',
837 '8_a_b_main_im_screen_name_skype' => '8_a_b_main_im_screen_name_skype varchar(64)',
838 '8_a_b_main_im_screen_name_yahoo' => '8_a_b_main_im_screen_name_yahoo varchar(64)',
839 '8_a_b_other_im_screen_name' => '8_a_b_other_im_screen_name varchar(64)',
840 '8_a_b_other_im_screen_name_jabber' => '8_a_b_other_im_screen_name_jabber varchar(64)',
841 '8_a_b_other_im_screen_name_skype' => '8_a_b_other_im_screen_name_skype varchar(64)',
842 '8_a_b_other_im_screen_name_yahoo' => '8_a_b_other_im_screen_name_yahoo varchar(64)',
843 '8_a_b_im_screen_name' => '8_a_b_im_screen_name varchar(64)',
3663269c 844 '5_a_b_im_provider' => '5_a_b_im_provider text',
5ebd7d09 845 '5_a_b_billing_im_screen_name' => '5_a_b_billing_im_screen_name varchar(64)',
846 '5_a_b_billing_im_screen_name_jabber' => '5_a_b_billing_im_screen_name_jabber varchar(64)',
847 '5_a_b_billing_im_screen_name_skype' => '5_a_b_billing_im_screen_name_skype varchar(64)',
848 '5_a_b_billing_im_screen_name_yahoo' => '5_a_b_billing_im_screen_name_yahoo varchar(64)',
849 '5_a_b_home_im_screen_name' => '5_a_b_home_im_screen_name varchar(64)',
850 '5_a_b_home_im_screen_name_jabber' => '5_a_b_home_im_screen_name_jabber varchar(64)',
851 '5_a_b_home_im_screen_name_skype' => '5_a_b_home_im_screen_name_skype varchar(64)',
852 '5_a_b_home_im_screen_name_yahoo' => '5_a_b_home_im_screen_name_yahoo varchar(64)',
853 '5_a_b_main_im_screen_name' => '5_a_b_main_im_screen_name varchar(64)',
854 '5_a_b_main_im_screen_name_jabber' => '5_a_b_main_im_screen_name_jabber varchar(64)',
855 '5_a_b_main_im_screen_name_skype' => '5_a_b_main_im_screen_name_skype varchar(64)',
856 '5_a_b_main_im_screen_name_yahoo' => '5_a_b_main_im_screen_name_yahoo varchar(64)',
857 '5_a_b_other_im_screen_name' => '5_a_b_other_im_screen_name varchar(64)',
858 '5_a_b_other_im_screen_name_jabber' => '5_a_b_other_im_screen_name_jabber varchar(64)',
859 '5_a_b_other_im_screen_name_skype' => '5_a_b_other_im_screen_name_skype varchar(64)',
860 '5_a_b_other_im_screen_name_yahoo' => '5_a_b_other_im_screen_name_yahoo varchar(64)',
861 '5_a_b_im_screen_name' => '5_a_b_im_screen_name varchar(64)',
a16a432a 862 'whare_kai_im_provider' => 'whare_kai_im_provider text',
5ebd7d09 863 'whare_kai_im_screen_name' => 'whare_kai_im_screen_name varchar(64)',
864 'whare_kai_im_screen_name_jabber' => 'whare_kai_im_screen_name_jabber varchar(64)',
865 'whare_kai_im_screen_name_skype' => 'whare_kai_im_screen_name_skype varchar(64)',
866 'whare_kai_im_screen_name_yahoo' => 'whare_kai_im_screen_name_yahoo varchar(64)',
867 '2_a_b_whare_kai_im_screen_name' => '2_a_b_whare_kai_im_screen_name varchar(64)',
868 '2_a_b_whare_kai_im_screen_name_jabber' => '2_a_b_whare_kai_im_screen_name_jabber varchar(64)',
869 '2_a_b_whare_kai_im_screen_name_skype' => '2_a_b_whare_kai_im_screen_name_skype varchar(64)',
870 '2_a_b_whare_kai_im_screen_name_yahoo' => '2_a_b_whare_kai_im_screen_name_yahoo varchar(64)',
871 '8_a_b_whare_kai_im_screen_name' => '8_a_b_whare_kai_im_screen_name varchar(64)',
872 '8_a_b_whare_kai_im_screen_name_jabber' => '8_a_b_whare_kai_im_screen_name_jabber varchar(64)',
873 '8_a_b_whare_kai_im_screen_name_skype' => '8_a_b_whare_kai_im_screen_name_skype varchar(64)',
874 '8_a_b_whare_kai_im_screen_name_yahoo' => '8_a_b_whare_kai_im_screen_name_yahoo varchar(64)',
875 '5_a_b_whare_kai_im_screen_name' => '5_a_b_whare_kai_im_screen_name varchar(64)',
876 '5_a_b_whare_kai_im_screen_name_jabber' => '5_a_b_whare_kai_im_screen_name_jabber varchar(64)',
877 '5_a_b_whare_kai_im_screen_name_skype' => '5_a_b_whare_kai_im_screen_name_skype varchar(64)',
878 '5_a_b_whare_kai_im_screen_name_yahoo' => '5_a_b_whare_kai_im_screen_name_yahoo varchar(64)',
3663269c 879 ], $sqlColumns);
880
881 }
882
f797aeb8 883 /**
884 * Test phone data export.
885 *
886 * Less over the top complete than the im test.
887 */
888 public function testExportPhoneData() {
889 $this->contactIDs[] = $this->individualCreate();
890 $this->contactIDs[] = $this->individualCreate();
891 $locationTypes = ['Billing' => 'Billing', 'Home' => 'Home'];
892 $phoneTypes = ['Mobile', 'Phone'];
893 foreach ($this->contactIDs as $contactID) {
894 $this->callAPISuccess('Phone', 'create', [
895 'contact_id' => $contactID,
896 'location_type_id' => 'Billing',
897 'phone_type_id' => 'Mobile',
001a515b 898 'phone' => 'Billing' . 'Mobile' . $contactID,
f797aeb8 899 'is_primary' => 1,
900 ]);
901 $this->callAPISuccess('Phone', 'create', [
902 'contact_id' => $contactID,
903 'location_type_id' => 'Home',
904 'phone_type_id' => 'Phone',
001a515b 905 'phone' => 'Home' . 'Phone' . $contactID,
f797aeb8 906 ]);
907 }
908
909 $relationships = [
39b959db 910 $this->contactIDs[1] => ['label' => 'Spouse of'],
f797aeb8 911 ];
912
913 foreach ($relationships as $contactID => $relationshipType) {
914 $relationshipTypeID = $this->callAPISuccess('RelationshipType', 'getvalue', ['label_a_b' => $relationshipType['label'], 'return' => 'id']);
915 $result = $this->callAPISuccess('Relationship', 'create', [
916 'contact_id_a' => $this->contactIDs[0],
917 'relationship_type_id' => $relationshipTypeID,
39b959db 918 'contact_id_b' => $contactID,
f797aeb8 919 ]);
920 $relationships[$contactID]['id'] = $result['id'];
921 $relationships[$contactID]['relationship_type_id'] = $relationshipTypeID;
922 }
923
924 $fields = [['Individual', 'contact_id']];
925 // ' ' denotes primary location type.
926 foreach (array_keys(array_merge($locationTypes, [' ' => ['Primary']])) as $locationType) {
927 $fields[] = [
928 'Individual',
929 'phone',
930 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'location_type_id', $locationType),
931 ];
932 $fields[] = [
933 'Individual',
934 'phone_type_id',
935 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'location_type_id', $locationType),
936 ];
937 foreach ($relationships as $contactID => $relationship) {
938 $fields[] = [
939 'Individual',
940 $relationship['relationship_type_id'] . '_a_b',
941 'phone_type_id',
942 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'location_type_id', $locationType),
943 ];
944 }
945 foreach ($phoneTypes as $phoneType) {
946 $fields[] = [
947 'Individual',
948 'phone',
949 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'location_type_id', $locationType),
950 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', $phoneType),
951 ];
952 foreach ($relationships as $contactID => $relationship) {
953 $fields[] = [
954 'Individual',
955 $relationship['relationship_type_id'] . '_a_b',
956 'phone_type_id',
957 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'location_type_id', $locationType),
958 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', $phoneType),
959 ];
960 }
961 }
962 }
963 list($tableName) = $this->doExport($fields, $this->contactIDs[0]);
964
965 $dao = CRM_Core_DAO::executeQuery('SELECT * FROM ' . $tableName);
966 while ($dao->fetch()) {
967 // note there is some chance these might be random on some mysql co
968 $this->assertEquals('BillingMobile3', $dao->billing_phone_mobile);
969 $this->assertEquals('', $dao->billing_phone_phone);
970 $relField = '2_a_b_phone_type_id';
971 $this->assertEquals('Phone', $dao->$relField);
972 $this->assertEquals('Mobile', $dao->phone_type_id);
973 $this->assertEquals('Mobile', $dao->billing_phone_type_id);
974 }
975 }
976
a16a432a 977 /**
978 * Export City against multiple location types.
979 */
980 public function testExportAddressData() {
981 $this->diversifyLocationTypes();
982
983 $locationTypes = ['Billing' => 'Billing', 'Home' => 'Home', 'Main' => 'Méin', 'Other' => 'Other', 'Whare Kai' => 'Whare Kai'];
984
985 $this->contactIDs[] = $this->individualCreate();
986 $this->contactIDs[] = $this->individualCreate();
987 $this->contactIDs[] = $this->householdCreate();
988 $this->contactIDs[] = $this->organizationCreate();
989 $fields = [['Individual', 'contact_id']];
990 foreach ($this->contactIDs as $contactID) {
991 foreach ($locationTypes as $locationName => $locationLabel) {
992 $this->callAPISuccess('Address', 'create', [
993 'contact_id' => $contactID,
994 'location_type_id' => $locationName,
995 'street_address' => $locationLabel . $contactID . 'street_address',
996 'city' => $locationLabel . $contactID . 'city',
997 'postal_code' => $locationLabel . $contactID . 'postal_code',
998 ]);
999 $fields[] = ['Individual', 'city', CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'location_type_id', $locationName)];
1000 $fields[] = ['Individual', 'street_address', CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'location_type_id', $locationName)];
1001 $fields[] = ['Individual', 'postal_code', CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Address', 'location_type_id', $locationName)];
1002 }
1003 }
1004
1005 $relationships = [
1006 $this->contactIDs[1] => ['label' => 'Spouse of'],
1007 $this->contactIDs[2] => ['label' => 'Household Member of'],
39b959db 1008 $this->contactIDs[3] => ['label' => 'Employee of'],
a16a432a 1009 ];
1010
1011 foreach ($relationships as $contactID => $relationshipType) {
1012 $relationshipTypeID = $this->callAPISuccess('RelationshipType', 'getvalue', ['label_a_b' => $relationshipType['label'], 'return' => 'id']);
1013 $result = $this->callAPISuccess('Relationship', 'create', [
1014 'contact_id_a' => $this->contactIDs[0],
1015 'relationship_type_id' => $relationshipTypeID,
39b959db 1016 'contact_id_b' => $contactID,
a16a432a 1017 ]);
1018 $relationships[$contactID]['id'] = $result['id'];
1019 $relationships[$contactID]['relationship_type_id'] = $relationshipTypeID;
1020 }
1021
1022 // ' ' denotes primary location type.
1023 foreach (array_keys(array_merge($locationTypes, [' ' => ['Primary']])) as $locationType) {
1024 foreach ($relationships as $contactID => $relationship) {
1025 $fields[] = [
1026 'Individual',
1027 $relationship['relationship_type_id'] . '_a_b',
1028 'city',
1029 CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_IM', 'location_type_id', $locationType),
1030 ];
1031 }
1032 }
1033 list($tableName, $sqlColumns) = $this->doExport($fields, $this->contactIDs[0]);
1034
1035 $dao = CRM_Core_DAO::executeQuery('SELECT * FROM ' . $tableName);
1036 while ($dao->fetch()) {
1037 $id = $dao->contact_id;
1038 $this->assertEquals('Méin' . $id . 'city', $dao->main_city);
1039 $this->assertEquals('Billing' . $id . 'street_address', $dao->billing_street_address);
1040 $this->assertEquals('Whare Kai' . $id . 'postal_code', $dao->whare_kai_postal_code);
1041 foreach ($relationships as $relatedContactID => $relationship) {
1042 $relationshipString = $field = $relationship['relationship_type_id'] . '_a_b';
1043 $field = $relationshipString . '_main_city';
1044 $this->assertEquals('Méin' . $relatedContactID . 'city', $dao->$field);
1045 }
1046 }
1047
1048 $this->assertEquals([
1049 'contact_id' => 'contact_id varchar(255)',
5ebd7d09 1050 'billing_city' => 'billing_city varchar(64)',
1051 'billing_street_address' => 'billing_street_address varchar(96)',
1052 'billing_postal_code' => 'billing_postal_code varchar(64)',
1053 'home_city' => 'home_city varchar(64)',
1054 'home_street_address' => 'home_street_address varchar(96)',
1055 'home_postal_code' => 'home_postal_code varchar(64)',
1056 'main_city' => 'main_city varchar(64)',
1057 'main_street_address' => 'main_street_address varchar(96)',
1058 'main_postal_code' => 'main_postal_code varchar(64)',
1059 'other_city' => 'other_city varchar(64)',
1060 'other_street_address' => 'other_street_address varchar(96)',
1061 'other_postal_code' => 'other_postal_code varchar(64)',
1062 'whare_kai_city' => 'whare_kai_city varchar(64)',
1063 'whare_kai_street_address' => 'whare_kai_street_address varchar(96)',
1064 'whare_kai_postal_code' => 'whare_kai_postal_code varchar(64)',
1065 '2_a_b_billing_city' => '2_a_b_billing_city varchar(64)',
1066 '2_a_b_home_city' => '2_a_b_home_city varchar(64)',
1067 '2_a_b_main_city' => '2_a_b_main_city varchar(64)',
1068 '2_a_b_other_city' => '2_a_b_other_city varchar(64)',
1069 '2_a_b_whare_kai_city' => '2_a_b_whare_kai_city varchar(64)',
1070 '2_a_b_city' => '2_a_b_city varchar(64)',
1071 '8_a_b_billing_city' => '8_a_b_billing_city varchar(64)',
1072 '8_a_b_home_city' => '8_a_b_home_city varchar(64)',
1073 '8_a_b_main_city' => '8_a_b_main_city varchar(64)',
1074 '8_a_b_other_city' => '8_a_b_other_city varchar(64)',
1075 '8_a_b_whare_kai_city' => '8_a_b_whare_kai_city varchar(64)',
1076 '8_a_b_city' => '8_a_b_city varchar(64)',
1077 '5_a_b_billing_city' => '5_a_b_billing_city varchar(64)',
1078 '5_a_b_home_city' => '5_a_b_home_city varchar(64)',
1079 '5_a_b_main_city' => '5_a_b_main_city varchar(64)',
1080 '5_a_b_other_city' => '5_a_b_other_city varchar(64)',
1081 '5_a_b_whare_kai_city' => '5_a_b_whare_kai_city varchar(64)',
1082 '5_a_b_city' => '5_a_b_city varchar(64)',
a16a432a 1083 ], $sqlColumns);
1084 }
1085
4d251131 1086 /**
1087 * Test master_address_id field.
1088 */
1089 public function testExportMasterAddress() {
1090 $this->setUpContactExportData();
1091
994a070c 1092 //export the master address for contact B
46312f7d 1093 $selectedFields = [
1094 ['Individual', 'master_id', 1],
1095 ];
994a070c 1096 list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
1097 TRUE,
46312f7d 1098 [$this->contactIDs[1]],
1099 [],
994a070c 1100 NULL,
1101 $selectedFields,
1102 NULL,
1103 CRM_Export_Form_Select::CONTACT_EXPORT,
4d251131 1104 "contact_a.id IN ({$this->contactIDs[1]})",
994a070c 1105 NULL,
1106 FALSE,
1107 FALSE,
46312f7d 1108 [
994a070c 1109 'suppress_csv_for_testing' => TRUE,
46312f7d 1110 ]
994a070c 1111 );
1112 $field = key($sqlColumns);
1113
1114 //assert the exported result
1115 $masterName = CRM_Core_DAO::singleValueQuery("SELECT {$field} FROM {$tableName}");
77544f6f 1116 $displayName = CRM_Contact_BAO_Contact::getMasterDisplayName($this->masterAddressID);
994a070c 1117 $this->assertEquals($displayName, $masterName);
1118
1119 // delete the export temp table and component table
1120 $sql = "DROP TABLE IF EXISTS {$tableName}";
1121 CRM_Core_DAO::executeQuery($sql);
1122 }
1123
6382c24c
LCA
1124 /**
1125 * Test that deceased and do not mail contacts are removed from contacts before
6d52bfe5 1126 *
1127 * @dataProvider getReasonsNotToMail
1128 *
1129 * @param array $reason
1130 * @param array $addressReason
46312f7d 1131 *
1132 * @throws \CRM_Core_Exception
6382c24c 1133 */
6d52bfe5 1134 public function testExportDeceasedDoNotMail($reason, $addressReason) {
46312f7d 1135 $contactA = $this->callAPISuccess('contact', 'create', [
6382c24c
LCA
1136 'first_name' => 'John',
1137 'last_name' => 'Doe',
1138 'contact_type' => 'Individual',
46312f7d 1139 ]);
6382c24c 1140
6d52bfe5 1141 $contactB = $this->callAPISuccess('contact', 'create', array_merge([
6382c24c
LCA
1142 'first_name' => 'Jane',
1143 'last_name' => 'Doe',
1144 'contact_type' => 'Individual',
6d52bfe5 1145 ], $reason));
6382c24c
LCA
1146
1147 //create address for contact A
6d52bfe5 1148 $this->callAPISuccess('address', 'create', [
6382c24c
LCA
1149 'contact_id' => $contactA['id'],
1150 'location_type_id' => 'Home',
1151 'street_address' => 'ABC 12',
1152 'postal_code' => '123 AB',
1153 'country_id' => '1152',
1154 'city' => 'ABC',
1155 'is_primary' => 1,
6d52bfe5 1156 ]);
6382c24c
LCA
1157
1158 //create address for contact B
6d52bfe5 1159 $this->callAPISuccess('address', 'create', array_merge([
6382c24c
LCA
1160 'contact_id' => $contactB['id'],
1161 'location_type_id' => 'Home',
1162 'street_address' => 'ABC 12',
1163 'postal_code' => '123 AB',
1164 'country_id' => '1152',
1165 'city' => 'ABC',
1166 'is_primary' => 1,
6d52bfe5 1167 ], $addressReason));
6382c24c
LCA
1168
1169 //export and merge contacts with same address
c8925481 1170 list($tableName, $sqlColumns, $headerRows, $processor) = CRM_Export_BAO_Export::exportComponents(
6382c24c 1171 TRUE,
46312f7d 1172 [$contactA['id'], $contactB['id']],
1173 [],
6382c24c
LCA
1174 NULL,
1175 NULL,
1176 NULL,
1177 CRM_Export_Form_Select::CONTACT_EXPORT,
1178 "contact_a.id IN ({$contactA['id']}, {$contactB['id']})",
1179 NULL,
1180 TRUE,
1181 FALSE,
46312f7d 1182 [
6382c24c
LCA
1183 'mergeOption' => TRUE,
1184 'suppress_csv_for_testing' => TRUE,
46312f7d 1185 'postal_mailing_export' => [
6382c24c 1186 'postal_mailing_export' => TRUE,
46312f7d 1187 ],
1188 ]
6382c24c
LCA
1189 );
1190
c8925481 1191 $this->assertTrue(!in_array('state_province_id', $processor->getHeaderRows()));
6382c24c
LCA
1192 $greeting = CRM_Core_DAO::singleValueQuery("SELECT email_greeting FROM {$tableName}");
1193
1194 //Assert email_greeting is not merged
1195 $this->assertNotContains(',', (string) $greeting);
1196
1197 // delete the export temp table and component table
1198 $sql = "DROP TABLE IF EXISTS {$tableName}";
1199 CRM_Core_DAO::executeQuery($sql);
1200 }
1201
6d52bfe5 1202 /**
1203 * Get reasons that a contact is not postalable.
46312f7d 1204 *
6d52bfe5 1205 * @return array
1206 */
1207 public function getReasonsNotToMail() {
1208 return [
1209 [['is_deceased' => 1], []],
1210 [['do_not_mail' => 1], []],
1211 [[], ['street_address' => '']],
1212 ];
1213 }
39b959db 1214
2593f7dc 1215 /**
46312f7d 1216 * Set up household for tests.
1217 *
2593f7dc 1218 * @return array
46312f7d 1219 * @throws \Exception
2593f7dc 1220 */
1221 protected function setUpHousehold() {
1222 $this->setUpContactExportData();
1223 $householdID = $this->householdCreate([
cedeaa5c 1224 'source' => 'household sauce',
2593f7dc 1225 'api.Address.create' => [
1226 'city' => 'Portland',
1227 'state_province_id' => 'Maine',
39b959db
SL
1228 'location_type_id' => 'Home',
1229 ],
2593f7dc 1230 ]);
1231
1232 $relationshipTypes = $this->callAPISuccess('RelationshipType', 'get', [])['values'];
1233 $houseHoldTypeID = NULL;
1234 foreach ($relationshipTypes as $id => $relationshipType) {
1235 if ($relationshipType['name_a_b'] === 'Household Member of') {
1236 $houseHoldTypeID = $relationshipType['id'];
1237 }
1238 }
1239 $this->callAPISuccess('Relationship', 'create', [
1240 'contact_id_a' => $this->contactIDs[0],
1241 'contact_id_b' => $householdID,
1242 'relationship_type_id' => $houseHoldTypeID,
1243 ]);
1244 $this->callAPISuccess('Relationship', 'create', [
1245 'contact_id_a' => $this->contactIDs[1],
1246 'contact_id_b' => $householdID,
1247 'relationship_type_id' => $houseHoldTypeID,
1248 ]);
46312f7d 1249 return [$householdID, $houseHoldTypeID];
2593f7dc 1250 }
1251
3663269c 1252 /**
704e3e9a 1253 * Do a CiviCRM export.
1254 *
46312f7d 1255 * @param array $selectedFields
704e3e9a 1256 * @param int $id
1257 *
c66a5741 1258 * @param int $exportMode
1259 *
3663269c 1260 * @return array
46312f7d 1261 * @throws \CRM_Core_Exception
3663269c 1262 */
c66a5741 1263 protected function doExport($selectedFields, $id, $exportMode = CRM_Export_Form_Select::CONTACT_EXPORT) {
f797aeb8 1264 $ids = (array) $id;
3663269c 1265 list($tableName, $sqlColumns) = CRM_Export_BAO_Export::exportComponents(
1266 TRUE,
f797aeb8 1267 $ids,
46312f7d 1268 [],
3663269c 1269 NULL,
1270 $selectedFields,
1271 NULL,
c66a5741 1272 $exportMode,
f797aeb8 1273 "contact_a.id IN (" . implode(',', $ids) . ")",
3663269c 1274 NULL,
1275 FALSE,
1276 FALSE,
46312f7d 1277 [
3663269c 1278 'suppress_csv_for_testing' => TRUE,
46312f7d 1279 ]
3663269c 1280 );
46312f7d 1281 return [$tableName, $sqlColumns];
3663269c 1282 }
1283
0a3b035f 1284 /**
1285 * Ensure component is enabled.
1286 *
1287 * @param int $exportMode
1288 */
1289 public function ensureComponentIsEnabled($exportMode) {
1290 if ($exportMode === CRM_Export_Form_Select::CASE_EXPORT) {
1291 CRM_Core_BAO_ConfigSetting::enableComponent('CiviCase');
1292 }
1293 }
1294
ce14544c 1295 /**
1296 * Test our export all field metadata retrieval.
1297 *
1298 * @dataProvider additionalFieldsDataProvider
46312f7d 1299 *
ce14544c 1300 * @param int $exportMode
1301 * @param $expected
1302 */
1303 public function testAdditionalReturnProperties($exportMode, $expected) {
1304 $this->ensureComponentIsEnabled($exportMode);
1305 $processor = new CRM_Export_BAO_ExportProcessor($exportMode, NULL, 'AND');
1306 $metadata = $processor->getAdditionalReturnProperties();
1307 $this->assertEquals($expected, $metadata);
1308 }
1309
1310 /**
1311 * Test our export all field metadata retrieval.
1312 *
1313 * @dataProvider allFieldsDataProvider
46312f7d 1314 *
ce14544c 1315 * @param int $exportMode
1316 * @param $expected
1317 */
1318 public function testDefaultReturnProperties($exportMode, $expected) {
1319 $this->ensureComponentIsEnabled($exportMode);
1320 $processor = new CRM_Export_BAO_ExportProcessor($exportMode, NULL, 'AND');
1321 $metadata = $processor->getDefaultReturnProperties();
1322 $this->assertEquals($expected, $metadata);
1323 }
1324
1325 /**
1326 * Get fields returned from additionalFields function.
1327 *
1328 * @return array
1329 */
1330 public function additionalFieldsDataProvider() {
1331 return [
1332 [
1333 'anything that will then be defaulting ton contact',
1334 $this->getExtraReturnProperties(),
1335 ],
1336 [
1337 CRM_Export_Form_Select::ACTIVITY_EXPORT,
1338 array_merge($this->getExtraReturnProperties(), $this->getActivityReturnProperties()),
1339 ],
1340 [
1341 CRM_Export_Form_Select::CASE_EXPORT,
1342 array_merge($this->getExtraReturnProperties(), $this->getCaseReturnProperties()),
1343 ],
1344 [
1345 CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
1346 array_merge($this->getExtraReturnProperties(), $this->getContributionReturnProperties()),
1347 ],
1348 [
1349 CRM_Export_Form_Select::EVENT_EXPORT,
1350 array_merge($this->getExtraReturnProperties(), $this->getEventReturnProperties()),
1351 ],
1352 [
1353 CRM_Export_Form_Select::MEMBER_EXPORT,
1354 array_merge($this->getExtraReturnProperties(), $this->getMembershipReturnProperties()),
1355 ],
1356 [
1357 CRM_Export_Form_Select::PLEDGE_EXPORT,
1358 array_merge($this->getExtraReturnProperties(), $this->getPledgeReturnProperties()),
1359 ],
1360
1361 ];
1362 }
1363
1364 /**
1365 * get data for testing field metadata by query mode.
1366 */
1367 public function allFieldsDataProvider() {
1368 return [
1369 [
1370 'anything that will then be defaulting ton contact',
1371 $this->getBasicReturnProperties(TRUE),
1372 ],
1373 [
1374 CRM_Export_Form_Select::ACTIVITY_EXPORT,
1375 array_merge($this->getBasicReturnProperties(FALSE), $this->getActivityReturnProperties()),
1376 ],
1377 [
1378 CRM_Export_Form_Select::CASE_EXPORT,
1379 array_merge($this->getBasicReturnProperties(FALSE), $this->getCaseReturnProperties()),
1380 ],
1381 [
1382 CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
1383 array_merge($this->getBasicReturnProperties(FALSE), $this->getContributionReturnProperties()),
1384 ],
1385 [
1386 CRM_Export_Form_Select::EVENT_EXPORT,
1387 array_merge($this->getBasicReturnProperties(FALSE), $this->getEventReturnProperties()),
1388 ],
1389 [
1390 CRM_Export_Form_Select::MEMBER_EXPORT,
1391 array_merge($this->getBasicReturnProperties(FALSE), $this->getMembershipReturnProperties()),
1392 ],
1393 [
1394 CRM_Export_Form_Select::PLEDGE_EXPORT,
1395 array_merge($this->getBasicReturnProperties(FALSE), $this->getPledgeReturnProperties()),
1396 ],
1397 ];
1398 }
1399
1400 /**
1401 * Get return properties manually added in.
1402 */
1403 public function getExtraReturnProperties() {
7626754f 1404 return [];
ce14544c 1405 }
1406
1407 /**
1408 * Get basic return properties.
1409 *
704e3e9a 1410 * @param bool $isContactMode
ce14544c 1411 * Are we in contact mode or not
1412 *
1413 * @return array
1414 */
1415 protected function getBasicReturnProperties($isContactMode) {
1416 $returnProperties = [
1417 'id' => 1,
1418 'contact_type' => 1,
1419 'contact_sub_type' => 1,
1420 'do_not_email' => 1,
1421 'do_not_phone' => 1,
1422 'do_not_mail' => 1,
1423 'do_not_sms' => 1,
1424 'do_not_trade' => 1,
1425 'is_opt_out' => 1,
1426 'legal_identifier' => 1,
1427 'external_identifier' => 1,
1428 'sort_name' => 1,
1429 'display_name' => 1,
1430 'nick_name' => 1,
1431 'legal_name' => 1,
1432 'image_URL' => 1,
1433 'preferred_communication_method' => 1,
1434 'preferred_language' => 1,
1435 'preferred_mail_format' => 1,
1436 'hash' => 1,
1437 'contact_source' => 1,
1438 'first_name' => 1,
1439 'middle_name' => 1,
1440 'last_name' => 1,
1441 'prefix_id' => 1,
1442 'suffix_id' => 1,
1443 'formal_title' => 1,
1444 'communication_style_id' => 1,
1445 'email_greeting_id' => 1,
1446 'postal_greeting_id' => 1,
1447 'addressee_id' => 1,
1448 'job_title' => 1,
1449 'gender_id' => 1,
1450 'birth_date' => 1,
1451 'is_deceased' => 1,
1452 'deceased_date' => 1,
1453 'household_name' => 1,
1454 'organization_name' => 1,
1455 'sic_code' => 1,
1456 'user_unique_id' => 1,
1457 'current_employer_id' => 1,
1458 'contact_is_deleted' => 1,
1459 'created_date' => 1,
1460 'modified_date' => 1,
1461 'addressee' => 1,
1462 'email_greeting' => 1,
1463 'postal_greeting' => 1,
1464 'current_employer' => 1,
1465 'location_type' => 1,
1466 'street_address' => 1,
1467 'street_number' => 1,
1468 'street_number_suffix' => 1,
1469 'street_name' => 1,
1470 'street_unit' => 1,
1471 'supplemental_address_1' => 1,
1472 'supplemental_address_2' => 1,
1473 'supplemental_address_3' => 1,
1474 'city' => 1,
1475 'postal_code_suffix' => 1,
1476 'postal_code' => 1,
1477 'geo_code_1' => 1,
1478 'geo_code_2' => 1,
1479 'address_name' => 1,
1480 'master_id' => 1,
1481 'county' => 1,
1482 'state_province' => 1,
1483 'country' => 1,
1484 'phone' => 1,
1485 'phone_ext' => 1,
1486 'email' => 1,
1487 'on_hold' => 1,
1488 'is_bulkmail' => 1,
1489 'signature_text' => 1,
1490 'signature_html' => 1,
1491 'im_provider' => 1,
1492 'im' => 1,
1493 'openid' => 1,
1494 'world_region' => 1,
1495 'url' => 1,
1496 'groups' => 1,
1497 'tags' => 1,
1498 'notes' => 1,
1499 'phone_type_id' => 1,
ce14544c 1500 ];
1501 if (!$isContactMode) {
1502 unset($returnProperties['groups']);
1503 unset($returnProperties['tags']);
1504 unset($returnProperties['notes']);
1505 }
1506 return $returnProperties;
1507 }
1508
1509 /**
1510 * Get return properties for pledges.
1511 *
1512 * @return array
1513 */
1514 public function getPledgeReturnProperties() {
1515 return [
1516 'contact_type' => 1,
1517 'contact_sub_type' => 1,
1518 'sort_name' => 1,
1519 'display_name' => 1,
1520 'pledge_id' => 1,
1521 'pledge_amount' => 1,
1522 'pledge_total_paid' => 1,
1523 'pledge_create_date' => 1,
1524 'pledge_start_date' => 1,
1525 'pledge_next_pay_date' => 1,
1526 'pledge_next_pay_amount' => 1,
1527 'pledge_status' => 1,
1528 'pledge_is_test' => 1,
1529 'pledge_contribution_page_id' => 1,
1530 'pledge_financial_type' => 1,
1531 'pledge_frequency_interval' => 1,
1532 'pledge_frequency_unit' => 1,
1533 'pledge_currency' => 1,
1534 'pledge_campaign_id' => 1,
1535 'pledge_balance_amount' => 1,
1536 'pledge_payment_id' => 1,
1537 'pledge_payment_scheduled_amount' => 1,
1538 'pledge_payment_scheduled_date' => 1,
1539 'pledge_payment_paid_amount' => 1,
1540 'pledge_payment_paid_date' => 1,
1541 'pledge_payment_reminder_date' => 1,
1542 'pledge_payment_reminder_count' => 1,
1543 'pledge_payment_status' => 1,
1544 ];
1545 }
1546
1547 /**
1548 * Get membership return properties.
1549 *
1550 * @return array
1551 */
1552 public function getMembershipReturnProperties() {
1553 return [
ce14544c 1554 'contact_type' => 1,
1555 'contact_sub_type' => 1,
1556 'sort_name' => 1,
1557 'display_name' => 1,
1558 'membership_type' => 1,
1559 'member_is_test' => 1,
1560 'member_is_pay_later' => 1,
1561 'join_date' => 1,
1562 'membership_start_date' => 1,
1563 'membership_end_date' => 1,
1564 'membership_source' => 1,
1565 'membership_status' => 1,
1566 'membership_id' => 1,
1567 'owner_membership_id' => 1,
1568 'max_related' => 1,
1569 'membership_recur_id' => 1,
1570 'member_campaign_id' => 1,
1571 'member_is_override' => 1,
1572 'member_auto_renew' => 1,
1573 ];
1574 }
1575
1576 /**
1577 * Get return properties for events.
1578 *
1579 * @return array
1580 */
1581 public function getEventReturnProperties() {
1582 return [
1583 'contact_type' => 1,
1584 'contact_sub_type' => 1,
1585 'sort_name' => 1,
1586 'display_name' => 1,
1587 'event_id' => 1,
1588 'event_title' => 1,
1589 'event_start_date' => 1,
1590 'event_end_date' => 1,
1591 'event_type' => 1,
1592 'participant_id' => 1,
1593 'participant_status' => 1,
1594 'participant_status_id' => 1,
1595 'participant_role' => 1,
1596 'participant_role_id' => 1,
1597 'participant_note' => 1,
1598 'participant_register_date' => 1,
1599 'participant_source' => 1,
1600 'participant_fee_level' => 1,
1601 'participant_is_test' => 1,
1602 'participant_is_pay_later' => 1,
1603 'participant_fee_amount' => 1,
1604 'participant_discount_name' => 1,
1605 'participant_fee_currency' => 1,
1606 'participant_registered_by_id' => 1,
1607 'participant_campaign_id' => 1,
1608 ];
1609 }
1610
1611 /**
1612 * Get return properties for activities.
1613 *
1614 * @return array
1615 */
1616 public function getActivityReturnProperties() {
1617 return [
1618 'activity_id' => 1,
1619 'contact_type' => 1,
1620 'contact_sub_type' => 1,
1621 'sort_name' => 1,
1622 'display_name' => 1,
1623 'activity_type' => 1,
1624 'activity_type_id' => 1,
1625 'activity_subject' => 1,
1626 'activity_date_time' => 1,
1627 'activity_duration' => 1,
1628 'activity_location' => 1,
1629 'activity_details' => 1,
1630 'activity_status' => 1,
1631 'activity_priority' => 1,
1632 'source_contact' => 1,
1633 'source_record_id' => 1,
1634 'activity_is_test' => 1,
1635 'activity_campaign_id' => 1,
1636 'result' => 1,
1637 'activity_engagement_level' => 1,
1638 'parent_id' => 1,
1639 ];
1640 }
1641
1642 /**
1643 * Get return properties for Case.
1644 *
1645 * @return array
1646 */
1647 public function getCaseReturnProperties() {
1648 return [
1649 'contact_type' => 1,
1650 'contact_sub_type' => 1,
1651 'sort_name' => 1,
1652 'display_name' => 1,
1653 'phone' => 1,
1654 'case_start_date' => 1,
1655 'case_end_date' => 1,
1656 'case_subject' => 1,
1657 'case_source_contact_id' => 1,
1658 'case_activity_status' => 1,
1659 'case_activity_duration' => 1,
1660 'case_activity_medium_id' => 1,
1661 'case_activity_details' => 1,
1662 'case_activity_is_auto' => 1,
1663 'contact_id' => 1,
1664 'case_id' => 1,
1665 'case_activity_subject' => 1,
1666 'case_status' => 1,
1667 'case_type' => 1,
1668 'case_role' => 1,
1669 'case_deleted' => 1,
1670 'case_recent_activity_date' => 1,
1671 'case_recent_activity_type' => 1,
1672 'case_scheduled_activity_date' => 1,
1673 ];
1674 }
1675
1676 /**
1677 * Get return properties for contribution.
1678 *
1679 * @return array
1680 */
1681 public function getContributionReturnProperties() {
1682 return [
1683 'contact_type' => 1,
1684 'contact_sub_type' => 1,
1685 'sort_name' => 1,
1686 'display_name' => 1,
1687 'financial_type' => 1,
1688 'contribution_source' => 1,
1689 'receive_date' => 1,
1690 'thankyou_date' => 1,
6e7cc0f5 1691 'contribution_cancel_date' => 1,
ce14544c 1692 'total_amount' => 1,
1693 'accounting_code' => 1,
1694 'payment_instrument' => 1,
1695 'payment_instrument_id' => 1,
1696 'contribution_check_number' => 1,
1697 'non_deductible_amount' => 1,
1698 'fee_amount' => 1,
1699 'net_amount' => 1,
1700 'trxn_id' => 1,
1701 'invoice_id' => 1,
1702 'invoice_number' => 1,
1703 'currency' => 1,
1704 'cancel_reason' => 1,
1705 'receipt_date' => 1,
ce14544c 1706 'is_test' => 1,
1707 'is_pay_later' => 1,
1708 'contribution_status' => 1,
1709 'contribution_recur_id' => 1,
1710 'amount_level' => 1,
1711 'contribution_note' => 1,
1712 'contribution_batch' => 1,
1713 'contribution_campaign_title' => 1,
1714 'contribution_campaign_id' => 1,
ce14544c 1715 'contribution_soft_credit_name' => 1,
1716 'contribution_soft_credit_amount' => 1,
1717 'contribution_soft_credit_type' => 1,
1718 'contribution_soft_credit_contact_id' => 1,
1719 'contribution_soft_credit_contribution_id' => 1,
1720 ];
1721 }
1722
0a3b035f 1723 /**
1724 * Test the column definition when 'all' fields defined.
1725 *
6c93b9a9 1726 * @param int $exportMode
1727 * @param array $expected
1728 * @param array $expectedHeaders
0a3b035f 1729 *
46312f7d 1730 * @throws \CRM_Core_Exception
0a3b035f 1731 * @dataProvider getSqlColumnsOutput
1732 */
6c93b9a9 1733 public function testGetSQLColumnsAndHeaders($exportMode, $expected, $expectedHeaders) {
0a3b035f 1734 $this->ensureComponentIsEnabled($exportMode);
1735 // We need some data so that we can get to the end of the export
1736 // function. Hopefully one day that won't be required to get metadata info out.
1737 // eventually aspire to call $provider->getSQLColumns straight after it
1738 // is intiated.
1739 $this->setupBaseExportData($exportMode);
1740
1741 $result = CRM_Export_BAO_Export::exportComponents(
1742 TRUE,
1743 [1],
1744 [],
1745 NULL,
1746 NULL,
1747 NULL,
1748 $exportMode,
1749 NULL,
1750 NULL,
1751 FALSE,
1752 FALSE,
46312f7d 1753 [
0a3b035f 1754 'suppress_csv_for_testing' => TRUE,
46312f7d 1755 ]
0a3b035f 1756 );
1757 $this->assertEquals($expected, $result[1]);
6c93b9a9 1758 $this->assertEquals($expectedHeaders, $result[2]);
0a3b035f 1759 }
1760
6202c5bb 1761 /**
1762 * Test exported with data entry mis-fire.
1763 *
1764 * Not fatal error if data incomplete.
1765 *
1766 * https://lab.civicrm.org/dev/core/issues/819
1767 */
1768 public function testExportIncompleteSubmission() {
1769 $this->setUpContactExportData();
1770 $this->doExport([['Individual', '']], $this->contactIDs[1]);
1771 }
1772
5506290d 1773 /**
1774 * Test exported with fields to output specified.
1775 *
1776 * @dataProvider getAllSpecifiableReturnFields
1777 *
1778 * @param int $exportMode
1779 * @param array $selectedFields
1780 * @param array $expected
1781 */
1782 public function testExportSpecifyFields($exportMode, $selectedFields, $expected) {
1783 $this->ensureComponentIsEnabled($exportMode);
1784 $this->setUpContributionExportData();
c66a5741 1785 list($tableName, $sqlColumns) = $this->doExport($selectedFields, $this->contactIDs[1], $exportMode);
5506290d 1786 $this->assertEquals($expected, $sqlColumns);
1787 }
1788
c66a5741 1789 /**
1790 * Test export fields when no payment fields to be exported.
1791 */
1792 public function textExportParticipantSpecifyFieldsNoPayment() {
1793 $selectedFields = $this->getAllSpecifiableParticipantReturnFields();
1794 foreach ($selectedFields as $index => $field) {
1795 if (substr($field[1], 0, 22) === 'componentPaymentField_') {
420384a0 1796 unset($selectedFields[$index]);
c66a5741 1797 }
1798 }
1799
1800 $expected = $this->getAllSpecifiableParticipantReturnFields();
1801 foreach ($expected as $index => $field) {
1802 if (substr($index, 0, 22) === 'componentPaymentField_') {
420384a0 1803 unset($expected[$index]);
c66a5741 1804 }
1805 }
1806
1807 list($tableName, $sqlColumns) = $this->doExport($selectedFields, $this->contactIDs[1], CRM_Export_Form_Select::EVENT_EXPORT);
1808 $this->assertEquals($expected, $sqlColumns);
1809 }
39b959db 1810
5506290d 1811 /**
46312f7d 1812 * Get all return fields (@return array
1813 *
1814 * @todo - still being built up.
5506290d 1815 *
5506290d 1816 */
1817 public function getAllSpecifiableReturnFields() {
1818 return [
1819 [
1820 CRM_Export_Form_Select::EVENT_EXPORT,
1821 $this->getAllSpecifiableParticipantReturnFields(),
c66a5741 1822 $this->getAllSpecifiableParticipantReturnColumns(),
5506290d 1823 ],
1824 ];
1825 }
1826
c66a5741 1827 /**
1828 * Get expected return column output for participant mode return all columns.
1829 *
1830 * @return array
1831 */
1832 public function getAllSpecifiableParticipantReturnColumns() {
1833 return [
1834 'participant_campaign_id' => 'participant_campaign_id varchar(128)',
1835 'participant_contact_id' => 'participant_contact_id varchar(16)',
1836 'componentpaymentfield_contribution_status' => 'componentpaymentfield_contribution_status text',
1837 'currency' => 'currency varchar(3)',
1838 'componentpaymentfield_received_date' => 'componentpaymentfield_received_date text',
1839 'default_role_id' => 'default_role_id varchar(16)',
1840 'participant_discount_name' => 'participant_discount_name varchar(16)',
1841 'event_id' => 'event_id varchar(16)',
1842 'event_end_date' => 'event_end_date varchar(32)',
1843 'event_start_date' => 'event_start_date varchar(32)',
1844 'template_title' => 'template_title varchar(255)',
1845 'event_title' => 'event_title varchar(255)',
1846 'participant_fee_amount' => 'participant_fee_amount varchar(32)',
1847 'participant_fee_currency' => 'participant_fee_currency varchar(3)',
1848 'fee_label' => 'fee_label varchar(255)',
1849 'participant_fee_level' => 'participant_fee_level longtext',
1850 'participant_is_pay_later' => 'participant_is_pay_later varchar(16)',
1851 'participant_id' => 'participant_id varchar(16)',
1852 'participant_note' => 'participant_note text',
1853 'participant_role_id' => 'participant_role_id varchar(128)',
1854 'participant_role' => 'participant_role varchar(255)',
1855 'participant_source' => 'participant_source varchar(128)',
1856 'participant_status_id' => 'participant_status_id varchar(16)',
1857 'participant_status' => 'participant_status varchar(255)',
1858 'participant_register_date' => 'participant_register_date varchar(32)',
1859 'participant_registered_by_id' => 'participant_registered_by_id varchar(16)',
1860 'participant_is_test' => 'participant_is_test varchar(16)',
1861 'componentpaymentfield_total_amount' => 'componentpaymentfield_total_amount text',
1862 'componentpaymentfield_transaction_id' => 'componentpaymentfield_transaction_id varchar(255)',
1863 'transferred_to_contact_id' => 'transferred_to_contact_id varchar(16)',
1864 ];
1865 }
1866
5506290d 1867 /**
1868 * @return array
1869 */
1870 public function getAllSpecifiableParticipantReturnFields() {
1871 return [
1872 0 =>
1873 [
1874 0 => 'Participant',
1875 1 => '',
1876 ],
1877 1 =>
1878 [
1879 0 => 'Participant',
1880 1 => 'participant_campaign_id',
1881 ],
1882 2 =>
1883 [
1884 0 => 'Participant',
1885 1 => 'participant_contact_id',
1886 ],
1887 3 =>
1888 [
1889 0 => 'Participant',
1890 1 => 'componentPaymentField_contribution_status',
1891 ],
1892 4 =>
1893 [
1894 0 => 'Participant',
1895 1 => 'currency',
1896 ],
1897 5 =>
1898 [
1899 0 => 'Participant',
1900 1 => 'componentPaymentField_received_date',
1901 ],
1902 6 =>
1903 [
1904 0 => 'Participant',
1905 1 => 'default_role_id',
1906 ],
1907 7 =>
1908 [
1909 0 => 'Participant',
1910 1 => 'participant_discount_name',
1911 ],
1912 8 =>
1913 [
1914 0 => 'Participant',
1915 1 => 'event_id',
1916 ],
1917 9 =>
1918 [
1919 0 => 'Participant',
1920 1 => 'event_end_date',
1921 ],
1922 10 =>
1923 [
1924 0 => 'Participant',
1925 1 => 'event_start_date',
1926 ],
1927 11 =>
1928 [
1929 0 => 'Participant',
1930 1 => 'template_title',
1931 ],
1932 12 =>
1933 [
1934 0 => 'Participant',
1935 1 => 'event_title',
1936 ],
1937 13 =>
1938 [
1939 0 => 'Participant',
1940 1 => 'participant_fee_amount',
1941 ],
1942 14 =>
1943 [
1944 0 => 'Participant',
1945 1 => 'participant_fee_currency',
1946 ],
1947 15 =>
1948 [
1949 0 => 'Participant',
1950 1 => 'fee_label',
1951 ],
1952 16 =>
1953 [
1954 0 => 'Participant',
1955 1 => 'participant_fee_level',
1956 ],
1957 17 =>
1958 [
1959 0 => 'Participant',
1960 1 => 'participant_is_pay_later',
1961 ],
1962 18 =>
1963 [
1964 0 => 'Participant',
1965 1 => 'participant_id',
1966 ],
1967 19 =>
1968 [
1969 0 => 'Participant',
1970 1 => 'participant_note',
1971 ],
1972 20 =>
1973 [
1974 0 => 'Participant',
1975 1 => 'participant_role_id',
1976 ],
1977 21 =>
1978 [
1979 0 => 'Participant',
1980 1 => 'participant_role',
1981 ],
1982 22 =>
1983 [
1984 0 => 'Participant',
1985 1 => 'participant_source',
1986 ],
1987 23 =>
1988 [
1989 0 => 'Participant',
1990 1 => 'participant_status_id',
1991 ],
1992 24 =>
1993 [
1994 0 => 'Participant',
1995 1 => 'participant_status',
1996 ],
1997 25 =>
1998 [
1999 0 => 'Participant',
2000 1 => 'participant_status',
2001 ],
2002 26 =>
2003 [
2004 0 => 'Participant',
2005 1 => 'participant_register_date',
2006 ],
2007 27 =>
2008 [
2009 0 => 'Participant',
2010 1 => 'participant_registered_by_id',
2011 ],
2012 28 =>
2013 [
2014 0 => 'Participant',
2015 1 => 'participant_is_test',
2016 ],
2017 29 =>
2018 [
2019 0 => 'Participant',
2020 1 => 'componentPaymentField_total_amount',
2021 ],
2022 30 =>
2023 [
2024 0 => 'Participant',
2025 1 => 'componentPaymentField_transaction_id',
2026 ],
2027 31 =>
2028 [
2029 0 => 'Participant',
2030 1 => 'transferred_to_contact_id',
2031 ],
2032 ];
2033 }
2034
0a3b035f 2035 /**
2036 * @param string $exportMode
2037 */
2038 public function setupBaseExportData($exportMode) {
2039 $this->createLoggedInUser();
2040 if ($exportMode === CRM_Export_Form_Select::CASE_EXPORT) {
2041 $this->setupCaseExportData();
2042 }
2043 if ($exportMode === CRM_Export_Form_Select::CONTRIBUTE_EXPORT) {
2044 $this->setUpContributionExportData();
2045 }
2046 if ($exportMode === CRM_Export_Form_Select::MEMBER_EXPORT) {
2047 $this->setUpMembershipExportData();
2048 }
2049 if ($exportMode === CRM_Export_Form_Select::ACTIVITY_EXPORT) {
2050 $this->setUpActivityExportData();
2051 }
2052 }
2053
2054 /**
2055 * Get comprehensive sql columns output.
2056 *
2057 * @return array
2058 */
2059 public function getSqlColumnsOutput() {
2060 return [
2061 [
2062 'anything that will then be defaulting ton contact',
2063 $this->getBasicSqlColumnDefinition(TRUE),
6c93b9a9 2064 $this->getBasicHeaderDefinition(TRUE),
0a3b035f 2065 ],
2066 [
2067 CRM_Export_Form_Select::ACTIVITY_EXPORT,
2068 array_merge($this->getBasicSqlColumnDefinition(FALSE), $this->getActivitySqlColumns()),
6c93b9a9 2069 array_merge($this->getBasicHeaderDefinition(FALSE), $this->getActivityHeaderDefinition()),
0a3b035f 2070 ],
2071 [
2072 CRM_Export_Form_Select::CASE_EXPORT,
2073 array_merge($this->getBasicSqlColumnDefinition(FALSE), $this->getCaseSqlColumns()),
6c93b9a9 2074 array_merge($this->getBasicHeaderDefinition(FALSE), $this->getCaseHeaderDefinition()),
0a3b035f 2075 ],
2076 [
2077 CRM_Export_Form_Select::CONTRIBUTE_EXPORT,
2078 array_merge($this->getBasicSqlColumnDefinition(FALSE), $this->getContributionSqlColumns()),
6c93b9a9 2079 array_merge($this->getBasicHeaderDefinition(FALSE), $this->getContributeHeaderDefinition()),
0a3b035f 2080 ],
2081 [
2082 CRM_Export_Form_Select::EVENT_EXPORT,
2083 array_merge($this->getBasicSqlColumnDefinition(FALSE), $this->getParticipantSqlColumns()),
6c93b9a9 2084 array_merge($this->getBasicHeaderDefinition(FALSE), $this->getParticipantHeaderDefinition()),
0a3b035f 2085 ],
2086 [
2087 CRM_Export_Form_Select::MEMBER_EXPORT,
2088 array_merge($this->getBasicSqlColumnDefinition(FALSE), $this->getMembershipSqlColumns()),
6c93b9a9 2089 array_merge($this->getBasicHeaderDefinition(FALSE), $this->getMemberHeaderDefinition()),
0a3b035f 2090 ],
2091 [
2092 CRM_Export_Form_Select::PLEDGE_EXPORT,
2093 array_merge($this->getBasicSqlColumnDefinition(FALSE), $this->getPledgeSqlColumns()),
6c93b9a9 2094 array_merge($this->getBasicHeaderDefinition(FALSE), $this->getPledgeHeaderDefinition()),
0a3b035f 2095 ],
2096
2097 ];
2098 }
2099
6c93b9a9 2100 /**
2101 * Get the header definition for exports.
2102 *
2103 * @param bool $isContactExport
2104 *
2105 * @return array
2106 */
2107 protected function getBasicHeaderDefinition($isContactExport) {
2108 $headers = [
39b959db
SL
2109 0 => 'Contact ID',
2110 1 => 'Contact Type',
2111 2 => 'Contact Subtype',
2112 3 => 'Do Not Email',
2113 4 => 'Do Not Phone',
2114 5 => 'Do Not Mail',
2115 6 => 'Do Not Sms',
2116 7 => 'Do Not Trade',
2117 8 => 'No Bulk Emails (User Opt Out)',
2118 9 => 'Legal Identifier',
2119 10 => 'External Identifier',
2120 11 => 'Sort Name',
2121 12 => 'Display Name',
2122 13 => 'Nickname',
2123 14 => 'Legal Name',
2124 15 => 'Image Url',
2125 16 => 'Preferred Communication Method',
2126 17 => 'Preferred Language',
2127 18 => 'Preferred Mail Format',
2128 19 => 'Contact Hash',
2129 20 => 'Contact Source',
2130 21 => 'First Name',
2131 22 => 'Middle Name',
2132 23 => 'Last Name',
2133 24 => 'Individual Prefix',
2134 25 => 'Individual Suffix',
2135 26 => 'Formal Title',
2136 27 => 'Communication Style',
2137 28 => 'Email Greeting ID',
2138 29 => 'Postal Greeting ID',
2139 30 => 'Addressee ID',
2140 31 => 'Job Title',
2141 32 => 'Gender',
2142 33 => 'Birth Date',
2143 34 => 'Deceased',
2144 35 => 'Deceased Date',
2145 36 => 'Household Name',
2146 37 => 'Organization Name',
2147 38 => 'Sic Code',
2148 39 => 'Unique ID (OpenID)',
2149 40 => 'Current Employer ID',
2150 41 => 'Contact is in Trash',
2151 42 => 'Created Date',
2152 43 => 'Modified Date',
2153 44 => 'Addressee',
2154 45 => 'Email Greeting',
2155 46 => 'Postal Greeting',
2156 47 => 'Current Employer',
2157 48 => 'Location Type',
2158 49 => 'Street Address',
2159 50 => 'Street Number',
2160 51 => 'Street Number Suffix',
2161 52 => 'Street Name',
2162 53 => 'Street Unit',
2163 54 => 'Supplemental Address 1',
2164 55 => 'Supplemental Address 2',
2165 56 => 'Supplemental Address 3',
2166 57 => 'City',
2167 58 => 'Postal Code Suffix',
2168 59 => 'Postal Code',
2169 60 => 'Latitude',
2170 61 => 'Longitude',
2171 62 => 'Address Name',
2172 63 => 'Master Address Belongs To',
2173 64 => 'County',
2174 65 => 'State',
2175 66 => 'Country',
2176 67 => 'Phone',
2177 68 => 'Phone Extension',
2178 69 => 'Phone Type',
2179 70 => 'Email',
2180 71 => 'On Hold',
2181 72 => 'Use for Bulk Mail',
2182 73 => 'Signature Text',
2183 74 => 'Signature Html',
2184 75 => 'IM Provider',
2185 76 => 'IM Screen Name',
2186 77 => 'OpenID',
2187 78 => 'World Region',
2188 79 => 'Website',
2189 80 => 'Group(s)',
2190 81 => 'Tag(s)',
2191 82 => 'Note(s)',
2192 ];
6c93b9a9 2193 if (!$isContactExport) {
6c93b9a9 2194 unset($headers[80]);
2195 unset($headers[81]);
219c47d6 2196 unset($headers[82]);
6c93b9a9 2197 }
2198 return $headers;
2199 }
2200
2201 /**
2202 * Get the definition for activity headers.
2203 *
2204 * @return array
2205 */
2206 protected function getActivityHeaderDefinition() {
2207 return [
2208 81 => 'Activity ID',
2209 82 => 'Activity Type',
2210 83 => 'Activity Type ID',
2211 84 => 'Subject',
2212 85 => 'Activity Date',
2213 86 => 'Duration',
2214 87 => 'Location',
2215 88 => 'Details',
2216 89 => 'Activity Status',
2217 90 => 'Activity Priority',
2218 91 => 'Source Contact',
2219 92 => 'source_record_id',
2220 93 => 'Test',
2221 94 => 'Campaign ID',
2222 95 => 'result',
2223 96 => 'Engagement Index',
2224 97 => 'parent_id',
2225 ];
2226 }
2227
2228 /**
2229 * Get the definition for case headers.
2230 *
2231 * @return array
2232 */
2233 protected function getCaseHeaderDefinition() {
2234 return [
2235 81 => 'contact_id',
2236 82 => 'Case ID',
2237 83 => 'case_activity_subject',
2238 84 => 'Case Subject',
2239 85 => 'Case Status',
2240 86 => 'Case Type',
2241 87 => 'Role in Case',
2242 88 => 'Case is in the Trash',
2243 89 => 'case_recent_activity_date',
2244 90 => 'case_recent_activity_type',
2245 91 => 'case_scheduled_activity_date',
2246 92 => 'Case Start Date',
2247 93 => 'Case End Date',
2248 94 => 'case_source_contact_id',
2249 95 => 'case_activity_status',
2250 96 => 'case_activity_duration',
2251 97 => 'case_activity_medium_id',
2252 98 => 'case_activity_details',
2253 99 => 'case_activity_is_auto',
2254 ];
2255 }
2256
2257 /**
2258 * Get the definition for contribute headers.
2259 *
2260 * @return array
2261 */
2262 protected function getContributeHeaderDefinition() {
2263 return [
2264 81 => 'Financial Type',
2265 82 => 'Contribution Source',
2266 83 => 'Date Received',
2267 84 => 'Thank-you Date',
6e7cc0f5 2268 85 => 'Cancelled / Refunded Date',
6c93b9a9 2269 86 => 'Total Amount',
2270 87 => 'Accounting Code',
a0090e6b 2271 88 => 'Payment Methods',
6c93b9a9 2272 89 => 'Payment Method ID',
2273 90 => 'Check Number',
2274 91 => 'Non-deductible Amount',
2275 92 => 'Fee Amount',
2276 93 => 'Net Amount',
2277 94 => 'Transaction ID',
2278 95 => 'Invoice Reference',
2279 96 => 'Invoice Number',
2280 97 => 'Currency',
927898c5 2281 98 => 'Cancellation / Refund Reason',
6c93b9a9 2282 99 => 'Receipt Date',
6c93b9a9 2283 106 => 'Test',
2284 107 => 'Is Pay Later',
a0090e6b 2285 108 => 'Contribution Status',
6c93b9a9 2286 109 => 'Recurring Contribution ID',
2287 110 => 'Amount Label',
2288 111 => 'Contribution Note',
2289 112 => 'Batch Name',
2290 113 => 'Campaign Title',
2291 114 => 'Campaign ID',
6c93b9a9 2292 116 => 'Soft Credit For',
2293 117 => 'Soft Credit Amount',
2294 118 => 'Soft Credit Type',
2295 119 => 'Soft Credit For Contact ID',
2296 120 => 'Soft Credit For Contribution ID',
2297 ];
2298 }
2299
2300 /**
2301 * Get the definition for event headers.
2302 *
2303 * @return array
2304 */
2305 protected function getParticipantHeaderDefinition() {
2306 return [
2307 81 => 'Event',
2308 82 => 'Event Title',
2309 83 => 'Event Start Date',
2310 84 => 'Event End Date',
2311 85 => 'Event Type',
2312 86 => 'Participant ID',
2313 87 => 'Participant Status',
2314 88 => 'Participant Status Id',
2315 89 => 'Participant Role',
2316 90 => 'Participant Role Id',
2317 91 => 'Participant Note',
2318 92 => 'Register date',
2319 93 => 'Participant Source',
2320 94 => 'Fee level',
2321 95 => 'Test',
2322 96 => 'Is Pay Later',
2323 97 => 'Fee Amount',
2324 98 => 'Discount Name',
2325 99 => 'Fee Currency',
2326 100 => 'Registered By ID',
2327 101 => 'Campaign ID',
2328 ];
2329 }
2330
2331 /**
2332 * Get the definition for member headers.
2333 *
2334 * @return array
2335 */
2336 protected function getMemberHeaderDefinition() {
2337 return [
2338 81 => 'Membership Type',
2339 82 => 'Test',
2340 83 => 'Is Pay Later',
2341 84 => 'Member Since',
2342 85 => 'Membership Start Date',
2343 86 => 'Membership Expiration Date',
2344 87 => 'Source',
2345 88 => 'Membership Status',
2346 89 => 'Membership ID',
2347 90 => 'Primary Member ID',
2348 91 => 'max_related',
2349 92 => 'membership_recur_id',
2350 93 => 'Campaign ID',
2351 94 => 'member_is_override',
2352 95 => 'member_auto_renew',
2353 ];
2354 }
2355
2356 /**
2357 * Get the definition for pledge headers.
2358 *
2359 * @return array
2360 */
2361 protected function getPledgeHeaderDefinition() {
2362 return [
2363 81 => 'Pledge ID',
2364 82 => 'Total Pledged',
2365 83 => 'Total Paid',
2366 84 => 'Pledge Made',
2367 85 => 'pledge_start_date',
2368 86 => 'Next Payment Date',
2369 87 => 'Next Payment Amount',
2370 88 => 'Pledge Status',
2371 89 => 'Test',
2372 90 => 'Pledge Contribution Page Id',
2373 91 => 'pledge_financial_type',
2374 92 => 'Pledge Frequency Interval',
2375 93 => 'Pledge Frequency Unit',
2376 94 => 'pledge_currency',
2377 95 => 'Campaign ID',
2378 96 => 'Balance Amount',
2379 97 => 'Payment ID',
2380 98 => 'Scheduled Amount',
2381 99 => 'Scheduled Date',
2382 100 => 'Paid Amount',
2383 101 => 'Paid Date',
2384 102 => 'Last Reminder',
2385 103 => 'Reminders Sent',
2386 104 => 'Pledge Payment Status',
2387 ];
2388 }
2389
0a3b035f 2390 /**
2391 * Get the column definition for exports.
2392 *
2393 * @param bool $isContactExport
2394 *
2395 * @return array
2396 */
2397 protected function getBasicSqlColumnDefinition($isContactExport) {
2398 $columns = [
2399 'civicrm_primary_id' => 'civicrm_primary_id varchar(16)',
2400 'contact_type' => 'contact_type varchar(64)',
2401 'contact_sub_type' => 'contact_sub_type varchar(255)',
2402 'do_not_email' => 'do_not_email varchar(16)',
2403 'do_not_phone' => 'do_not_phone varchar(16)',
2404 'do_not_mail' => 'do_not_mail varchar(16)',
2405 'do_not_sms' => 'do_not_sms varchar(16)',
2406 'do_not_trade' => 'do_not_trade varchar(16)',
2407 'is_opt_out' => 'is_opt_out varchar(16)',
2408 'legal_identifier' => 'legal_identifier varchar(32)',
2409 'external_identifier' => 'external_identifier varchar(64)',
2410 'sort_name' => 'sort_name varchar(128)',
2411 'display_name' => 'display_name varchar(128)',
2412 'nick_name' => 'nick_name varchar(128)',
2413 'legal_name' => 'legal_name varchar(128)',
2414 'image_url' => 'image_url longtext',
2415 'preferred_communication_method' => 'preferred_communication_method varchar(255)',
2416 'preferred_language' => 'preferred_language varchar(5)',
2417 'preferred_mail_format' => 'preferred_mail_format varchar(8)',
2418 'hash' => 'hash varchar(32)',
2419 'contact_source' => 'contact_source varchar(255)',
2420 'first_name' => 'first_name varchar(64)',
2421 'middle_name' => 'middle_name varchar(64)',
2422 'last_name' => 'last_name varchar(64)',
2423 'prefix_id' => 'prefix_id varchar(255)',
2424 'suffix_id' => 'suffix_id varchar(255)',
2425 'formal_title' => 'formal_title varchar(64)',
2426 'communication_style_id' => 'communication_style_id varchar(16)',
2427 'email_greeting_id' => 'email_greeting_id varchar(16)',
2428 'postal_greeting_id' => 'postal_greeting_id varchar(16)',
2429 'addressee_id' => 'addressee_id varchar(16)',
2430 'job_title' => 'job_title varchar(255)',
2431 'gender_id' => 'gender_id varchar(16)',
2432 'birth_date' => 'birth_date varchar(32)',
2433 'is_deceased' => 'is_deceased varchar(16)',
2434 'deceased_date' => 'deceased_date varchar(32)',
2435 'household_name' => 'household_name varchar(128)',
2436 'organization_name' => 'organization_name varchar(128)',
2437 'sic_code' => 'sic_code varchar(8)',
2438 'user_unique_id' => 'user_unique_id varchar(255)',
2439 'current_employer_id' => 'current_employer_id varchar(16)',
2440 'contact_is_deleted' => 'contact_is_deleted varchar(16)',
2441 'created_date' => 'created_date varchar(32)',
2442 'modified_date' => 'modified_date varchar(32)',
2443 'addressee' => 'addressee varchar(255)',
2444 'email_greeting' => 'email_greeting varchar(255)',
2445 'postal_greeting' => 'postal_greeting varchar(255)',
2446 'current_employer' => 'current_employer varchar(128)',
2447 'location_type' => 'location_type text',
2448 'street_address' => 'street_address varchar(96)',
2449 'street_number' => 'street_number varchar(16)',
2450 'street_number_suffix' => 'street_number_suffix varchar(8)',
2451 'street_name' => 'street_name varchar(64)',
2452 'street_unit' => 'street_unit varchar(16)',
2453 'supplemental_address_1' => 'supplemental_address_1 varchar(96)',
2454 'supplemental_address_2' => 'supplemental_address_2 varchar(96)',
2455 'supplemental_address_3' => 'supplemental_address_3 varchar(96)',
2456 'city' => 'city varchar(64)',
2457 'postal_code_suffix' => 'postal_code_suffix varchar(12)',
2458 'postal_code' => 'postal_code varchar(64)',
2459 'geo_code_1' => 'geo_code_1 varchar(32)',
2460 'geo_code_2' => 'geo_code_2 varchar(32)',
2461 'address_name' => 'address_name varchar(255)',
2462 'master_id' => 'master_id varchar(128)',
2463 'county' => 'county varchar(64)',
2464 'state_province' => 'state_province varchar(64)',
2465 'country' => 'country varchar(64)',
2466 'phone' => 'phone varchar(32)',
2467 'phone_ext' => 'phone_ext varchar(16)',
219c47d6 2468 'phone_type_id' => 'phone_type_id varchar(16)',
0a3b035f 2469 'email' => 'email varchar(254)',
2470 'on_hold' => 'on_hold varchar(16)',
2471 'is_bulkmail' => 'is_bulkmail varchar(16)',
2472 'signature_text' => 'signature_text longtext',
2473 'signature_html' => 'signature_html longtext',
2474 'im_provider' => 'im_provider text',
5ebd7d09 2475 'im_screen_name' => 'im_screen_name varchar(64)',
0a3b035f 2476 'openid' => 'openid varchar(255)',
2477 'world_region' => 'world_region varchar(128)',
2478 'url' => 'url varchar(128)',
2479 'groups' => 'groups text',
2480 'tags' => 'tags text',
2481 'notes' => 'notes text',
0a3b035f 2482 ];
2483 if (!$isContactExport) {
2484 unset($columns['groups']);
2485 unset($columns['tags']);
2486 unset($columns['notes']);
2487 }
2488 return $columns;
2489 }
2490
2491 /**
2492 * Get Case SQL columns.
2493 *
2494 * @return array
2495 */
2496 protected function getCaseSqlColumns() {
2497 return [
2498 'case_start_date' => 'case_start_date varchar(32)',
2499 'case_end_date' => 'case_end_date varchar(32)',
2500 'case_subject' => 'case_subject varchar(128)',
2501 'case_source_contact_id' => 'case_source_contact_id varchar(255)',
2502 'case_activity_status' => 'case_activity_status text',
2503 'case_activity_duration' => 'case_activity_duration text',
2504 'case_activity_medium_id' => 'case_activity_medium_id varchar(255)',
2505 'case_activity_details' => 'case_activity_details text',
2506 'case_activity_is_auto' => 'case_activity_is_auto text',
2507 'contact_id' => 'contact_id varchar(255)',
2508 'case_id' => 'case_id varchar(16)',
2509 'case_activity_subject' => 'case_activity_subject text',
2510 'case_status' => 'case_status text',
2511 'case_type' => 'case_type text',
2512 'case_role' => 'case_role text',
2513 'case_deleted' => 'case_deleted varchar(16)',
2514 'case_recent_activity_date' => 'case_recent_activity_date text',
2515 'case_recent_activity_type' => 'case_recent_activity_type text',
2516 'case_scheduled_activity_date' => 'case_scheduled_activity_date text',
2517 ];
2518 }
2519
2520 /**
2521 * Get activity sql columns.
2522 *
2523 * @return array
2524 */
2525 protected function getActivitySqlColumns() {
2526 return [
2527 'activity_id' => 'activity_id varchar(16)',
2528 'activity_type' => 'activity_type varchar(255)',
2529 'activity_type_id' => 'activity_type_id varchar(16)',
2530 'activity_subject' => 'activity_subject varchar(255)',
2531 'activity_date_time' => 'activity_date_time varchar(32)',
2532 'activity_duration' => 'activity_duration varchar(16)',
2533 'activity_location' => 'activity_location varchar(255)',
2534 'activity_details' => 'activity_details longtext',
2535 'activity_status' => 'activity_status varchar(255)',
2536 'activity_priority' => 'activity_priority varchar(255)',
2537 'source_contact' => 'source_contact varchar(255)',
2538 'source_record_id' => 'source_record_id varchar(255)',
2539 'activity_is_test' => 'activity_is_test varchar(16)',
2540 'activity_campaign_id' => 'activity_campaign_id varchar(128)',
2541 'result' => 'result text',
2542 'activity_engagement_level' => 'activity_engagement_level varchar(16)',
2543 'parent_id' => 'parent_id varchar(255)',
2544 ];
2545 }
2546
2547 /**
2548 * Get participant sql columns.
2549 *
2550 * @return array
2551 */
2552 protected function getParticipantSqlColumns() {
2553 return [
2554 'event_id' => 'event_id varchar(16)',
2555 'event_title' => 'event_title varchar(255)',
2556 'event_start_date' => 'event_start_date varchar(32)',
2557 'event_end_date' => 'event_end_date varchar(32)',
2558 'event_type' => 'event_type varchar(255)',
2559 'participant_id' => 'participant_id varchar(16)',
2560 'participant_status' => 'participant_status varchar(255)',
2561 'participant_status_id' => 'participant_status_id varchar(16)',
2562 'participant_role' => 'participant_role varchar(255)',
2563 'participant_role_id' => 'participant_role_id varchar(128)',
2564 'participant_note' => 'participant_note text',
2565 'participant_register_date' => 'participant_register_date varchar(32)',
2566 'participant_source' => 'participant_source varchar(128)',
2567 'participant_fee_level' => 'participant_fee_level longtext',
2568 'participant_is_test' => 'participant_is_test varchar(16)',
2569 'participant_is_pay_later' => 'participant_is_pay_later varchar(16)',
2570 'participant_fee_amount' => 'participant_fee_amount varchar(32)',
2571 'participant_discount_name' => 'participant_discount_name varchar(16)',
2572 'participant_fee_currency' => 'participant_fee_currency varchar(3)',
2573 'participant_registered_by_id' => 'participant_registered_by_id varchar(16)',
2574 'participant_campaign_id' => 'participant_campaign_id varchar(128)',
2575 ];
2576 }
2577
2578 /**
2579 * Get contribution sql columns.
2580 *
2581 * @return array
2582 */
2583 public function getContributionSqlColumns() {
2584 return [
2585 'civicrm_primary_id' => 'civicrm_primary_id varchar(16)',
2586 'contact_type' => 'contact_type varchar(64)',
2587 'contact_sub_type' => 'contact_sub_type varchar(255)',
2588 'do_not_email' => 'do_not_email varchar(16)',
2589 'do_not_phone' => 'do_not_phone varchar(16)',
2590 'do_not_mail' => 'do_not_mail varchar(16)',
2591 'do_not_sms' => 'do_not_sms varchar(16)',
2592 'do_not_trade' => 'do_not_trade varchar(16)',
2593 'is_opt_out' => 'is_opt_out varchar(16)',
2594 'legal_identifier' => 'legal_identifier varchar(32)',
2595 'external_identifier' => 'external_identifier varchar(64)',
2596 'sort_name' => 'sort_name varchar(128)',
2597 'display_name' => 'display_name varchar(128)',
2598 'nick_name' => 'nick_name varchar(128)',
2599 'legal_name' => 'legal_name varchar(128)',
2600 'image_url' => 'image_url longtext',
2601 'preferred_communication_method' => 'preferred_communication_method varchar(255)',
2602 'preferred_language' => 'preferred_language varchar(5)',
2603 'preferred_mail_format' => 'preferred_mail_format varchar(8)',
2604 'hash' => 'hash varchar(32)',
2605 'contact_source' => 'contact_source varchar(255)',
2606 'first_name' => 'first_name varchar(64)',
2607 'middle_name' => 'middle_name varchar(64)',
2608 'last_name' => 'last_name varchar(64)',
2609 'prefix_id' => 'prefix_id varchar(255)',
2610 'suffix_id' => 'suffix_id varchar(255)',
2611 'formal_title' => 'formal_title varchar(64)',
2612 'communication_style_id' => 'communication_style_id varchar(16)',
2613 'email_greeting_id' => 'email_greeting_id varchar(16)',
2614 'postal_greeting_id' => 'postal_greeting_id varchar(16)',
2615 'addressee_id' => 'addressee_id varchar(16)',
2616 'job_title' => 'job_title varchar(255)',
2617 'gender_id' => 'gender_id varchar(16)',
2618 'birth_date' => 'birth_date varchar(32)',
2619 'is_deceased' => 'is_deceased varchar(16)',
2620 'deceased_date' => 'deceased_date varchar(32)',
2621 'household_name' => 'household_name varchar(128)',
2622 'organization_name' => 'organization_name varchar(128)',
2623 'sic_code' => 'sic_code varchar(8)',
2624 'user_unique_id' => 'user_unique_id varchar(255)',
2625 'current_employer_id' => 'current_employer_id varchar(16)',
2626 'contact_is_deleted' => 'contact_is_deleted varchar(16)',
2627 'created_date' => 'created_date varchar(32)',
2628 'modified_date' => 'modified_date varchar(32)',
2629 'addressee' => 'addressee varchar(255)',
2630 'email_greeting' => 'email_greeting varchar(255)',
2631 'postal_greeting' => 'postal_greeting varchar(255)',
2632 'current_employer' => 'current_employer varchar(128)',
2633 'location_type' => 'location_type text',
2634 'street_address' => 'street_address varchar(96)',
2635 'street_number' => 'street_number varchar(16)',
2636 'street_number_suffix' => 'street_number_suffix varchar(8)',
2637 'street_name' => 'street_name varchar(64)',
2638 'street_unit' => 'street_unit varchar(16)',
2639 'supplemental_address_1' => 'supplemental_address_1 varchar(96)',
2640 'supplemental_address_2' => 'supplemental_address_2 varchar(96)',
2641 'supplemental_address_3' => 'supplemental_address_3 varchar(96)',
2642 'city' => 'city varchar(64)',
2643 'postal_code_suffix' => 'postal_code_suffix varchar(12)',
2644 'postal_code' => 'postal_code varchar(64)',
2645 'geo_code_1' => 'geo_code_1 varchar(32)',
2646 'geo_code_2' => 'geo_code_2 varchar(32)',
2647 'address_name' => 'address_name varchar(255)',
2648 'master_id' => 'master_id varchar(128)',
2649 'county' => 'county varchar(64)',
2650 'state_province' => 'state_province varchar(64)',
2651 'country' => 'country varchar(64)',
2652 'phone' => 'phone varchar(32)',
2653 'phone_ext' => 'phone_ext varchar(16)',
2654 'email' => 'email varchar(254)',
2655 'on_hold' => 'on_hold varchar(16)',
2656 'is_bulkmail' => 'is_bulkmail varchar(16)',
2657 'signature_text' => 'signature_text longtext',
2658 'signature_html' => 'signature_html longtext',
2659 'im_provider' => 'im_provider text',
5ebd7d09 2660 'im_screen_name' => 'im_screen_name varchar(64)',
0a3b035f 2661 'openid' => 'openid varchar(255)',
2662 'world_region' => 'world_region varchar(128)',
2663 'url' => 'url varchar(128)',
219c47d6 2664 'phone_type_id' => 'phone_type_id varchar(16)',
124f3c1b 2665 'financial_type' => 'financial_type varchar(255)',
0a3b035f 2666 'contribution_source' => 'contribution_source varchar(255)',
2667 'receive_date' => 'receive_date varchar(32)',
2668 'thankyou_date' => 'thankyou_date varchar(32)',
6e7cc0f5 2669 'contribution_cancel_date' => 'contribution_cancel_date varchar(32)',
0a3b035f 2670 'total_amount' => 'total_amount varchar(32)',
2671 'accounting_code' => 'accounting_code varchar(64)',
a0090e6b 2672 'payment_instrument' => 'payment_instrument varchar(255)',
0a3b035f 2673 'payment_instrument_id' => 'payment_instrument_id varchar(16)',
2674 'contribution_check_number' => 'contribution_check_number varchar(255)',
2675 'non_deductible_amount' => 'non_deductible_amount varchar(32)',
2676 'fee_amount' => 'fee_amount varchar(32)',
2677 'net_amount' => 'net_amount varchar(32)',
2678 'trxn_id' => 'trxn_id varchar(255)',
2679 'invoice_id' => 'invoice_id varchar(255)',
2680 'invoice_number' => 'invoice_number varchar(255)',
2681 'currency' => 'currency varchar(3)',
2682 'cancel_reason' => 'cancel_reason longtext',
2683 'receipt_date' => 'receipt_date varchar(32)',
0a3b035f 2684 'is_test' => 'is_test varchar(16)',
2685 'is_pay_later' => 'is_pay_later varchar(16)',
a0090e6b 2686 'contribution_status' => 'contribution_status varchar(255)',
0a3b035f 2687 'contribution_recur_id' => 'contribution_recur_id varchar(16)',
2688 'amount_level' => 'amount_level longtext',
2689 'contribution_note' => 'contribution_note text',
2690 'contribution_batch' => 'contribution_batch text',
2691 'contribution_campaign_title' => 'contribution_campaign_title varchar(255)',
2692 'contribution_campaign_id' => 'contribution_campaign_id varchar(128)',
0a3b035f 2693 'contribution_soft_credit_name' => 'contribution_soft_credit_name varchar(255)',
2694 'contribution_soft_credit_amount' => 'contribution_soft_credit_amount varchar(255)',
2695 'contribution_soft_credit_type' => 'contribution_soft_credit_type varchar(255)',
2696 'contribution_soft_credit_contact_id' => 'contribution_soft_credit_contact_id varchar(255)',
2697 'contribution_soft_credit_contribution_id' => 'contribution_soft_credit_contribution_id varchar(255)',
2698 ];
2699 }
2700
2701 /**
2702 * Get pledge sql columns.
2703 *
2704 * @return array
2705 */
2706 public function getPledgeSqlColumns() {
2707 return [
2708 'pledge_id' => 'pledge_id varchar(16)',
2709 'pledge_amount' => 'pledge_amount varchar(32)',
2710 'pledge_total_paid' => 'pledge_total_paid text',
2711 'pledge_create_date' => 'pledge_create_date varchar(32)',
2712 'pledge_start_date' => 'pledge_start_date text',
2713 'pledge_next_pay_date' => 'pledge_next_pay_date text',
2714 'pledge_next_pay_amount' => 'pledge_next_pay_amount text',
2715 'pledge_status' => 'pledge_status varchar(255)',
2716 'pledge_is_test' => 'pledge_is_test varchar(16)',
2717 'pledge_contribution_page_id' => 'pledge_contribution_page_id varchar(255)',
2718 'pledge_financial_type' => 'pledge_financial_type text',
2719 'pledge_frequency_interval' => 'pledge_frequency_interval varchar(255)',
2720 'pledge_frequency_unit' => 'pledge_frequency_unit varchar(255)',
2721 'pledge_currency' => 'pledge_currency text',
2722 'pledge_campaign_id' => 'pledge_campaign_id varchar(128)',
2723 'pledge_balance_amount' => 'pledge_balance_amount text',
2724 'pledge_payment_id' => 'pledge_payment_id varchar(16)',
2725 'pledge_payment_scheduled_amount' => 'pledge_payment_scheduled_amount varchar(32)',
2726 'pledge_payment_scheduled_date' => 'pledge_payment_scheduled_date varchar(32)',
2727 'pledge_payment_paid_amount' => 'pledge_payment_paid_amount text',
2728 'pledge_payment_paid_date' => 'pledge_payment_paid_date text',
2729 'pledge_payment_reminder_date' => 'pledge_payment_reminder_date varchar(32)',
2730 'pledge_payment_reminder_count' => 'pledge_payment_reminder_count varchar(16)',
2731 'pledge_payment_status' => 'pledge_payment_status varchar(255)',
2732 ];
2733 }
2734
2735 /**
2736 * Get membership sql columns.
2737 *
2738 * @return array
2739 */
2740 public function getMembershipSqlColumns() {
2741 return [
2742 'membership_type' => 'membership_type varchar(128)',
2743 'member_is_test' => 'member_is_test varchar(16)',
2744 'member_is_pay_later' => 'member_is_pay_later varchar(16)',
2745 'join_date' => 'join_date varchar(32)',
2746 'membership_start_date' => 'membership_start_date varchar(32)',
2747 'membership_end_date' => 'membership_end_date varchar(32)',
2748 'membership_source' => 'membership_source varchar(128)',
2749 'membership_status' => 'membership_status varchar(255)',
2750 'membership_id' => 'membership_id varchar(16)',
2751 'owner_membership_id' => 'owner_membership_id varchar(16)',
2752 'max_related' => 'max_related text',
2753 'membership_recur_id' => 'membership_recur_id varchar(255)',
2754 'member_campaign_id' => 'member_campaign_id varchar(128)',
2755 'member_is_override' => 'member_is_override text',
2756 'member_auto_renew' => 'member_auto_renew text',
2757 ];
2758 }
2759
a16a432a 2760 /**
2761 * Change our location types so we have some edge cases in the mix.
2762 *
2763 * - a space in the name
2764 * - name differs from label
2765 * - non-anglo char in the label (not valid in the name).
2766 */
2767 protected function diversifyLocationTypes() {
2768 $this->locationTypes['Main'] = $this->callAPISuccess('Location_type', 'get', [
2769 'name' => 'Main',
2770 'return' => 'id',
2771 'api.LocationType.Create' => ['display_name' => 'Méin'],
2772 ]);
2773 $this->locationTypes['Whare Kai'] = $this->callAPISuccess('Location_type', 'create', [
2774 'name' => 'Whare Kai',
2775 'display_name' => 'Whare Kai',
2776 ]);
2777 }
2778
12a6fdef 2779 /**
2780 * Test export components.
2781 *
2782 * Tests the exportComponents function with the provided parameters.
2783 *
2784 * This exportComponents will export a csv but it will also throw a prematureExitException
2785 * which we catch & grab the processor from.
2786 *
2787 * $this->processor is set to the export processor.
2788 *
2789 * @param $params
2790 *
2791 * @throws \CRM_Core_Exception
2792 */
2793 protected function doExportTest($params) {
2794 $this->startCapturingOutput();
2795 try {
2796 CRM_Export_BAO_Export::exportComponents(
2797 CRM_Utils_Array::value('selectAll', $params, (empty($params['fields']))),
2798 CRM_Utils_Array::value('ids', $params, []),
2799 CRM_Utils_Array::value('params', $params, []),
2800 CRM_Utils_Array::value('order', $params),
2801 CRM_Utils_Array::value('fields', $params),
2802 CRM_Utils_Array::value('moreReturnProperties', $params),
2803 CRM_Utils_Array::value('exportMode', $params, CRM_Export_Form_Select::CONTACT_EXPORT),
2804 CRM_Utils_Array::value('componentClause', $params, FALSE),
2805 CRM_Utils_Array::value('componentTable', $params),
2806 CRM_Utils_Array::value('mergeSameAddress', $params, FALSE),
2807 CRM_Utils_Array::value('mergeSameHousehold', $params, FALSE)
2808 );
2809 }
2810 catch (CRM_Core_Exception_PrematureExitException $e) {
2811 $this->processor = $e->errorData['processor'];
2812 ob_end_clean();
2813 return;
2814 }
2815 $this->fail('We expected a premature exit exception');
2816 }
2817
ef51caa8 2818}