$mappingParams = array(
'name' => $params['saveMappingName'],
'description' => $params['saveMappingDesc'],
- 'mapping_type_id' => CRM_Core_OptionGroup::getValue('mapping_type',
- 'Import Contact',
- 'name'
- ),
+ 'mapping_type_id' => 'Import Contact',
);
- $saveMapping = CRM_Core_BAO_Mapping::add($mappingParams);
+ $saveMapping = civicrm_api3('Mapping', 'create', $mappingParams);
- $locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$contactType = $this->get('contactType');
switch ($contactType) {
case CRM_Import_Parser::CONTACT_INDIVIDUAL:
for ($i = 0; $i < $this->_columnCount; $i++) {
$saveMappingFields = new CRM_Core_DAO_MappingField();
- $saveMappingFields->mapping_id = $saveMapping->id;
+ $saveMappingFields->mapping_id = $saveMapping['id'];
$saveMappingFields->contact_type = $cType;
$saveMappingFields->column_number = $i;
}
else {
$saveMappingFields->name = $mapper[$i];
- $location_id = array_keys($locationTypes, $locations[$i]);
+ $locationTypeID = $parserParameters['mapperLocType'][$i];
// to get phoneType id and provider id separately
// before saving mappingFields of phone and IM, CRM-3140
if (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'url') {
elseif (CRM_Utils_Array::value('0', $mapperKeys[$i]) == 'im') {
$saveMappingFields->im_provider_id = isset($mapperKeys[$i][2]) ? $mapperKeys[$i][2] : NULL;
}
- $saveMappingFields->location_type_id = isset($location_id[0]) ? $location_id[0] : NULL;
+ $saveMappingFields->location_type_id = is_numeric($locationTypeID) ? $locationTypeID : NULL;
}
$saveMappingFields->relationship_type_id = NULL;
}
* Test the form loads without error / notice and mappings are assigned.
*
* (Added in conjunction with fixed noting on mapping assignment).
+ *
+ * @dataProvider getSubmitData
+ *
+ * @param array $params
+ * @param array $mapper
+ * @param array $expecteds
*/
- public function testSubmit() {
+ public function testSubmit($params, $mapper, $expecteds = array()) {
+ CRM_Core_DAO::executeQuery("CREATE TABLE IF NOT EXISTS civicrm_import_job_xxx (`nada` text, `first_name` text, `last_name` text, `address` text) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci");
$form = $this->getFormObject('CRM_Contact_Import_Form_MapField');
$form->set('contactType', CRM_Import_Parser::CONTACT_INDIVIDUAL);
- $form->set('fields', array());
- $form->_columnNames = array();
- $form->_importTableName = 'civicrm_cache';
- $form->submit(array(), array());
+ $form->_columnNames = array('nada', 'first_name', 'last_name', 'address');
+ $form->set('importTableName', 'civicrm_import_job_xxx');
+ $form->preProcess();
+ $form->submit($params, $mapper);
+
+ CRM_Core_DAO::executeQuery("DROP TABLE civicrm_import_job_xxx");
+ if (!empty($expecteds)) {
+ foreach ($expecteds as $expected) {
+ $result = $this->callAPISuccess($expected['entity'], 'get', array_merge($expected['values'], array('sequential' => 1)));
+ $this->assertEquals($expected['count'], $result['count']);
+ if (isset($expected['result'])) {
+ foreach ($expected['result'] as $key => $expectedValues) {
+ foreach ($expectedValues as $valueKey => $value) {
+ $this->assertEquals($value, $result['values'][$key][$valueKey]);
+ }
+ }
+ }
+ }
+ }
+ $this->quickCleanup(array('civicrm_mapping', 'civicrm_mapping_field'));
+ }
+
+ /**
+ * Get data to pass through submit function.
+ *
+ * @return array
+ */
+ public function getSubmitData() {
+ return array(
+ 'basic_data' => array(
+ array(
+ 'saveMappingName' => '',
+ 'saveMappingDesc' => '',
+ ),
+ array(
+ 0 => array(0 => 'do_not_import'),
+ 1 => array(0 => 'first_name'),
+ 2 => array(0 => 'last_name'),
+ 3 => array(0 => 'street_address', 1 => 2),
+ ),
+ ),
+ 'save_mapping' => array(
+ array(
+ 'saveMappingName' => 'new mapping',
+ 'saveMappingDesc' => 'save it',
+ 'saveMapping' => 1,
+ ),
+ array(
+ 0 => array(0 => 'do_not_import'),
+ 1 => array(0 => 'first_name'),
+ 2 => array(0 => 'last_name'),
+ 3 => array(0 => 'street_address', 1 => 2),
+ ),
+ array(
+ array('entity' => 'mapping', 'count' => 1, 'values' => array('name' => 'new mapping')),
+ array(
+ 'entity' =>
+ 'mapping_field',
+ 'count' => 4,
+ 'values' => array(),
+ 'result' => array(
+ 0 => array('name' => '- do not import -'),
+ 1 => array('name' => 'First Name'),
+ 2 => array('name' => 'Last Name'),
+ 3 => array('name' => 'Street Address', 'location_type_id' => 2),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Instantiate form object
+ *
+ * @param string $class
+ * @return \CRM_Core_Form
+ */
+ public function getFormObject($class) {
+ $form = parent::getFormObject($class);
+ $contactFields = CRM_Contact_BAO_Contact::importableFields();
+ $fields = array();
+ foreach ($contactFields as $name => $field) {
+ $fields[$name] = $field['title'];
+ }
+ $form->set('fields', $fields);
+ return $form;
}
}