[Rt-commit] rt branch, 4.4/custom-field-msg, created. rt-4.2.11-161-g7058527
Dustin Graves
dustin at bestpractical.com
Mon Aug 17 11:25:57 EDT 2015
The branch, 4.4/custom-field-msg has been created
at 7058527a74579e3d5c69081e3be77ee5446c84f2 (commit)
- Log -----------------------------------------------------------------
commit 7058527a74579e3d5c69081e3be77ee5446c84f2
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..e2eb16d 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1586,9 +1586,18 @@ sub AddToObject {
}
my $ocf = RT::ObjectCustomField->new( $self->CurrentUser );
- my ( $oid, $msg ) = $ocf->Add(
+ my $oid = $ocf->Add(
CustomField => $self->id, ObjectId => $id,
);
+
+ my $msg;
+ # If object has no id, it represents all objects
+ if ($object->id) {
+ $msg = $self->loc( 'Added custom field [_1] to [_2].', $self->Name, $object->Name );
+ } else {
+ $msg = $self->loc( 'Globall added custom field [_1].', $self->Name );
+ }
+
return ( $oid, $msg );
}
@@ -1620,7 +1629,16 @@ sub RemoveFromObject {
}
# XXX: Delete doesn't return anything
- my ( $oid, $msg ) = $ocf->Delete;
+ my $oid = $ocf->Delete;
+
+ my $msg;
+ # If object has no id, it represents all objects
+ if ($object->id) {
+ $msg = $self->loc( 'Removed custom field [_1] from [_2].', $self->Name, $object->Name );
+ } else {
+ $msg = $self->loc( 'Globally removed custom field [_1].', $self->Name );
+ }
+
return ( $oid, $msg );
}
diff --git a/t/articles/upload-customfields.t b/t/articles/upload-customfields.t
index 6ce7086..cbc17da 100644
--- a/t/articles/upload-customfields.t
+++ b/t/articles/upload-customfields.t
@@ -55,7 +55,7 @@ $m->form_number(3);
my $tcf = (grep { /AddCustomField-/ } map { $_->name } $m->current_form->inputs )[0];
$m->tick( $tcf, 0 ); # Associate the new CF with this queue
$m->click('UpdateObjs');
-$m->content_like( qr/Object created/, 'TCF added to the queue' );
+$m->content_contains("Added custom field img$$ to All Objects", 'TCF added to the queue' );
$m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
'UI -> Articles' );
diff --git a/t/customfields/api.t b/t/customfields/api.t
index a50ca77..873503c 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.', "Removing custom field from queue produces appropriate message");
+
+ ($status, $msg) = $custom_field->AddToObject( $all_queues );
+ is($msg, 'Globally added custom field custom_field_0.', "Adding custom field globally produces appropriate message");
+
+ ($status, $msg) = $custom_field->RemoveFromObject( $all_queues );
+ is($msg, 'Globally removed custom field custom_field_0.', "Rmeoving custom field globally 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.', "Removing custom field from queue produces appropriate message");
+
+ ($status, $msg) = $custom_field->AddToObject( $all_queues );
+ is($msg, 'Globally added custom field custom_field_1.', "Adding custom field globally produces appropriate message");
+
+ ($status, $msg) = $custom_field->RemoveFromObject( $all_queues );
+ is($msg, 'Globally removed custom field custom_field_1.', "Removing custom field globally 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, 'Globally added custom field custom_field_2.', "Adding custom field globally produces appropriate message");
+
+ ($status, $msg) = $custom_field->RemoveFromObject( $all_classes );
+ is($msg, 'Globally removed custom field custom_field_2.', "Removing custom field globally produces appropriate message");
+}
diff --git a/t/web/cf_access.t b/t/web/cf_access.t
index c93057f..d303aa7 100644
--- a/t/web/cf_access.t
+++ b/t/web/cf_access.t
@@ -112,7 +112,7 @@ my ( $cf, $cfid, $tid );
$m->tick( AddCustomField => $_ => 0 ) for @names; # ...and not any other. ;-)
$m->click('UpdateCFs');
- $m->content_contains('Object created', 'TCF added to the queue' );
+ $m->content_contains("Added custom field img to General", 'TCF added to the queue' );
}
my $tester = RT::Test->load_or_create_user( Name => 'tester', Password => '123456' );
diff --git a/t/web/cf_date.t b/t/web/cf_date.t
index 4783484..24d9e04 100644
--- a/t/web/cf_date.t
+++ b/t/web/cf_date.t
@@ -47,7 +47,7 @@ ok $queue && $queue->id, 'loaded or created queue';
$m->tick( "AddCustomField" => $cfid );
$m->click('UpdateCFs');
- $m->content_contains('Object created', 'TCF added to the queue' );
+ $m->content_contains("Added custom field $cf_name to General", 'TCF added to the queue' );
}
diag 'check valid inputs with various timezones in ticket create page';
diff --git a/t/web/cf_datetime.t b/t/web/cf_datetime.t
index a370ce4..e62ae8b 100644
--- a/t/web/cf_datetime.t
+++ b/t/web/cf_datetime.t
@@ -55,7 +55,7 @@ ok $queue && $queue->id, 'loaded or created queue';
$m->tick( "AddCustomField" => $cfid );
$m->click('UpdateCFs');
- $m->content_contains('Object created', 'TCF added to the queue' );
+ $m->content_contains("Added custom field $cf_name to General", 'TCF added to the queue' );
}
diag 'check valid inputs with various timezones in ticket create page';
diff --git a/t/web/cf_image.t b/t/web/cf_image.t
index d1c3944..f3244b0 100644
--- a/t/web/cf_image.t
+++ b/t/web/cf_image.t
@@ -23,7 +23,7 @@ $m->follow_link_ok( {id => "page-applies-to"} );
$m->form_with_fields( "AddCustomField-1" );
$m->tick( "AddCustomField-1", 0 );
$m->click_ok( "UpdateObjs" );
-$m->content_contains("Object created");
+$m->content_contains("Added custom field Images to All Objects");
$m->submit_form_ok({
diff --git a/t/web/cf_onqueue.t b/t/web/cf_onqueue.t
index dd3320a..35ebb21 100644
--- a/t/web/cf_onqueue.t
+++ b/t/web/cf_onqueue.t
@@ -35,7 +35,7 @@ diag "Apply the new CF globally";
$m->tick( AddCustomField => 1 );
$m->click('UpdateCFs');
- $m->content_contains('Object created', 'CF QueueCFTest enabled globally' );
+ $m->content_contains("Added custom field QueueCFTest to All Objects", 'CF QueueCFTest enabled globally' );
}
diag "Edit the CF value for default queue";
diff --git a/t/web/cf_select_one.t b/t/web/cf_select_one.t
index 4f81e2a..f70486f 100644
--- a/t/web/cf_select_one.t
+++ b/t/web/cf_select_one.t
@@ -59,7 +59,7 @@ diag "apply the CF to General queue";
$m->tick( "AddCustomField" => $cfid );
$m->click('UpdateCFs');
- $m->content_contains('Object created', 'TCF added to the queue' );
+ $m->content_contains("Added custom field $cf_name to General", 'TCF added to the queue' );
}
my $tid;
diff --git a/t/web/ticket_preserve_basics.t b/t/web/ticket_preserve_basics.t
index 1459414..98f64c2 100644
--- a/t/web/ticket_preserve_basics.t
+++ b/t/web/ticket_preserve_basics.t
@@ -88,7 +88,7 @@ $m->get_ok($url.'/Admin/CustomFields/Objects.html?id='.$cf->id);
$m->form_with_fields('UpdateObjs');
$m->tick('AddCustomField-'.$cf->id => '0'); # Make CF global
$m->click('UpdateObjs');
-$m->text_contains('Object created', 'CF applied globally');
+$m->text_contains("Added custom field CF1 to All Objects", 'CF applied globally');
# Test for preservation when a ticket is submitted and CF validation fails
for my $try (@form_tries) {
-----------------------------------------------------------------------
More information about the rt-commit
mailing list