[Rt-commit] rt branch, 4.4/category-level-cf-groupings, created. rt-4.4.4-61-gd0d1e7fe9

? sunnavy sunnavy at bestpractical.com
Fri Aug 16 10:33:32 EDT 2019


The branch, 4.4/category-level-cf-groupings has been created
        at  d0d1e7fe96dae3f6fb7c0722b8daf210702b88c1 (commit)

- Log -----------------------------------------------------------------
commit cddf1191cfc174c15f3695127928a40a80e1def8
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Aug 16 05:43:34 2019 +0800

    Reduce code duplication of checking formats of CustomFieldGroupings
    
    Various formats are supported in the structure of CustomFieldGroupings
    and we canonilize them in PostLoadCheck. Since the PostLoadCheck will
    always be run in real world, it's fine to assume the config is well
    canonilized in code.
    
    Current duplicated code is not much, but as we are going to support more
    formats there, the duplication will be a pain to maintain.

diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index c0dfd3d34..f0c8bec68 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1486,14 +1486,12 @@ sub Groupings {
     my @groups;
     if ( $record_class ) {
         push @groups, sort {lc($a) cmp lc($b)} keys %{ $BUILTIN_GROUPINGS{$record_class} || {} };
-        if ( ref($config->{$record_class} ||= []) eq "ARRAY") {
-            my @order = @{ $config->{$record_class} };
+        if ( $config->{$record_class} ) {
+            my @order = @{ $config->{$record_class} || [] };
             while (@order) {
                 push @groups, shift(@order);
                 shift(@order);
             }
-        } else {
-            @groups = sort {lc($a) cmp lc($b)} keys %{ $config->{$record_class} };
         }
     } else {
         my %all = (%$config, %BUILTIN_GROUPINGS);
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index afeb44959..f2dfd9662 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -123,7 +123,7 @@ sub LimitToGrouping {
     my $config = RT->Config->Get('CustomFieldGroupings');
        $config = {} unless ref($config) eq 'HASH';
        $config = $config->{$grouping_class} || [];
-    my %h = ref $config eq "ARRAY" ? @{$config} : %{$config};
+    my %h = @{$config};
 
     if ( $grouping ) {
         my $list = $h{$grouping};

commit a57fcc2703666f23ebf97979a77a0a51b0ac7fad
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Aug 16 05:52:26 2019 +0800

    Update cf groupings tests for code duplication cleanup
    
    Now we need to always canonicalize CustomFieldGroupings in tests

diff --git a/t/web/cf_groupings.t b/t/web/cf_groupings.t
index a872617c4..cddbaa7a2 100644
--- a/t/web/cf_groupings.t
+++ b/t/web/cf_groupings.t
@@ -9,6 +9,7 @@ RT->Config->Set( 'CustomFieldGroupings',
         map { +($_ => ["Test$_"]) } @groupings,
     },
 );
+RT->Config->PostLoadCheck;
 
 my %CF;
 for my $grouping (@groupings) {
@@ -146,6 +147,7 @@ my $id = $m->get_ticket_id;
             More   => [ 'TestMore' ],
         },
     );
+    RT->Config->PostLoadCheck;
 
     ( $baseurl, $m ) = RT::Test->started_ok;
     ok $m->login, 'logged in as root';
diff --git a/t/web/cf_groupings_user.t b/t/web/cf_groupings_user.t
index b1450712e..0c8c91ca4 100644
--- a/t/web/cf_groupings_user.t
+++ b/t/web/cf_groupings_user.t
@@ -12,10 +12,13 @@ RT->Config->Set( 'CustomFieldGroupings',
         More             => ['TestMore'],
     },
 );
+RT->Config->PostLoadCheck;
 
 my %CF;
 
-while (my ($group,$cfs) = each %{ RT->Config->Get('CustomFieldGroupings')->{'RT::User'} } ) {
+my @config = @{ RT->Config->Get('CustomFieldGroupings')->{'RT::User'} };
+while (my $group = shift @config) {
+    my $cfs = shift @config;
     my $name = $cfs->[0];
     my $cf = RT::CustomField->new( RT->SystemUser );
     my ($id, $msg) = $cf->Create(

commit 09d42d61319a46f163605ef2a6989c918563c339
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Aug 16 05:58:55 2019 +0800

    Support different custom field groupings at category level
    
    Now tickets/assets could have queue/catalog level of cf groupings.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 1ce94ba0f..d1f55cc62 100644
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -996,6 +996,21 @@ ordering is preserved during display, otherwise groupings are displayed
 alphabetically.  The second level keys are the grouping names and the
 values are array refs containing a list of CF names.
 
+For C<RT::Ticket> and C<RT::Asset>, the structure could be a bit more
+complicated as we support queue/catalog level of groupings. Take
+C<RT::Ticket> for example, the configuration could be like:
+
+    'RT::Ticket' => {
+        'Default' => [
+            'Grouping Name'    => [ 'CF Name' ],
+        ],
+        'General' => [
+            'Grouping Name'    => [ 'CF Name', 'Another CF' ],
+            'Another Grouping' => ['Some CF'],
+            'Dates'            => ['Shipped date'],
+        ],
+    },
+
 There are several special built-in groupings which RT displays in
 specific places (usually the collapsible box of the same title).  The
 ordering of these standard groupings cannot be modified.  You may also
diff --git a/lib/RT/Asset.pm b/lib/RT/Asset.pm
index d79575991..c38cb8e73 100644
--- a/lib/RT/Asset.pm
+++ b/lib/RT/Asset.pm
@@ -673,6 +673,11 @@ sub FindDependencies {
     $deps->Add( out => $self->CatalogObj );
 }
 
+sub CategoryObj {
+    my $self = shift;
+    return $self->CatalogObj;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index 431a12ca2..fbd44e0f2 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -1025,26 +1025,65 @@ our %META;
             }
 
             for my $class (keys %$groups) {
-                my @h;
+                my %h;
                 if (ref($groups->{$class}) eq 'HASH') {
-                    push @h, $_, $groups->{$class}->{$_}
-                        for sort {lc($a) cmp lc($b)} keys %{ $groups->{$class} };
+                    for my $key ( keys %{ $groups->{$class} } ) {
+                        my $value = $groups->{$class}{$key};
+                        if ( ref $value eq 'ARRAY' ) {
+                            if ( ref $value->[1] eq 'ARRAY' ) {
+                                # 'RT::Ticket' => {
+                                #     General => [
+                                #         'Network' => [ 'IP Address', 'Router', ],
+                                #     ],
+                                # }
+                                $h{$key} = $value;
+                            }
+                            else {
+                                # 'RT::Ticket' => {
+                                #     'Network' => [ 'IP Address', 'Router', ],
+                                # }
+                                $h{Default} = [
+                                    map { $_, $groups->{$class}->{$_} }
+                                    sort { lc($a) cmp lc($b) } keys %{ $groups->{$class} }
+                                ];
+                                last;
+                            }
+                        }
+                        elsif ( ref $value eq 'HASH' ) {
+                            # 'RT::Ticket' => {
+                            #     General => {
+                            #         'Network' => [ 'IP Address', 'Router', ],
+                            #     },
+                            # }
+                            $h{$key} = [ map { $_, $groups->{$class}{$key}{$_} }
+                                    sort { lc($a) cmp lc($b) } keys %{ $groups->{$class}{$key} } ];
+                        }
+                        else {
+                            RT->Logger->error(
+                                "Config option \%CustomFieldGroupings{$class}{$key} is not a HASH or ARRAY; ignoring");
+                        }
+                    }
                 } elsif (ref($groups->{$class}) eq 'ARRAY') {
-                    @h = @{ $groups->{$class} };
+                    $h{Default} = $groups->{$class};
                 } else {
                     RT->Logger->error("Config option \%CustomFieldGroupings{$class} is not a HASH or ARRAY; ignoring");
                     delete $groups->{$class};
                     next;
                 }
 
-                $groups->{$class} = [];
-                while (@h) {
-                    my $group = shift @h;
-                    my $ref   = shift @h;
-                    if (ref($ref) eq 'ARRAY') {
-                        push @{$groups->{$class}}, $group => $ref;
-                    } else {
-                        RT->Logger->error("Config option \%CustomFieldGroupings{$class}{$group} is not an ARRAY; ignoring");
+                $groups->{$class} = {};
+                for my $category ( keys %h ) {
+                    my @h = @{ $h{$category} };
+                    while (@h) {
+                        my $group = shift @h;
+                        my $ref   = shift @h;
+                        if ( ref($ref) eq 'ARRAY' ) {
+                            push @{ $groups->{$class}{$category} }, $group => $ref;
+                        }
+                        else {
+                            RT->Logger->error(
+                                "Config option \%CustomFieldGroupings{$class}{$category}{$group} is not an ARRAY; ignoring");
+                        }
                     }
                 }
             }
@@ -1819,8 +1858,8 @@ sub UpdateOption {
 
 sub ObjectHasCustomFieldGrouping {
     my $self        = shift;
-    my %args        = ( Object => undef, Grouping => undef, @_ );
-    my $object_type = RT::CustomField->_GroupingClass($args{Object});
+    my %args        = ( Object => undef, CategoryObj => undef, Grouping => undef, @_ );
+    my $object_type = RT::CustomField->_GroupingClass($args{Object}, $args{CategoryObj} ? $args{CategoryObj}->Name : () );
     my $groupings   = RT->Config->Get( 'CustomFieldGroupings' );
     return 0 unless $groupings;
     return 1 if $groupings->{$object_type} && grep { $_ eq $args{Grouping} } @{ $groupings->{$object_type} };
diff --git a/lib/RT/CustomField.pm b/lib/RT/CustomField.pm
index f0c8bec68..1540a30af 100644
--- a/lib/RT/CustomField.pm
+++ b/lib/RT/CustomField.pm
@@ -1461,7 +1461,7 @@ sub CollectionClassFromLookupType {
     return $collection_class;
 }
 
-=head2 Groupings
+=head2 Groupings Object|Class Name, Queue Name|Catalog Name
 
 Returns a (sorted and lowercased) list of the groupings in which this custom
 field appears.
@@ -1472,13 +1472,17 @@ apply to the record class this CF applies to (L</RecordClassFromLookupType>).
 If passed a loaded object or a class name, the returned list is limited to
 groupings which apply to the class of the object or the specified class.
 
-If called on an unloaded object, all potential groupings are returned.
+You can optionally pass queue/catalog name to get queue/catalog level of
+groupings for the record class, and it'll automatically fallback to default
+groupings for the record class.
+
+If called on an unloaded object, all potential default groupings are returned.
 
 =cut
 
 sub Groupings {
     my $self = shift;
-    my $record_class = $self->_GroupingClass(shift);
+    my ( $record_class, $category ) = $self->_GroupingClass(@_);
 
     my $config = RT->Config->Get('CustomFieldGroupings');
        $config = {} unless ref($config) eq 'HASH';
@@ -1486,8 +1490,14 @@ sub Groupings {
     my @groups;
     if ( $record_class ) {
         push @groups, sort {lc($a) cmp lc($b)} keys %{ $BUILTIN_GROUPINGS{$record_class} || {} };
-        if ( $config->{$record_class} ) {
-            my @order = @{ $config->{$record_class} || [] };
+        if ( my $record_config = $config->{$record_class} ) {
+            my @order;
+            for my $category ( $category, 'Default' ) {
+                if ( $category && $record_config->{$category} ) {
+                    @order = @{ $record_config->{$category} };
+                    last;
+                }
+            }
             while (@order) {
                 push @groups, shift(@order);
                 shift(@order);
@@ -1513,19 +1523,24 @@ returned list.
 
 sub CustomGroupings {
     my $self = shift;
-    my $record_class = $self->_GroupingClass(shift);
-    return grep !$BUILTIN_GROUPINGS{$record_class}{$_}, $self->Groupings( $record_class );
+    my ( $record_class, $category ) = $self->_GroupingClass(@_);
+    return grep !$BUILTIN_GROUPINGS{$record_class}{$_}, $self->Groupings( $record_class, $category );
 }
 
 sub _GroupingClass {
     my $self    = shift;
     my $record  = shift;
+    my $category = shift;
 
     my $record_class = ref($record) || $record || '';
     $record_class = $self->RecordClassFromLookupType
         if !$record_class and blessed($self) and $self->id;
 
-    return $record_class;
+    if ( !$category && blessed $record && $record->id && $record->can('CategoryObj') ) {
+        my ($container_object) = $record->CategoryObj;
+        $category = $container_object->Name if $container_object;
+    }
+    return ( $record_class, $category );
 }
 
 =head2 RegisterBuiltInGroupings
diff --git a/lib/RT/CustomFields.pm b/lib/RT/CustomFields.pm
index f2dfd9662..10ff25755 100644
--- a/lib/RT/CustomFields.pm
+++ b/lib/RT/CustomFields.pm
@@ -115,15 +115,26 @@ L<RT::Record> object.
 
 sub LimitToGrouping {
     my $self = shift;
-    my $obj = shift;
-    my $grouping = shift;
+    my ( $obj, $category, $grouping );
+    if ( @_ >= 3 ) {
+        ( $obj, $category, $grouping ) = @_;
+    }
+    else {
+        ( $obj, $grouping ) = @_;
+    }
 
-    my $grouping_class = $self->NewItem->_GroupingClass($obj);
+    ( my $grouping_class, $category ) = $self->NewItem->_GroupingClass($obj, $category);
 
     my $config = RT->Config->Get('CustomFieldGroupings');
        $config = {} unless ref($config) eq 'HASH';
-       $config = $config->{$grouping_class} || [];
-    my %h = @{$config};
+       $config = $config->{$grouping_class} || {};
+    my %h;
+    for my $category ( $category, 'Default' ) {
+        if ( $category && $config->{$category} ) {
+            %h = @{ $config->{$category} };
+            last;
+        }
+    }
 
     if ( $grouping ) {
         my $list = $h{$grouping};
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 38708af5f..c85661eb6 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -3715,6 +3715,11 @@ sub Serialize {
     return %store;
 }
 
+sub CategoryObj {
+    my $self = shift;
+    return $self->QueueObj;
+}
+
 RT::Base->_ImportOverlays();
 
 1;
diff --git a/share/html/Admin/Assets/Catalogs/DefaultValues.html b/share/html/Admin/Assets/Catalogs/DefaultValues.html
index 01cd9c681..a77e674c5 100644
--- a/share/html/Admin/Assets/Catalogs/DefaultValues.html
+++ b/share/html/Admin/Assets/Catalogs/DefaultValues.html
@@ -57,7 +57,8 @@
         $catalog->AssetCustomFields->LimitToDefaultValuesSupportedTypes
     },
     TitleBoxARGS => { title_class => "inverse" },
-    Object => RT::Asset->new($session{CurrentUser})
+    Object => RT::Asset->new($session{CurrentUser}),
+    CategoryObj => $catalog,
 &>
 
 <& /Elements/Submit, Name => 'Update', Label => loc('Save Changes') &>
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index 201e8c8ab..b6027f6e2 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -70,6 +70,7 @@
         CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
         Grouping => 'Basics',
         InTable => 1,
+        CategoryObj => $queue,
     &>
     </table>
     </&>
@@ -85,12 +86,13 @@
         CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
         Grouping => 'Dates',
         InTable => 1,
+        CategoryObj => $queue,
     &>
     </table>
     </&>
 </div>
 
-% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'People') ) {
+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), CategoryObj => $queue, Grouping => 'People') ) {
 <div class="ticket-info-people">
     <&|/Widgets/TitleBox, title => loc("People") &>
     <table>
@@ -99,13 +101,14 @@
         CustomFields => $queue->TicketCustomFields->LimitToDefaultValuesSupportedTypes,
         Grouping => 'People',
         InTable => 1,
+        CategoryObj => $queue,
     &>
     </table>
     </&>
 </div>
 % }
 
-% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), Grouping => 'Links') ) {
+% if ( RT->Config->ObjectHasCustomFieldGrouping(Object => RT::Ticket->new($session{CurrentUser}), CategoryObj => $queue, Grouping => 'Links') ) {
 <div class="ticket-info-links">
     <&|/Widgets/TitleBox, title => loc("Links") &>
     <table>
diff --git a/share/html/Asset/Create.html b/share/html/Asset/Create.html
index 39ae7e6c8..32dc39068 100644
--- a/share/html/Asset/Create.html
+++ b/share/html/Asset/Create.html
@@ -92,6 +92,7 @@
 
   <& /Elements/EditCustomFieldCustomGroupings,
         Object => $asset,
+        CategoryObj => $catalog,
         TitleBoxARGS => { title_class => "inverse" },
         KeepValue => 1,
         CustomFieldGenerator => sub { $catalog->AssetCustomFields },
diff --git a/share/html/Elements/EditCustomFieldCustomGroupings b/share/html/Elements/EditCustomFieldCustomGroupings
index f7b1859c3..3c6e53bd9 100644
--- a/share/html/Elements/EditCustomFieldCustomGroupings
+++ b/share/html/Elements/EditCustomFieldCustomGroupings
@@ -60,7 +60,8 @@
 <%ARGS>
 $Object
 $CustomFieldGenerator => undef,
- at Groupings => (RT::CustomField->CustomGroupings( $Object ), '')
+$CategoryObj => undef
+ at Groupings => (RT::CustomField->CustomGroupings( $Object, $Object->id && $Object->can('CategoryObj') ? $Object->CategoryObj->Name : ( $CategoryObj ? $CategoryObj->Name : () ) ), '')
 </%ARGS>
 <%INIT>
 my $css_class = lc(ref($Object)||$Object);
diff --git a/share/html/Elements/EditCustomFields b/share/html/Elements/EditCustomFields
index f0f2f55a2..cb1ac0d1d 100644
--- a/share/html/Elements/EditCustomFields
+++ b/share/html/Elements/EditCustomFields
@@ -106,7 +106,7 @@
 $CustomFields ||= $Object->CustomFields;
 $CustomFields->{include_set_initial} = 1 if $ForCreation;
 
-$CustomFields->LimitToGrouping( $Object => $Grouping ) if defined $Grouping;
+$CustomFields->LimitToGrouping( $Object, $Object->id && $Object->can('CategoryObj') ? $Object->CategoryObj->Name : $CategoryObj ? $CategoryObj->Name : undef, $Grouping ) if defined $Grouping;
 
 $m->callback( %ARGS, CallbackName => 'MassageCustomFields', CustomFields => $CustomFields,
                   Object => $Object, ShowHintsRef => \$ShowHints, InTableRef => \$InTable );
@@ -133,6 +133,7 @@ if ( $AsTable ) {
 </%INIT>
 <%ARGS>
 $Object
+$CategoryObj => undef
 $CustomFields => undef
 $Grouping     => undef
 $AsTable => 1
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index bbe1ccf0d..60be3f47d 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -118,6 +118,7 @@
       <& /Elements/EditCustomFields,
           %ARGS,
           Object => $ticket,
+          CategoryObj => $QueueObj,
           CustomFields => $QueueObj->TicketCustomFields,
           Grouping => 'Basics',
           InTable => 1,
@@ -134,6 +135,7 @@
 <& /Elements/EditCustomFieldCustomGroupings,
     %ARGS,
     Object => $ticket,
+    CategoryObj => $QueueObj,
     CustomFieldGenerator => sub { $QueueObj->TicketCustomFields },
     ForCreation => 1,
 &>
@@ -211,6 +213,7 @@
 <& /Elements/EditCustomFields,
     %ARGS,
     Object => $ticket,
+    CategoryObj => $QueueObj,
     CustomFields => $QueueObj->TicketCustomFields,
     Grouping => 'People',
     InTable => 1,
@@ -326,6 +329,7 @@
 <& /Elements/EditCustomFields,
     %ARGS,
     Object => $ticket,
+    CategoryObj => $QueueObj,
     CustomFields => $QueueObj->TicketCustomFields,
     Grouping => 'Dates',
     InTable => 1,

commit 3ef3684c148763b311cdc3b1108498a3939c80cc
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Aug 16 06:06:34 2019 +0800

    Update tests for the new canonicalized format of CustomFieldGroupings

diff --git a/t/assets/web.t b/t/assets/web.t
index 67a842915..2c3a5000e 100644
--- a/t/assets/web.t
+++ b/t/assets/web.t
@@ -8,6 +8,7 @@ RT->Config->Set("CustomFieldGroupings",
         Dates => [qw(Purchased)],
     },
 );
+RT->Config->PostLoadCheck;
 
 my $catalog = create_catalog( Name => "Office" );
 ok $catalog->id, "Created Catalog";
diff --git a/t/web/cf_groupings_user.t b/t/web/cf_groupings_user.t
index 0c8c91ca4..ee07c70d8 100644
--- a/t/web/cf_groupings_user.t
+++ b/t/web/cf_groupings_user.t
@@ -16,7 +16,7 @@ RT->Config->PostLoadCheck;
 
 my %CF;
 
-my @config = @{ RT->Config->Get('CustomFieldGroupings')->{'RT::User'} };
+my @config = @{ RT->Config->Get('CustomFieldGroupings')->{'RT::User'}{Default} };
 while (my $group = shift @config) {
     my $cfs = shift @config;
     my $name = $cfs->[0];

commit d0d1e7fe96dae3f6fb7c0722b8daf210702b88c1
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Aug 16 21:45:25 2019 +0800

    Add tests for queue level cf groupings

diff --git a/t/web/cf_groupings_per_queue.t b/t/web/cf_groupings_per_queue.t
new file mode 100644
index 000000000..19cfd3a5c
--- /dev/null
+++ b/t/web/cf_groupings_per_queue.t
@@ -0,0 +1,97 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my @groupings = qw/Basics Dates People Links More/;
+RT->Config->Set( 'CustomFieldGroupings',
+    'RT::Ticket' => {
+        'General' => {
+            map { +($_ => ["Test$_"]) } @groupings,
+        },
+        'Default' => {
+            map { +($_ => ["Test$_"]) } grep { $_ ne 'More' } @groupings,
+        },
+    },
+);
+RT->Config->PostLoadCheck;
+
+my $general = RT::Test->load_or_create_queue( Name => 'General' );
+my $foo = RT::Test->load_or_create_queue( Name => 'Foo' );
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+ok $m->login, 'logged in as root';
+
+my %CF;
+for my $grouping (@groupings) {
+    my $name = "Test$grouping";
+    my $cf = RT::CustomField->new( RT->SystemUser );
+    my ($id, $msg) = $cf->Create(
+        Name => $name,
+        Queue => '0',
+        Description => 'A Testing custom field',
+        Type => 'FreeformSingle',
+        Pattern => '^(?!bad value).*$',
+    );
+    ok $id, "custom field '$name' correctly created";
+    $CF{$grouping} = $id;
+}
+
+for my $queue ( $general, $foo ) {
+
+    my %location = (
+        Basics => ".ticket-info-basics",
+        Dates  => ".ticket-info-dates",
+        People => "#ticket-create-message",
+        Links  => ".ticket-info-links",
+        More   => ".ticket-info-cfs",
+    );
+
+    {
+        diag "testing Create";
+        $m->goto_create_ticket($queue);
+
+        my $prefix = 'Object-RT::Ticket--CustomField:';
+        my $dom    = $m->dom;
+        $m->form_name('TicketCreate');
+        $m->field( "Subject", "CF grouping test" );
+
+        for my $grouping (@groupings) {
+            my $input_name = $prefix . "$grouping-$CF{$grouping}-Value";
+            if ( $grouping eq 'More' && $queue == $foo ) {
+                $input_name =~ s!:More!!;
+            }
+            is $dom->find(qq{input[name="$input_name"]})->size, 1, "only one CF input on the page";
+            ok $dom->at(qq{$location{$grouping} input[name="$input_name"]}), "CF is in the right place";
+            $m->field( $input_name, "Test" . $grouping . "Value" );
+        }
+        $m->submit;
+    }
+
+    my $id = $m->get_ticket_id;
+    {
+        diag "testing Display";
+        ok $id, "created a ticket";
+        my $dom = $m->dom;
+
+        $location{People} = ".ticket-info-people";
+        foreach my $grouping (@groupings) {
+            my $row_id = "CF-$CF{$grouping}-ShowRow";
+            is $dom->find(qq{#$row_id})->size, 1, "CF on the page";
+            like $dom->at(qq{#$row_id})->all_text, qr/Test$grouping:\s*Test${grouping}Value/, "value is set";
+            ok $dom->at(qq{$location{$grouping} #$row_id}), "CF is in the right place";
+        }
+        if ( $queue == $general ) {
+            ok( !$m->find_link( url_regex => qr/#ticket-info-cfs$/, text => 'Custom Fields' ),
+                'no "Custom Fields" widget' );
+            ok( $m->find_link( url_regex => qr/#ticket-info-cfs-More$/, text => 'More' ), 'has "More" widget' );
+        }
+        else {
+            ok( $m->find_link( url_regex => qr/#ticket-info-cfs$/, text => 'Custom Fields' ),
+                'has "Custom Fields" widget' );
+            ok( !$m->find_link( url_regex => qr/#ticket-info-cfs-More$/, text => 'More' ), 'no "More" widget' );
+        }
+    }
+}
+
+done_testing;

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


More information about the rt-commit mailing list