[Rt-commit] rt branch, 4.4/custom-field-msg, created. rt-4.2.11-135-g5dccb8b

Dustin Graves dustin at bestpractical.com
Tue Aug 11 17:27:36 EDT 2015


The branch, 4.4/custom-field-msg has been created
        at  5dccb8b9cee3150056d23fa03ccd05bf08c0490a (commit)

- Log -----------------------------------------------------------------
commit 5dccb8b9cee3150056d23fa03ccd05bf08c0490a
Author: Dustin Graves <dustin at bestpractical.com>
Date:   Tue Aug 11 16:31:16 2015 +0000

    Improve applying a custom field to a queue message
    
    Change revoke message and add Unit Tests for these messages
    
    Fixes: I#31128

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index 39b90b9..ee6d999 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1586,9 +1586,20 @@ sub AddToObject {
     }
 
     my $ocf = RT::ObjectCustomField->new( $self->CurrentUser );
-    my ( $oid, $msg ) = $ocf->Add(
+    my $oid = $ocf->Add(
         CustomField => $self->id, ObjectId => $id,
     );
+
+    my $object_name;
+    # If object has no id, it represents all objects
+    if ($object->id) {
+        $object_name = $object->Name;
+    } else {
+        $object_name = 'All Objects';
+    }
+
+    my $msg = "Added custom field " . $self->Name . " to " . $object_name . ".";
+
     return ( $oid, $msg );
 }
 
@@ -1620,7 +1631,18 @@ sub RemoveFromObject {
     }
 
     # XXX: Delete doesn't return anything
-    my ( $oid, $msg ) = $ocf->Delete;
+    my $oid = $ocf->Delete;
+
+    my $object_name;
+    # If object has no id, it represents all objects
+    if ($object->id) {
+        $object_name = $object->Name;
+    } else {
+        $object_name = 'All Objects';
+    }
+
+    my $msg = "Removed custom field " . $self->Name . " from " . $object_name . ".";
+
     return ( $oid, $msg );
 }
 
diff --git a/t/customfields/api.t b/t/customfields/api.t
index a50ca77..e408cd5 100644
--- a/t/customfields/api.t
+++ b/t/customfields/api.t
@@ -1,8 +1,9 @@
 
+
 use strict;
 use warnings FATAL => 'all';
 
-use RT::Test nodata => 1, tests => 145;
+use RT::Test nodata => 1, tests => 157;
 use Test::Warn;
 
 # Before we get going, ditch all object_cfs; this will remove
