-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21216 from demeritcowboy/import-csv-blankline
Alternate to 20131 - Avoid crash during import for blank lines in a one-column csv file
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,4 +125,34 @@ public function trimDataProvider(): array { | |
]; | ||
} | ||
|
||
/** | ||
* Test only one column and a blank line at the end, because | ||
* fgetcsv will return the blank lines as array(0 => NULL) which is an | ||
* edge case. Note if it has more than one column then the blank line gets | ||
* skipped because of some checking for column-count matches in the import, | ||
* and so you don't hit the current fail. | ||
*/ | ||
public function testBlankLineAtEnd() { | ||
$dataSource = new CRM_Import_DataSource_CSV(); | ||
$params = [ | ||
'uploadFile' => [ | ||
'name' => __DIR__ . '/blankLineAtEnd.csv', | ||
], | ||
'skipColumnHeader' => TRUE, | ||
]; | ||
|
||
// Get the PEAR::DB object | ||
$dao = new CRM_Core_DAO(); | ||
$db = $dao->getDatabaseConnection(); | ||
|
||
$form = new CRM_Contact_Import_Form_DataSource(); | ||
$form->controller = new CRM_Contact_Import_Controller(); | ||
|
||
$dataSource->postProcess($params, $db, $form); | ||
$tableName = $form->get('importTableName'); | ||
$json = json_encode(CRM_Core_DAO::singleValueQuery("SELECT email FROM $tableName")); | ||
$this->assertEquals('"[email protected]"', $json); | ||
CRM_Core_DAO::executeQuery("DROP TABLE $tableName"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[email protected] | ||
|