From e119ba7ddb7b931b54286f34e7ef62b855c37a02 Mon Sep 17 00:00:00 2001 From: eileen Date: Thu, 5 Sep 2019 15:21:42 +1200 Subject: [PATCH] Add test for getting columns from header --- CRM/Contact/Import/Form/MapField.php | 2 +- .../CRM/Contact/Import/Form/MapFieldTest.php | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index 69f111bbc2..82aa20167d 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -70,7 +70,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { 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; } diff --git a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php index 50ebd39fcb..927833c5cb 100644 --- a/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php +++ b/tests/phpunit/CRM/Contact/Import/Form/MapFieldTest.php @@ -322,6 +322,37 @@ document.forms.MapField['mapper[0][3]'].style.display = 'none';\n", ]; } + /** + * 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. * -- 2.25.1