From 1de1c868851b91cf02fb677ebc65fa31e3120958 Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Sat, 17 Aug 2019 14:42:33 +1000 Subject: [PATCH] dev/core#1186 add in unit test to lock in fix from dmeritcowboy in #15055 --- .../phpunit/CRM/Core/BAO/CustomFieldTest.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php index 1867cabe2ecf..ccb84063d02f 100644 --- a/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php +++ b/tests/phpunit/CRM/Core/BAO/CustomFieldTest.php @@ -675,4 +675,27 @@ public function testBulkCreate() { $this->assertContains('KEY `INDEX_my_text` (`my_text`)', $dao->Create_Table); } + /** + * Check that outputting the display value for a file field with No description doesn't generate error + */ + public function testFileDisplayValueNoDescription() { + $customGroup = $this->customGroupCreate([ + 'extends' => 'Individual', + 'title' => 'Test Contact File Custom Group', + ]); + $fileField = $this->customFieldCreate([ + 'custom_group_id' => $customGroup['id'], + 'data_type' => 'File', + 'html_type' => 'File', + 'default_value' => '', + ]); + $filePath = Civi::paths()->getPath('[civicrm.files]/custom/test_file.txt'); + $file = $this->callAPISuccess('File', 'create', [ + 'uri' => $filePath, + ]); + $individual = $this->individualCreate(['custom_' . $fileField['id'] => $file['id']]); + $expectedDisplayValue = CRM_Core_BAO_File::paperIconAttachment('*', $file['id'])[$file['id']]; + $this->assertEquals($expectedDisplayValue, CRM_Core_BAO_CustomField::displayValue($file['id'], $fileField['id'])); + } + }