Skip to content

Commit

Permalink
dev/core#1283 fix inability to export more than 255 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 7, 2019
1 parent 7aed0a9 commit b7d6b1f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,9 @@ public static function getFieldsForImport(
) {
continue;
}
if (!empty($values['text_length'])) {
$values['maxlength'] = (int) $values['text_length'];
}

/* generate the key for the fields array */

Expand Down
3 changes: 2 additions & 1 deletion tests/phpunit/CRM/Core/BAO/CustomFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public function testGetFieldsForImport() {
'import' => 1,
'custom_field_id' => $this->getCustomFieldID('text'),
'options_per_line' => NULL,
'text_length' => NULL,
'text_length' => 300,
'data_type' => 'String',
'html_type' => 'Text',
'is_search_range' => '0',
Expand All @@ -537,6 +537,7 @@ public function testGetFieldsForImport() {
'where' => 'civicrm_value_custom_group_' . $customGroupID . '.enter_text_here_' . $this->getCustomFieldID('text'),
'extends_table' => 'civicrm_contact',
'search_table' => 'contact_a',
'maxlength' => 300,
],
$this->getCustomFieldName('select_string') => [
'name' => $this->getCustomFieldName('select_string'),
Expand Down
9 changes: 7 additions & 2 deletions tests/phpunit/CRM/Export/BAO/ExportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,9 +682,14 @@ public function testExportCustomData() {
$this->setUpContactExportData();
$this->entity = 'Contact';
$this->createCustomGroupWithFieldsOfAllTypes();
$longString = 'Blah';
for ($i = 0; $i < 70; $i++) {
$longString .= 'Blah';
}

$this->callAPISuccess('Contact', 'create', [
'id' => $this->contactIDs[1],
$this->getCustomFieldName('text') => 'BlahdeBlah',
$this->getCustomFieldName('text') => $longString,
$this->getCustomFieldName('country') => 'LA',
'api.Address.create' => ['location_type_id' => 'Billing', 'city' => 'Waipu'],
]);
Expand All @@ -699,7 +704,7 @@ public function testExportCustomData() {
'ids' => [$this->contactIDs[1]],
]);
$row = $this->csv->fetchOne();
$this->assertEquals('BlahdeBlah', $row['Enter text here']);
$this->assertEquals($longString, $row['Enter text here']);
$this->assertEquals('Waipu', $row['Billing-City']);
$this->assertEquals("Lao People's Democratic Republic", $row['Country']);
}
Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/CRMTraits/Custom/CustomDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ protected function createTextCustomField($params = []) {
'is_required' => 1,
'sequential' => 1,
'is_searchable' => 1,
'text_length' => 300,
], $params);

return $this->callAPISuccess('CustomField', 'create', $params)['values'][0];
Expand Down

0 comments on commit b7d6b1f

Please sign in to comment.