ts('For Duplicate Contacts')
);
- $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type',
- 'Import Contact',
- 'name'
- ));
+ $mappingArray = CRM_Core_BAO_Mapping::getMappings('Import Contact');
$this->assign('savedMapping', $mappingArray);
$this->addElement('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
/**
* Get the list of mappings.
*
- * @param string $mappingTypeId
- * Mapping type id.
+ * @param string $mappingType
+ * Mapping type name.
*
* @return array
- * array of mapping name
+ * Array of mapping names, keyed by id.
*/
- public static function getMappings($mappingTypeId) {
+ public static function getMappings($mappingType) {
+ $result = civicrm_api3('Mapping', 'get', array('mapping_type_id' => $mappingType, 'options' => array('limit' => 1, 'sort' => 'name')));
$mapping = array();
- $mappingDAO = new CRM_Core_DAO_Mapping();
- $mappingDAO->mapping_type_id = $mappingTypeId;
- $mappingDAO->find();
- while ($mappingDAO->fetch()) {
- $mapping[$mappingDAO->id] = $mappingDAO->name;
+ foreach ($result['values'] as $key => $value) {
+ $mapping[$key] = $value['name'];
}
-
return $mapping;
}
$mappingTypeId = CRM_Core_OptionGroup::getValue('mapping_type', $exportType, 'name');
$this->set('mappingTypeId', $mappingTypeId);
- $mappings = CRM_Core_BAO_Mapping::getMappings($mappingTypeId);
+ $mappings = CRM_Core_BAO_Mapping::getMappings($exportType);
if (!empty($mappings)) {
$this->add('select', 'mapping', ts('Use Saved Field Mapping'), array('' => '-select-') + $mappings);
}
$this->setDefaults(array('fieldSeparator' => $config->fieldSeparator));
//get the saved mapping details
- $mappingArray = CRM_Core_BAO_Mapping::getMappings(CRM_Core_OptionGroup::getValue('mapping_type',
- 'Import ' . static::IMPORT_ENTITY,
- 'name'
- ));
+ $mappingArray = CRM_Core_BAO_Mapping::getMappings('Import ' . static::IMPORT_ENTITY);
$this->assign('savedMapping', $mappingArray);
$this->add('select', 'savedMapping', ts('Mapping Option'), array('' => ts('- select -')) + $mappingArray);
--- /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_DataSourceTest class.
+ */
+
+/**
+ * Test contact import datasource.
+ *
+ * @package CiviCRM
+ * @group headless
+ */
+class CRM_Contact_Import_Form_DataSourceTest extends CiviUnitTestCase {
+
+ /**
+ * Test the form loads without error / notice and mappings are assigned.
+ *
+ * (Added in conjunction with fixed noting on mapping assignment).
+ */
+ public function testBuildForm() {
+ $this->callAPISuccess('Mapping', 'create', array('name' => 'Well dressed ducks', 'mapping_type_id' => 'Import Contact'));
+ $form = $this->getFormObject('CRM_Contact_Import_Form_DataSource');
+ $form->buildQuickForm();
+ $this->assertEquals(array(1 => 'Well dressed ducks'), CRM_Core_Smarty::singleton()->get_template_vars('savedMapping'));
+ }
+
+}
}
}
+
+ /**
+ * Instantiate form object.
+ *
+ * We need to instantiate the form to run preprocess, which means we have to trick it about the request method.
+ *
+ * @param string $class
+ * Name of form class.
+ *
+ * @return \CRM_Core_Form
+ */
+ public function getFormObject($class) {
+ $form = new $class();
+ $_SERVER['REQUEST_METHOD'] = 'GET';
+ $form->controller = new CRM_Core_Controller();
+ return $form;
+ }
+
}