protected $masterAddressID;
public function tearDown() {
- $this->quickCleanup(['civicrm_contact', 'civicrm_email', 'civicrm_address']);
+ $this->quickCleanup(['civicrm_contact', 'civicrm_email', 'civicrm_address', 'civicrm_relationship']);
$this->quickCleanUpFinancialEntities();
parent::tearDown();
}
$this->assertEquals('Big campaign,', CRM_Core_DAO::singleValueQuery("SELECT GROUP_CONCAT(contribution_campaign_title) FROM {$tableName}"));
}
+ /**
+ * Test exporting relationships.
+ *
+ * This is to ensure that CRM-13995 remains fixed.
+ */
+ public function testExportRelationshipsMergeToHousehold() {
+ list($householdID, $houseHoldTypeID) = $this->setUpHousehold();
+
+ $selectedFields = [
+ ['Individual', $houseHoldTypeID . '_a_b', 'state_province', ''],
+ ['Individual', $houseHoldTypeID . '_a_b', 'city', ''],
+ ['Individual', 'city', ''],
+ ['Individual', 'state_province', ''],
+ ];
+ list($tableName) = CRM_Export_BAO_Export::exportComponents(
+ FALSE,
+ $this->contactIDs,
+ [],
+ NULL,
+ $selectedFields,
+ NULL,
+ CRM_Export_Form_Select::CONTACT_EXPORT,
+ "contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
+ NULL,
+ FALSE,
+ TRUE,
+ [
+ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT,
+ 'suppress_csv_for_testing' => TRUE,
+ ]
+ );
+ $dao = CRM_Core_DAO::executeQuery("SELECT * FROM {$tableName}");
+ while ($dao->fetch()) {
+ $this->assertEquals('Portland', $dao->city);
+ $this->assertEquals('ME', $dao->state_province);
+ $this->assertEquals($householdID, $dao->civicrm_primary_id);
+ $this->assertEquals($householdID, $dao->civicrm_primary_id);
+ }
+
+ }
+
+ /**
+ * Test exporting relationships.
+ */
+ public function testExportRelationshipsMergeToHouseholdAllFields() {
+ $this->markTestIncomplete('Does not yet work under CI due to mysql limitation (number of columns in table). Works on some boxes');
+ list($householdID) = $this->setUpHousehold();
+ list($tableName) = CRM_Export_BAO_Export::exportComponents(
+ FALSE,
+ $this->contactIDs,
+ [],
+ NULL,
+ NULL,
+ NULL,
+ CRM_Export_Form_Select::CONTACT_EXPORT,
+ "contact_a.id IN (" . implode(",", $this->contactIDs) . ")",
+ NULL,
+ FALSE,
+ TRUE,
+ [
+ 'exportOption' => CRM_Export_Form_Select::CONTACT_EXPORT,
+ 'suppress_csv_for_testing' => TRUE,
+ ]
+ );
+ $dao = CRM_Core_DAO::executeQuery("SELECT * FROM {$tableName}");
+ while ($dao->fetch()) {
+ $this->assertEquals('Portland', $dao->city);
+ $this->assertEquals('ME', $dao->state_province);
+ $this->assertEquals($householdID, $dao->civicrm_primary_id);
+ $this->assertEquals($householdID, $dao->civicrm_primary_id);
+ $this->assertEquals('Unit Test Household', $dao->addressee);
+ $this->assertEquals('Unit Test Household', $dao->display_name);
+ }
+ }
+
/**
* Test master_address_id field.
*/
CRM_Core_DAO::executeQuery($sql);
}
+ /**
+ * @return array
+ */
+ protected function setUpHousehold() {
+ $this->setUpContactExportData();
+ $householdID = $this->householdCreate([
+ 'api.Address.create' => [
+ 'city' => 'Portland',
+ 'state_province_id' => 'Maine',
+ 'location_type_id' => 'Home'
+ ]
+ ]);
+
+ $relationshipTypes = $this->callAPISuccess('RelationshipType', 'get', [])['values'];
+ $houseHoldTypeID = NULL;
+ foreach ($relationshipTypes as $id => $relationshipType) {
+ if ($relationshipType['name_a_b'] === 'Household Member of') {
+ $houseHoldTypeID = $relationshipType['id'];
+ }
+ }
+ $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $this->contactIDs[0],
+ 'contact_id_b' => $householdID,
+ 'relationship_type_id' => $houseHoldTypeID,
+ ]);
+ $this->callAPISuccess('Relationship', 'create', [
+ 'contact_id_a' => $this->contactIDs[1],
+ 'contact_id_b' => $householdID,
+ 'relationship_type_id' => $houseHoldTypeID,
+ ]);
+ return array($householdID, $houseHoldTypeID);
+ }
+
}