$this->controller->resetPage($this->_name);
return;
}
-
- $mapper = array();
- $mapperKeys = array();
$mapperKeys = $this->controller->exportValue($this->_name, 'mapper');
- $mapperKeysMain = array();
+
+ $parser = $this->submit($params, $mapperKeys);
+
+ // add all the necessary variables to the form
+ $parser->set($this);
+ }
+
+ /**
+ * Format custom field name.
+ *
+ * Combine group and field name to avoid conflict.
+ *
+ * @param array $fields
+ *
+ * @return array
+ */
+ public function formatCustomFieldName(&$fields) {
+ //CRM-2676, replacing the conflict for same custom field name from different custom group.
+ $fieldIds = $formattedFieldNames = array();
+ foreach ($fields as $key => $value) {
+ if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) {
+ $fieldIds[] = $customFieldId;
+ }
+ }
+
+ if (!empty($fieldIds) && is_array($fieldIds)) {
+ $groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldIds);
+
+ if (!empty($groupTitles)) {
+ foreach ($groupTitles as $fId => $values) {
+ $key = "custom_{$fId}";
+ $groupTitle = $values['groupTitle'];
+ $formattedFieldNames[$key] = $fields[$key] . ' :: ' . $groupTitle;
+ }
+ }
+ }
+
+ return $formattedFieldNames;
+ }
+
+ /**
+ * Main submit function.
+ *
+ * Extracted to add testing & start refactoring.
+ *
+ * @param $params
+ * @param $mapperKeys
+ *
+ * @return \CRM_Contact_Import_Parser_Contact
+ */
+ public function submit($params, $mapperKeys) {
+ $mapper = $mapperKeysMain = array();
$phoneTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id');
$imProviders = CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id');
$this->get('contactSubType'),
$this->get('dedupe')
);
-
- // add all the necessary variables to the form
- $parser->set($this);
- }
-
- /**
- * Format custom field name.
- *
- * Combine group and field name to avoid conflict.
- *
- * @param array $fields
- *
- * @return array
- */
- public function formatCustomFieldName(&$fields) {
- //CRM-2676, replacing the conflict for same custom field name from different custom group.
- $fieldIds = $formattedFieldNames = array();
- foreach ($fields as $key => $value) {
- if ($customFieldId = CRM_Core_BAO_CustomField::getKeyID($key)) {
- $fieldIds[] = $customFieldId;
- }
- }
-
- if (!empty($fieldIds) && is_array($fieldIds)) {
- $groupTitles = CRM_Core_BAO_CustomGroup::getGroupTitles($fieldIds);
-
- if (!empty($groupTitles)) {
- foreach ($groupTitles as $fId => $values) {
- $key = "custom_{$fId}";
- $groupTitle = $values['groupTitle'];
- $formattedFieldNames[$key] = $fields[$key] . ' :: ' . $groupTitle;
- }
- }
- }
-
- return $formattedFieldNames;
+ return $parser;
}
}
--- /dev/null
+<?php
+/*
++--------------------------------------------------------------------+
+| CiviCRM version 4.7 |
++--------------------------------------------------------------------+
+| Copyright CiviCRM LLC (c) 2004-2017 |
++--------------------------------------------------------------------+
+| This file is a part of CiviCRM. |
+| |
+| CiviCRM is free software; you can copy, modify, and distribute it |
+| under the terms of the GNU Affero General Public License |
+| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+| |
+| CiviCRM is distributed in the hope that it will be useful, but |
+| WITHOUT ANY WARRANTY; without even the implied warranty of |
+| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+| See the GNU Affero General Public License for more details. |
+| |
+| You should have received a copy of the GNU Affero General Public |
+| License and the CiviCRM Licensing Exception along |
+| with this program; if not, contact CiviCRM LLC |
+| at info[AT]civicrm[DOT]org. If you have questions about the |
+| GNU Affero General Public License or the licensing of CiviCRM, |
+| see the CiviCRM license FAQ at http://civicrm.org/licensing |
++--------------------------------------------------------------------+
+ */
+
+/**
+ * @file
+ * File for the CRM_Contact_Import_Form_MapFieldTest class.
+ */
+
+/**
+ * Test contact import mapfield.
+ *
+ * @package CiviCRM
+ * @group headless
+ */
+class CRM_Contact_Import_Form_MapFieldTest extends CiviUnitTestCase {
+
+ /**
+ * Test the form loads without error / notice and mappings are assigned.
+ *
+ * (Added in conjunction with fixed noting on mapping assignment).
+ */
+ public function testSubmit() {
+ $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());
+ }
+
+}