6 use RT::Test tests => 37;
10 my $class = RT::Class->new($RT::SystemUser);
11 isa_ok($class, 'RT::Class');
12 isa_ok($class, 'RT::Record');
13 isa_ok($class, 'RT::Record');
16 my $name = 'test-'.$$;
17 my ($id,$msg) = $class->Create( Name =>$name, Description => 'Test class');
19 is ($class->Name, $name);
20 is ($class->Description, 'Test class');
26 can_ok($class, 'CustomFields');
27 can_ok($class, 'AddCustomFieldValue');
28 can_ok($class, 'DeleteCustomFieldValue');
29 can_ok($class, 'FirstCustomFieldValue');
30 can_ok($class, 'CustomFieldValues');
31 can_ok($class, 'CurrentUserHasRight');
34 # Add a custom field to our class
35 my $cf = RT::CustomField->new($RT::SystemUser);
36 isa_ok($cf, 'RT::CustomField');
38 ($id,$msg) = $cf->Create( Name => 'Articles::Sample-'.$$,
39 Description => 'Test text cf',
40 LookupType => RT::Article->CustomFieldLookupType,
49 ($id,$msg) = $cf->AddToObject($class);
53 # Does our class have a custom field?
55 my $cfs = $class->ArticleCustomFields;
56 isa_ok($cfs, 'RT::CustomFields');
57 is($cfs->Count, 1, "We only have one custom field");
58 my $found_cf = $cfs->First;
59 is ($cf->id, $found_cf->id, "it's the right one");
61 ($id,$msg) = $cf->RemoveFromObject($class);
63 is($class->ArticleCustomFields->Count, 0, "All gone!");
65 # Put it back. we want to go forward.
67 ($id,$msg) = $cf->AddToObject($class);
73 use_ok('RT::Article');
75 my $art = RT::Article->new($RT::SystemUser);
76 ($id,$msg) =$art->Create(Class => $class->id,
78 Description => 'A sample article');
80 ok($id,"Created article ".$id." - " .$msg);
82 # make sure there is one transaction.
84 my $txns = $art->Transactions;
86 is($txns->Count, 1, "One txn");
87 my $txn = $txns->First;
88 is ($txn->ObjectType, 'RT::Article');
89 is ($txn->ObjectId , $id , "It's the right article");
90 is ($txn->Type, 'Create', "It's a create!");
93 my $art_cfs = $art->CustomFields();
94 is ($art_cfs->Count, 1, "It has a custom field");
95 my $values = $art->CustomFieldValues($art_cfs->First);
96 is ($values->Count, 0);
98 $art->AddCustomFieldValue(Field => $cf->id, Value => 'Testing');
99 $values = $art->CustomFieldValues($art_cfs->First->id);
101 # We added the custom field
102 is ($values->Count, 1);
103 is ($values->First->Content, 'Testing', "We added the CF");
105 is ($art->Transactions->Count,2, "We added a second transaction for the custom field addition");
106 my $txn2 = $art->Transactions->Last;
107 is ($txn2->ObjectId, $art->id);
108 is ($txn2->id, ($txn->id +1));
109 is ($txn2->Type, 'CustomField');
110 is($txn2->NewValue, 'Testing');
111 ok (!$txn2->OldValue, "It had no old value");