Skip to content

Commit

Permalink
Add a class to handle test entities consistently
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Mar 13, 2019
1 parent 9abdba6 commit cd35535
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CRM/Activity/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
$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 (
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/BAO/ContributionSoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ public static function getSoftContributionList($contact_id, $filter = NULL, $isT
$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;
Expand Down
3 changes: 3 additions & 0 deletions CRM/Contribute/Page/ContributionRecurPayments.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ private function loadRelatedContributions() {
$this->insertStatusLabels($contribution);
$this->insertContributionActions($contribution);

if ($contribution['is_test']) {
$contribution['financial_type'] = CRM_Core_TestEntity::appendTestText($contribution['financial_type']);
}
$relatedContributions[] = $contribution;
}

Expand Down
58 changes: 58 additions & 0 deletions CRM/Core/TestEntity.php
Original file line number Diff line number Diff line change
@@ -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)');
}

}
2 changes: 1 addition & 1 deletion CRM/Event/Form/ParticipantView.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function preProcess() {
}

if ($values[$participantID]['is_test']) {
$values[$participantID]['status'] .= ' (test) ';
$values[$participantID]['status'] = CRM_Core_TestEntity::appendTestText($values[$participantID]['status']);
}

// Get Note
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
$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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Form/MembershipView.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public function preProcess() {
}

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);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Member/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
$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;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Pledge/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
}
// 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();
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/WebTest/Event/AddParticipationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function testEventAddMultipleParticipants() {
$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));
Expand Down

0 comments on commit cd35535

Please sign in to comment.