wrong linebreaks when activity type label is changed
authordemeritcowboy <demeritcowboy@hotmail.com>
Tue, 21 Jan 2020 22:37:41 +0000 (17:37 -0500)
committerdemeritcowboy <demeritcowboy@hotmail.com>
Tue, 21 Jan 2020 22:37:41 +0000 (17:37 -0500)
CRM/Activity/Form/Activity.php
templates/CRM/Activity/Form/Activity.tpl
tests/phpunit/CRM/Activity/Form/ActivityTest.php
tests/phpunit/CRM/Contact/Form/Task/EmailCommonTest.php

index 889901a56649e6e758414eed195f0e01dce94cd0..a3d6f4a5d6f8332b82352274dfe4e447163b3647 100644 (file)
@@ -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
    */
index 5b2e22a499a97615984ecb407a1a897308d81593..b56c202ad78a4a63fb68ce9dde175ac78fe88fa2 100644 (file)
   </tr>
   <tr class="crm-activity-form-block-details">
     <td class="label">{$form.details.label}</td>
-    {* 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"}
       <td class="view-value">
       {$form.details.html}
       </td>
-    {* 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"}
       <td class="view-value">
        {$form.details.html|crmStripAlternatives|nl2br}
       </td>
index 6fceb9a701cb528d097a7517a06399984037ef45..e65c333d7eae90ea9bde1f7e7dcf44ffdd288140 100644 (file)
@@ -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 = <<<ENDBODY
+-ALTERNATIVE ITEM 0-
+Hi,
+
+Wassup!?!?
+
+Let's check if the output when viewing the form has legible line breaks in the output.
+
+Thanks!
+
+-ALTERNATIVE ITEM 1-
+
+<div dir="ltr">Hi,<br></div>
+<div dir="ltr"><br></div>
+<div dir="ltr">Wassup!?!?<br></div>
+<div dir="ltr"><br></div>
+<div dir="ltr">Let&#39;s check if the output when viewing the form has legible line breaks in the output.<br></div>
+<div dir="ltr"><br></div>
+<div dir="ltr">Thanks!<br></div>
+-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,<br />\n<br />\nWassup!?!?<br />\n<br />\nLet's check if the output when viewing the form has legible line breaks in the output.<br />\n<br />\nThanks!", $output);
+
+    // Put label back
+    $this->callAPISuccess('OptionValue', 'create', [
+      'id' => $inbound_email['id'],
+      'label' => $inbound_email['label'],
+    ]);
+  }
+
 }
index 6f7524a8cb4cb14a8830d9119838aa103490ca9e..0326787d18ef546553181aa1c1b1a68de8dce05c 100644 (file)
@@ -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, [