@@ -31,7 +32,7 @@ $ticket->Create(
 my $cfs = $ticket->CustomFields;
 is( $cfs->Count, 0 );
 
-# Check that record has no any CF values yet {{{
+# Check that record has no any CF values yet
 my $cfvs = $ticket->CustomFieldValues;
 is( $cfvs->Count, 0 );
 is( $ticket->FirstCustomFieldValue, undef );
@@ -63,7 +64,7 @@ my @custom_fields = ($local_cf1, $local_cf2, $global_cf3);
 $cfs = $ticket->CustomFields;
 is( $cfs->Count, 3 );
 
-# Check that record has no any CF values yet {{{
+# Check that record has no any CF values yet
 $cfvs = $ticket->CustomFieldValues;
 is( $cfvs->Count, 0 );
 is( $ticket->FirstCustomFieldValue, undef );
@@ -95,7 +96,7 @@ for (@custom_fields) {
     is( $ticket->FirstCustomFieldValue( $_->Name ), undef );
 }
 
-# try to add field value with fields that do not exist {{{
+# try to add field value with fields that do not exist
 my ($status, $msg) = $ticket->AddCustomFieldValue( Field => -1 , Value => 'foo' );
 ok(!$status, "shouldn't add value" );
 ($status, $msg) = $ticket->AddCustomFieldValue( Field => 'SomeUnexpedCustomFieldName' , Value => 'foo' );
@@ -230,4 +231,70 @@ warning_like {
 #       $test_add_delete_cycle->( sub { return $_[0]->Name } );
 #}
 
+# These represent adding the custom field to all objects
+my $all_queues = RT::Queue->new( RT->SystemUser );
+my $all_classes = RT::Class->new( RT->SystemUser );
+
+# Queue CustomField Message Test
+{
+    my $queue = RT::Queue->new( RT->SystemUser );
+    $queue->Create( Name => 'queue_name_0' );
+
+    my $custom_field = RT::CustomField->new( RT->SystemUser );
+    $custom_field->Create( Name => 'custom_field_0', Type => 'SelectSingle', LookupType => 'RT::Queue' );
+
+    my ($status, $msg) = $custom_field->AddToObject( $queue );
+    is($msg, 'Added custom field custom_field_0 to queue_name_0.', "Adding custom field to queue produces appropriate message");
+
+    ($status, $msg) = $custom_field->RemoveFromObject( $queue );
+    is($msg, 'Removed custom field custom_field_0 from queue_name_0.', "Remove custom field from queue produces appropriate message");
+
+    ($status, $msg) = $custom_field->AddToObject( $all_queues );
+    is($msg, 'Added custom field custom_field_0 to All Objects.', "Adding custom field to General queue produces appropriate message");
+
+    ($status, $msg) = $custom_field->RemoveFromObject( $all_queues );
+    is($msg, 'Removed custom field custom_field_0 from All Objects.', "Remove custom field from General queue produces appropriate message");
+}
+
+# Ticket CustomField Message Test
+{
+    my $queue = RT::Queue->new( RT->SystemUser );
+    $queue->Create( Name => 'queue_name_1' );
+
+    my $custom_field = RT::CustomField->new( RT->SystemUser );
+    $custom_field->Create( Name => 'custom_field_1', Type => 'SelectSingle', LookupType => 'RT::Queue-RT::Ticket' );
+
+    my ($status, $msg) = $custom_field->AddToObject( $queue );
+    is($msg, 'Added custom field custom_field_1 to queue_name_1.', "Adding custom field to queue-ticket produces appropriate message");
+
+    ($status, $msg) = $custom_field->RemoveFromObject( $queue );
+    is($msg, 'Removed custom field custom_field_1 from queue_name_1.', "Remove custom field from queue produces appropriate message");
+
+    ($status, $msg) = $custom_field->AddToObject( $all_queues );
+    is($msg, 'Added custom field custom_field_1 to All Objects.', "Adding custom field to General queue produces appropriate message");
+
+    ($status, $msg) = $custom_field->RemoveFromObject( $all_queues );
+    is($msg, 'Removed custom field custom_field_1 from All Objects.', "Remove custom field from General queue produces appropriate message");
+}
+
+# Class CustomField Message Test
+{
+    my $class = RT::Class->new( RT->SystemUser );
+    $class->Create( Name => 'class_name_0' );
+
+    my $custom_field = RT::CustomField->new( RT->SystemUser );
+    $custom_field->Create( Name => 'custom_field_2', Type => 'SelectSingle', LookupType => 'RT::Class-RT::Article' );
+
+    my ($status, $msg) = $custom_field->AddToObject( $class );
+    is($msg, 'Added custom field custom_field_2 to class_name_0.', "Adding custom field to class-ticket produces appropriate message");
+
+    ($status, $msg) = $custom_field->RemoveFromObject( $class );
+    is($msg, 'Removed custom field custom_field_2 from class_name_0.', "Remove custom field from class produces appropriate message");
+
+    ($status, $msg) = $custom_field->AddToObject( $all_classes );
+    is($msg, 'Added custom field custom_field_2 to All Objects.', "Adding custom field to General class produces appropriate message");
+
+    ($status, $msg) = $custom_field->RemoveFromObject( $all_classes );
+    is($msg, 'Removed custom field custom_field_2 from All Objects.', "Remove custom field from General class produces appropriate message");
+}
 

-----------------------------------------------------------------------


More information about the rt-commit mailing list