From 8fd37b20aba904d0b8e7faa12daf408e71ffbb51 Mon Sep 17 00:00:00 2001 From: eileenmcnaugton Date: Mon, 19 Oct 2015 11:18:11 +1300 Subject: [PATCH] CRM-17275 preliminary tidy-ups, remove unused vars & fix comments & re-use test code Conflicts: CRM/Contact/Import/Parser.php --- CRM/Contact/Import/Parser.php | 8 +-- .../CRM/Contact/Import/Parser/ContactTest.php | 64 ++++++++++--------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/CRM/Contact/Import/Parser.php b/CRM/Contact/Import/Parser.php index 4aae2ad82a..31ec9982ca 100644 --- a/CRM/Contact/Import/Parser.php +++ b/CRM/Contact/Import/Parser.php @@ -91,10 +91,10 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { * @param string $statusFieldName * @param int $onDuplicate * @param int $statusID - * @param null $totalRowCount + * @param int $totalRowCount * @param bool $doGeocodeAddress * @param int $timeout - * @param null $contactSubType + * @param string $contactSubType * @param int $dedupeRuleGroupID * * @return mixed @@ -145,8 +145,6 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { $this->_conflicts = array(); $this->_unparsedAddresses = array(); - $status = ''; - $this->_tableName = $tableName; $this->_primaryKeyName = $primaryKeyName; $this->_statusFieldName = $statusFieldName; @@ -196,8 +194,6 @@ abstract class CRM_Contact_Import_Parser extends CRM_Import_Parser { $this->_rowCount++; /* trim whitespace around the values */ - - $empty = TRUE; foreach ($values as $k => $v) { $values[$k] = trim($v, " \t\r\n"); } diff --git a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php index 223ddb7e49..0a63081955 100644 --- a/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php +++ b/tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php @@ -48,19 +48,14 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase { } /** - * Test that the import parser will do an update when external identifier is set. + * Test import parser will update based on a rule match. + * + * In this case the contact has no external identifier. * * @throws \Exception */ public function testImportParserWithUpdateWithoutExternalIdentifier() { - $originalValues = array( - 'first_name' => 'Bill', - 'last_name' => 'Gates', - 'email' => 'bill.gates@microsoft.com', - 'nick_name' => 'Billy-boy', - ); - $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); - $result = $this->callAPISuccessGetSingle('Contact', $originalValues); + list($originalValues, $result) = $this->setUpBaseContact(); $originalValues['nick_name'] = 'Old Bill'; $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $originalValues['id'] = $result['id']; @@ -69,43 +64,33 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase { } /** - * Test that the import parser will do an update when external identifier is set. + * Test import parser will update contacts with an external identifier. + * + * This is the basic test where the identifier matches the import parameters. * * @throws \Exception */ public function testImportParserWithUpdateWithExternalIdentifier() { - $originalValues = array( - 'first_name' => 'Bill', - 'last_name' => 'Gates', - 'email' => 'bill.gates@microsoft.com', - 'external_identifier' => 'windows', - 'nick_name' => 'Billy-boy', - ); - $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); - $result = $this->callAPISuccessGetSingle('Contact', $originalValues); + list($originalValues, $result) = $this->setUpBaseContact(array('external_identifier' => 'windows')); + $this->assertEquals($result['id'], CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', 'windows', 'id', 'external_identifier', TRUE)); $this->assertEquals('windows', $result['external_identifier']); + $originalValues['nick_name'] = 'Old Bill'; $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); $originalValues['id'] = $result['id']; + $this->assertEquals('Old Bill', $this->callAPISuccessGetValue('Contact', array('id' => $result['id'], 'return' => 'nick_name'))); $this->callAPISuccessGetSingle('Contact', $originalValues); } /** - * Test that the import parser updates when a new external identifier is set. + * Test that the import parser adds the external identifier where none is set. * * @throws \Exception */ - public function testImportParserWithUpdateWithNewExternalIdentifier() { - $originalValues = array( - 'first_name' => 'Bill', - 'last_name' => 'Gates', - 'email' => 'bill.gates@microsoft.com', - 'nick_name' => 'Billy-boy', - ); - $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); - $result = $this->callAPISuccessGetSingle('Contact', $originalValues); + public function testImportParserWithUpdateWithNoExternalIdentifier() { + list($originalValues, $result) = $this->setUpBaseContact(); $originalValues['nick_name'] = 'Old Bill'; $originalValues['external_identifier'] = 'windows'; $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); @@ -132,4 +117,25 @@ class CRM_Contact_Imports_Parser_ContactTest extends CiviUnitTestCase { $this->assertEquals($expectedResult, $parser->import($onDuplicateAction, $values)); } + /** + * Set up the underlying contact. + * + * @param array $params + * Optional extra parameters to set. + * + * @return array + * @throws \Exception + */ + protected function setUpBaseContact($params = array()) { + $originalValues = array_merge(array( + 'first_name' => 'Bill', + 'last_name' => 'Gates', + 'email' => 'bill.gates@microsoft.com', + 'nick_name' => 'Billy-boy', + ), $params); + $this->runImport($originalValues, CRM_Import_Parser::DUPLICATE_UPDATE, CRM_Import_Parser::VALID); + $result = $this->callAPISuccessGetSingle('Contact', $originalValues); + return array($originalValues, $result); + } + } -- 2.25.1