getFormObject('CRM_Contact_Import_Form_MapField'); $form->set('contactType', CRM_Import_Parser::CONTACT_INDIVIDUAL); $form->_columnNames = ['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'], ['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(['civicrm_mapping', 'civicrm_mapping_field']); } /** * Get data to pass through submit function. * * @return array */ public function getSubmitData() { return [ 'basic_data' => [ [ 'saveMappingName' => '', 'saveMappingDesc' => '', ], [ 0 => [0 => 'do_not_import'], 1 => [0 => 'first_name'], 2 => [0 => 'last_name'], 3 => [0 => 'street_address', 1 => 2], ], ], 'save_mapping' => [ [ 'saveMappingName' => 'new mapping', 'saveMappingDesc' => 'save it', 'saveMapping' => 1, ], [ 0 => [0 => 'do_not_import'], 1 => [0 => 'first_name'], 2 => [0 => 'last_name'], 3 => [0 => 'street_address', 1 => 2], ], [ ['entity' => 'mapping', 'count' => 1, 'values' => ['name' => 'new mapping']], [ 'entity' => 'mapping_field', 'count' => 4, 'values' => [], 'result' => [ 0 => ['name' => '- do not import -'], 1 => ['name' => 'First Name'], 2 => ['name' => 'Last Name'], 3 => ['name' => 'Street Address', 'location_type_id' => 2], ], ], ], ], ]; } /** * Instantiate form object * * @param string $class * @param array $formValues * @param string $pageName * @return \CRM_Core_Form * @throws \CRM_Core_Exception */ public function getFormObject($class, $formValues = [], $pageName = '') { $form = parent::getFormObject($class); $contactFields = CRM_Contact_BAO_Contact::importableFields(); $fields = []; foreach ($contactFields as $name => $field) { $fields[$name] = $field['title']; } $form->set('fields', $fields); return $form; } }