5 use RT::Test tests => 37;
9 my $class = RT::Class->new($RT::SystemUser);
10 isa_ok($class, 'RT::Class');
11 isa_ok($class, 'RT::Record');
12 isa_ok($class, 'RT::Record');
15 my $name = 'test-'.$$;
16 my ($id,$msg) = $class->Create( Name =>$name, Description => 'Test class');
18 is ($class->Name, $name);
19 is ($class->Description, 'Test class');
25 can_ok($class, 'CustomFields');
26 can_ok($class, 'AddCustomFieldValue');
27 can_ok($class, 'DeleteCustomFieldValue');
28 can_ok($class, 'FirstCustomFieldValue');
29 can_ok($class, 'CustomFieldValues');
30 can_ok($class, 'CurrentUserHasRight');
33 # Add a custom field to our class
34 my $cf = RT::CustomField->new($RT::SystemUser);
35 isa_ok($cf, 'RT::CustomField');
37 ($id,$msg) = $cf->Create( Name => 'Articles::Sample-'.$$,
38 Description => 'Test text cf',
39 LookupType => RT::Article->CustomFieldLookupType,
48 ($id,$msg) = $cf->AddToObject($class);
52 # Does our class have a custom field?
54 my $cfs = $class->ArticleCustomFields;
55 isa_ok($cfs, 'RT::CustomFields');
56 is($cfs->Count, 1, "We only have one custom field");
57 my $found_cf = $cfs->First;
58 is ($cf->id, $found_cf->id, "it's the right one");
60 ($id,$msg) = $cf->RemoveFromObject($class);
62 is($class->ArticleCustomFields->Count, 0, "All gone!");
64 # Put it back. we want to go forward.
66 ($id,$msg) = $cf->AddToObject($class);
72 use_ok('RT::Article');
74 my $art = RT::Article->new($RT::SystemUser);
75 ($id,$msg) =$art->Create(Class => $class->id,
77 Description => 'A sample article');
79 ok($id,"Created article ".$id." - " .$msg);
81 # make sure there is one transaction.
83 my $txns = $art->Transactions;
85 is($txns->Count, 1, "One txn");
86 my $txn = $txns->First;
87 is ($txn->ObjectType, 'RT::Article');
88 is ($txn->ObjectId , $id , "It's the right article");
89 is ($txn->Type, 'Create', "It's a create!");
92 my $art_cfs = $art->CustomFields();
93 is ($art_cfs->Count, 1, "It has a custom field");
94 my $values = $art->CustomFieldValues($art_cfs->First);
95 is ($values->Count, 0);
97 $art->AddCustomFieldValue(Field => $cf->id, Value => 'Testing');
98 $values = $art->CustomFieldValues($art_cfs->First->id);
100 # We added the custom field
101 is ($values->Count, 1);
102 is ($values->First->Content, 'Testing', "We added the CF");
104 is ($art->Transactions->Count,2, "We added a second transaction for the custom field addition");
105 my $txn2 = $art->Transactions->Last;
106 is ($txn2->ObjectId, $art->id);
107 is ($txn2->id, ($txn->id +1));
108 is ($txn2->Type, 'CustomField');
109 is($txn2->NewValue, 'Testing');
110 ok (!$txn2->OldValue, "It had no old value");