public function defaultFromColumnName($columnName, $patterns) {
if (!preg_match('/^[a-z0-9 ]$/i', $columnName)) {
- if ($columnKey = array_search($columnName, $this->_mapperFields)) {
+ if ($columnKey = array_search($columnName, $this->getFieldTitles())) {
$this->_fieldUsed[$columnKey] = TRUE;
return $columnKey;
}
];
}
+ /**
+ * Test the MapField function getting defaults from column names.
+ *
+ * @dataProvider getHeaderMatchDataProvider
+ *
+ * @throws \CiviCRM_API3_Exception
+ * @throws \CRM_Core_Exception
+ */
+ public function testDefaultFromColumnNames($columnHeader, $mapsTo) {
+ $this->setUpMapFieldForm();
+ $this->assertEquals($mapsTo, $this->form->defaultFromColumnName($columnHeader, $this->getHeaderPatterns()));
+ }
+
+ /**
+ * Get data to use for default from column names.
+ *
+ * @return array
+ */
+ public function getHeaderMatchDataProvider() {
+ return [
+ ['Contact Id', 'id'],
+ ['Contact ID', 'id'],
+ ['contact id', 'id'],
+ ['contact_id', 'id'],
+ // Yes, really... id wins the day here.
+ ['external id', 'id'],
+ ['external ident', 'external_identifier'],
+ ['external idg', 'external_identifier'],
+ ];
+ }
+
/**
* Wrapper for loadSavedMapping.
*