Add a class to handle test entities consistently
authorMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Wed, 13 Mar 2019 14:00:14 +0000 (14:00 +0000)
committerMatthew Wire (MJW Consulting) <mjw@mjwconsult.co.uk>
Wed, 13 Mar 2019 15:04:46 +0000 (15:04 +0000)
CRM/Activity/Selector/Search.php
CRM/Contribute/BAO/ContributionSoft.php
CRM/Contribute/Page/ContributionRecurPayments.php
CRM/Core/TestEntity.php [new file with mode: 0644]
CRM/Event/Form/ParticipantView.php
CRM/Event/Selector/Search.php
CRM/Member/Form/MembershipView.php
CRM/Member/Selector/Search.php
CRM/Pledge/Selector/Search.php
tests/phpunit/WebTest/Event/AddParticipationTest.php

index 0d9e36c5d156b789c413fb368eaee6ddb2d8b4d5..f6de0e43dd50ef0baf18d3fa1c0f35a2fa6b87aa 100644 (file)
@@ -310,7 +310,7 @@ class CRM_Activity_Selector_Search extends CRM_Core_Selector_Base implements CRM
       $accessMailingReport = FALSE;
       $activityTypeId = $row['activity_type_id'];
       if ($row['activity_is_test']) {
-        $row['activity_type'] = $row['activity_type'] . " (test)";
+        $row['activity_type'] = CRM_Core_TestEntity::appendTestText($row['activity_type']);
       }
       $row['mailingId'] = '';
       if (
index 1f6671cb3dbb98ce806cc6cc49735b8dd279495e..8b7e1ec8c9d66e5ee49a3923a448fd13274d477e 100644 (file)
@@ -520,7 +520,7 @@ class CRM_Contribute_BAO_ContributionSoft extends CRM_Contribute_DAO_Contributio
       $result[$cs->id]['links'] = CRM_Core_Action::formLink($links, NULL, $replace);
 
       if ($isTest) {
-        $result[$cs->id]['contribution_status'] = $result[$cs->id]['contribution_status'] . '<br /> (test)';
+        $result[$cs->id]['contribution_status'] = CRM_Core_TestEntity::appendTestText($result[$cs->id]['contribution_status']);
       }
     }
     return $result;
index 0410bdca3b14d8eb2002000105df4adcfd1ed9af..0237481dbf70caf46ac4b7665e8c19d25b8e7d19 100644 (file)
@@ -53,6 +53,9 @@ class CRM_Contribute_Page_ContributionRecurPayments extends CRM_Core_Page {
       $this->insertStatusLabels($contribution);
       $this->insertContributionActions($contribution);
 
+      if ($contribution['is_test']) {
+        $contribution['financial_type'] = CRM_Core_TestEntity::appendTestText($contribution['financial_type']);
+      }
       $relatedContributions[] = $contribution;
     }
 
diff --git a/CRM/Core/TestEntity.php b/CRM/Core/TestEntity.php
new file mode 100644 (file)
index 0000000..ee288de
--- /dev/null
@@ -0,0 +1,58 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 5                                                  |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * This file contains various support functions for test entities in CiviCRM.
+ * Historically there is a lot of inconsistency as to how test entities are displayed.
+ * This class helps resolve that.
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2019
+ */
+
+/**
+ * Class CRM_Core_TestEntity.
+ */
+class CRM_Core_TestEntity {
+
+  // @todo extend this class to include functions that control when/where test entities are displayed
+  //  and then use those functions everywhere we can display test transactions.
+  // Ideally the display of test transactions would be a per-user setting or permission
+  //  so it can be toggled on/off as required and does not affect "day-to-day" usage.
+
+  /**
+   * Append "test" text to a string. eg. Member Dues (test) or My registration (test)
+   *
+   * @param string $text
+   *
+   * @return string
+   */
+  public static function appendTestText($text) {
+    return $text . ' ' . ts('(test)');
+  }
+
+}
index fe3cfb3c4eda62b78c9b5d55934163583661386f..f5f22bdc44c251f7ab0d9c60938da0f9bc7cbcb3 100644 (file)
@@ -118,7 +118,7 @@ class CRM_Event_Form_ParticipantView extends CRM_Core_Form {
     }
 
     if ($values[$participantID]['is_test']) {
-      $values[$participantID]['status'] .= ' (test) ';
+      $values[$participantID]['status'] = CRM_Core_TestEntity::appendTestText($values[$participantID]['status']);
     }
 
     // Get Note
index cbe2da518284efc786298df7beda85cd02274844..521c14349979c98b286480c513b9335c489ec282 100644 (file)
@@ -363,7 +363,7 @@ class CRM_Event_Selector_Search extends CRM_Core_Selector_Base implements CRM_Co
       $row['showConfirmUrl'] = ($statusClass == 'Pending') ? TRUE : FALSE;
 
       if (!empty($row['participant_is_test'])) {
-        $row['participant_status'] .= ' (' . ts('test') . ')';
+        $row['participant_status'] = CRM_Core_TestEntity::appendTestText($row['participant_status']);
       }
 
       $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->participant_id;
index 7274bba59a5256ad4897fc35c903c9d0f54e267a..b5ac8470107c3e097b7c991bdc837afc496eb3cb 100644 (file)
@@ -398,7 +398,7 @@ SELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,
     }
 
     if (!empty($values['is_test'])) {
-      $values['membership_type'] .= ' (test) ';
+      $values['membership_type'] = CRM_Core_TestEntity::appendTestText($values['membership_type']);
     }
 
     $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($this->membershipID);
index f46782627aa18d05db6a396cdb232ef29a2c6441..0d7c3639c0f83fff64a9b7416ac0d8759e8b9d8b 100644 (file)
@@ -377,7 +377,7 @@ class CRM_Member_Selector_Search extends CRM_Core_Selector_Base implements CRM_C
       $row['campaign_id'] = $result->member_campaign_id;
 
       if (!empty($row['member_is_test'])) {
-        $row['membership_type'] = $row['membership_type'] . " (test)";
+        $row['membership_type'] = CRM_Core_TestEntity::appendTestText($row['membership_type']);
       }
 
       $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id;
index c7c75ce36d7f31e3346401718d6430e9170fb65f..f7548ed4d7a80c8c3089558ff743615abbb66f8e 100644 (file)
@@ -326,7 +326,7 @@ class CRM_Pledge_Selector_Search extends CRM_Core_Selector_Base {
       }
       // append (test) to status label
       if (!empty($row['pledge_is_test'])) {
-        $row['pledge_status'] .= ' (test)';
+        $row['pledge_status'] = CRM_Core_TestEntity::appendTestText($row['pledge_status']);
       }
 
       $hideOption = array();
index 0c21bd928608f392464de71bc9d3c23b296f33fa..044dd24d320bdb04cdda7461dc81244ef1c8852a 100644 (file)
@@ -342,7 +342,7 @@ class WebTest_Event_AddParticipationTest extends CiviSeleniumTestCase {
     $this->clickLink("_qf_Search_refresh", "participantSearch");
 
     //verifying the registered participants
-    $status = "Registered (test)";
+    $status = CRM_Core_TestEntity::appendTestText("Registered");
 
     foreach ($contacts as $contact) {
       $this->verifyText("xpath=//div[@id='participantSearch']//table//tbody//tr/td[@class='crm-participant-sort_name']/a[text()='{$contact['sort_name']}']/../../td[9]", preg_quote($status));