[Rt-commit] rt branch, 4.4/serialize-json-initialdata, updated. rt-4.4.1-366-g56316be

Shawn Moore shawn at bestpractical.com
Mon Mar 20 22:09:12 EDT 2017


The branch, 4.4/serialize-json-initialdata has been updated
       via  56316be2a43c4e4a8e400d210c4ef9cd98f47914 (commit)
       via  2b27b607deecc27f521b889ef1c46f6e30687899 (commit)
      from  d2f3c8561acc4d9c7378a9edd8d00109bc7fddc3 (commit)

Summary of changes:
 t/api/initialdata-roundtrip.t | 75 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 75 insertions(+)

- Log -----------------------------------------------------------------
commit 2b27b607deecc27f521b889ef1c46f6e30687899
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 01:29:49 2017 +0000

    Tests for CF lookup types

diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 4af670f..3fb6f52 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -154,6 +154,34 @@ my @tests = (
     },
 
     {
+        name => 'Custom field lookup types',
+        create => sub {
+            for my $type (qw/Asset Article Group Queue Ticket Transaction User/) {
+                my $class = "RT::$type";
+                my $cf = RT::CustomField->new(RT->SystemUser);
+                my ($ok, $msg) = $cf->Create(
+                    Name => "$type CF",
+                    Type => "FreeformSingle",
+                    LookupType => $class->CustomFieldLookupType,
+                );
+                ok($ok, $msg);
+            }
+        },
+        present => sub {
+            for my $type (qw/Asset Article Group Queue Ticket Transaction User/) {
+                my $class = "RT::$type";
+                my $cf = RT::CustomField->new(RT->SystemUser);
+                $cf->Load("$type CF");
+                ok($cf->Id, "loaded $type CF");
+                is($cf->Name, "$type CF", 'Name');
+                is($cf->Type, 'Freeform', 'Type');
+                is($cf->MaxValues, 1, 'MaxValues');
+                is($cf->LookupType, $class->CustomFieldLookupType, 'LookupType');
+            }
+        },
+    },
+
+    {
         name => 'Scrips',
         create => sub {
             my $bugs = RT::Queue->new(RT->SystemUser);

commit 56316be2a43c4e4a8e400d210c4ef9cd98f47914
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Mar 21 01:57:38 2017 +0000

    WIP

diff --git a/t/api/initialdata-roundtrip.t b/t/api/initialdata-roundtrip.t
index 3fb6f52..d8f0177 100644
--- a/t/api/initialdata-roundtrip.t
+++ b/t/api/initialdata-roundtrip.t
@@ -156,6 +156,15 @@ my @tests = (
     {
         name => 'Custom field lookup types',
         create => sub {
+            my %extra = (
+                Group => { method => 'CreateUserDefinedGroup' },
+                Asset => { Catalog => 'General assets' },
+                Article => undef,
+                Ticket => undef,
+                Transaction => undef,
+                User => undef,
+            );
+
             for my $type (qw/Asset Article Group Queue Ticket Transaction User/) {
                 my $class = "RT::$type";
                 my $cf = RT::CustomField->new(RT->SystemUser);
@@ -165,9 +174,37 @@ my @tests = (
                     LookupType => $class->CustomFieldLookupType,
                 );
                 ok($ok, $msg);
+
+                # apply globally
+                ($ok, $msg) = $cf->AddToObject($cf->RecordClassFromLookupType->new(RT->SystemUser));
+                ok($ok, $msg);
+
+                next if exists($extra{$type}) && !defined($extra{$type});
+
+                my $obj = $class->new(RT->SystemUser);
+                my $method = delete($extra{$type}{method}) || 'Create';
+                ($ok, $msg) = $obj->$method(
+                    Name => $type,
+                    %{ $extra{$type} || {} },
+                );
+                ok($ok, "created $type: $msg");
+                ok($obj->Id, "loaded $type");
+
+                ($ok, $msg) = $obj->AddCustomFieldValue(
+                    Field => $cf->Id,
+                    Value => "$type Value",
+                );
+                ok($ok, $msg);
             }
         },
         present => sub {
+            my %load = (
+                Transaction => undef,
+                Ticket => undef,
+                Article => undef,
+                User => undef,
+            );
+
             for my $type (qw/Asset Article Group Queue Ticket Transaction User/) {
                 my $class = "RT::$type";
                 my $cf = RT::CustomField->new(RT->SystemUser);
@@ -177,6 +214,16 @@ my @tests = (
                 is($cf->Type, 'Freeform', 'Type');
                 is($cf->MaxValues, 1, 'MaxValues');
                 is($cf->LookupType, $class->CustomFieldLookupType, 'LookupType');
+
+                next if exists($load{$type}) && !defined($load{$type});
+
+                my $obj = $class->new(RT->SystemUser);
+                $obj->LoadByCols(
+                    %{ $load{$type} || { Name => $type } },
+                );
+                ok($obj->Id, "loaded $type");
+
+                is($obj->FirstCustomFieldValue($cf->Id), "$type Value", "CF value for $type");
             }
         },
     },

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


More information about the rt-commit mailing list