From b7d6b1fa46feee35b89b35e51924aae59ea00826 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 7 Oct 2019 10:34:21 +0200 Subject: [PATCH] dev/core#1283 fix inability to export more than 255 chars --- CRM/Core/BAO/CustomField.php | 3 +++ tests/phpunit/CRM/Core/BAO/CustomFieldTest.php | 3 ++- tests/phpunit/CRM/Export/BAO/ExportTest.php | 9 +++++++-- tests/phpunit/CRMTraits/Custom/CustomDataTrait.php | 1 + 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CRM/Core/BAO/CustomField.php b/CRM/Core/BAO/CustomField.php index 26907960b8..e5c013ddf7 100644 --- a/CRM/Core/BAO/CustomField.php +++ b/CRM/Core/BAO/CustomField.php @@ -596,6 +596,9 @@ class CRM_Core_BAO_CustomField extends CRM_Core_DAO_CustomField { ) { continue; } + if (!empty($values['text_length'])) { + $values['maxlength'] = (int) $values['text_length']; + } /* generate the key for the fields array */ diff --git a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php index ccb84063d0..53c1456ea6 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php @@ -514,7 +514,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { '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', @@ -537,6 +537,7 @@ class CRM_Core_BAO_CustomFieldTest extends CiviUnitTestCase { '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'), diff --git a/tests/phpunit/CRM/Export/BAO/ExportTest.php b/tests/phpunit/CRM/Export/BAO/ExportTest.php index 891d5926e2..537ed560bb 100644 --- a/tests/phpunit/CRM/Export/BAO/ExportTest.php +++ b/tests/phpunit/CRM/Export/BAO/ExportTest.php @@ -682,9 +682,14 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { $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'], ]); @@ -699,7 +704,7 @@ class CRM_Export_BAO_ExportTest extends CiviUnitTestCase { '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']); } diff --git a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php index a90b465d6f..002000891b 100644 --- a/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php +++ b/tests/phpunit/CRMTraits/Custom/CustomDataTrait.php @@ -195,6 +195,7 @@ trait CRMTraits_Custom_CustomDataTrait { 'is_required' => 1, 'sequential' => 1, 'is_searchable' => 1, + 'text_length' => 300, ], $params); return $this->callAPISuccess('CustomField', 'create', $params)['values'][0]; -- 2.25.1