From: demeritcowboy Date: Tue, 21 Jan 2020 22:37:41 +0000 (-0500) Subject: wrong linebreaks when activity type label is changed X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=b819b81a9162a53fab0e5ea97bb833ddbfff39eb;p=civicrm-core.git wrong linebreaks when activity type label is changed --- diff --git a/CRM/Activity/Form/Activity.php b/CRM/Activity/Form/Activity.php index 889901a566..a3d6f4a5d6 100644 --- a/CRM/Activity/Form/Activity.php +++ b/CRM/Activity/Form/Activity.php @@ -42,7 +42,10 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task { public $_activityTypeId; /** - * The name of activity type. + * The label of the activity type. + * Unfortunately this variable is called Name but don't want to change it + * since it's public and might be commonly used in customized code. See also + * activityTypeNameAndLabel used in the smarty template. * * @var string */ diff --git a/templates/CRM/Activity/Form/Activity.tpl b/templates/CRM/Activity/Form/Activity.tpl index 5b2e22a499..b56c202ad7 100644 --- a/templates/CRM/Activity/Form/Activity.tpl +++ b/templates/CRM/Activity/Form/Activity.tpl @@ -134,13 +134,11 @@ {$form.details.label} - {* activityTypeName means label here not name, but it should be name (dev/core#1116-fixme) *} - {if $activityTypeName eq "Print PDF Letter"} + {if $activityTypeNameAndLabel.machineName eq "Print PDF Letter"} {$form.details.html} - {* activityTypeName means label here not name, but it should be name (dev/core#1116-fixme) *} - {elseif $activityTypeName eq "Inbound Email"} + {elseif $activityTypeNameAndLabel.machineName eq "Inbound Email"} {$form.details.html|crmStripAlternatives|nl2br} diff --git a/tests/phpunit/CRM/Activity/Form/ActivityTest.php b/tests/phpunit/CRM/Activity/Form/ActivityTest.php index 6fceb9a701..e65c333d7e 100644 --- a/tests/phpunit/CRM/Activity/Form/ActivityTest.php +++ b/tests/phpunit/CRM/Activity/Form/ActivityTest.php @@ -252,4 +252,90 @@ class CRM_Activity_Form_ActivityTest extends CiviUnitTestCase { $this->callAPISuccess('option_value', 'delete', ['id' => $result['id']]); } + /** + * Test that inbound email is still treated properly if you change the label. + * I'm not crazy about the strategy used in this test but I can't see another + * way to do it. + */ + public function testInboundEmailDisplaysWithLinebreaks() { + // Change label + $inbound_email = $this->callAPISuccess('OptionValue', 'getsingle', [ + 'option_group_id' => 'activity_type', + 'name' => 'Inbound Email', + ]); + $this->callAPISuccess('OptionValue', 'create', [ + 'id' => $inbound_email['id'], + 'label' => 'Probably Spam', + ]); + + // Fake an inbound email and store it + + $messageBody = <<Hi,
+

+
Wassup!?!?
+

+
Let's check if the output when viewing the form has legible line breaks in the output.
+

+
Thanks!
+-ALTERNATIVE END- +ENDBODY; + + $activity = $this->activityCreate([ + 'subject' => 'Important message read immediately!', + 'duration' => NULL, + 'location' => NULL, + 'details' => $messageBody, + 'status_id' => 'Completed', + 'activity_type_id' => 'Inbound Email', + 'source_contact_id' => $this->source, + 'assignee_contact_id' => NULL, + ]); + $activity_id = $activity['id']; + + // Simulate viewing it from the form. + + $form = new CRM_Activity_Form_Activity(); + $form->controller = new CRM_Core_Controller_Simple('CRM_Activity_Form_Activity', 'Activity'); + $form->set('context', 'standalone'); + $form->set('cid', $this->source); + $form->set('action', 'view'); + $form->set('id', $activity_id); + $form->set('atype', $activity['values'][$activity_id]['activity_type_id']); + + $form->buildForm(); + + // Wish there was another way to do this + $form->controller->handle($form, 'display'); + + // This isn't a faithful representation of the output since there'll + // probably be a lot missing, but for now I don't see a simpler way to + // do this. + // Also this is printing the template code to the console. It doesn't hurt + // the test but it's clutter and I don't know where it's coming from + // and can't seem to prevent it. + $output = $form->getTemplate()->fetch($form->getTemplateFileName()); + + // This kind of suffers from the same problem as the old webtests. It's + // a bit brittle and tied to the UI. + $this->assertContains("Hi,
\n
\nWassup!?!?
\n
\nLet's check if the output when viewing the form has legible line breaks in the output.
\n
\nThanks!", $output); + + // Put label back + $this->callAPISuccess('OptionValue', 'create', [ + 'id' => $inbound_email['id'], + 'label' => $inbound_email['label'], + ]); + } + } diff --git a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php index 6f7524a8cb..0326787d18 100644 --- a/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php +++ b/tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php @@ -63,6 +63,9 @@ class CRM_Contact_Form_Task_EmailCommonTest extends CiviUnitTestCase { $form->_allContactIds = $form->_toContactIds = $form->_contactIds; $form->_emails = [$loggedInEmail['id'] => 'mickey@mouse.com']; $form->_fromEmails = [$loggedInEmail['id'] => 'mickey@mouse.com']; + // This rule somehow disappears if there's a form-related test before us, + // so register it again. See packages/HTML/QuickForm/file.php. + $form->registerRule('maxfilesize', 'callback', '_ruleCheckMaxFileSize', 'HTML_QuickForm_file'); CRM_Contact_Form_Task_EmailCommon::preProcessFromAddress($form); CRM_Contact_Form_Task_EmailCommon::buildQuickForm($form); CRM_Contact_Form_Task_EmailCommon::submit($form, array_merge($form->_defaultValues, [