1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
use warnings;
use strict;
use RT::Test tests => 37;
use_ok('RT::Class');
my $class = RT::Class->new($RT::SystemUser);
isa_ok($class, 'RT::Class');
isa_ok($class, 'RT::Record');
isa_ok($class, 'RT::Record');
my $name = 'test-'.$$;
my ($id,$msg) = $class->Create( Name =>$name, Description => 'Test class');
ok($id,$msg);
is ($class->Name, $name);
is ($class->Description, 'Test class');
# Test custom fields.
can_ok($class, 'CustomFields');
can_ok($class, 'AddCustomFieldValue');
can_ok($class, 'DeleteCustomFieldValue');
can_ok($class, 'FirstCustomFieldValue');
can_ok($class, 'CustomFieldValues');
can_ok($class, 'CurrentUserHasRight');
# Add a custom field to our class
my $cf = RT::CustomField->new($RT::SystemUser);
isa_ok($cf, 'RT::CustomField');
# the following tests don't expect to see the new pre-defined "Content" cf.
# disabling the pre-defined one so we can test if old behavior still works
$cf->Load(1);
$cf->SetDisabled(1);
$cf = RT::CustomField->new($RT::SystemUser);
($id,$msg) = $cf->Create( Name => 'Articles::Sample-'.$$,
Description => 'Test text cf',
LookupType => RT::Article->CustomFieldLookupType,
Type => 'Text'
);
ok($id,$msg);
($id,$msg) = $cf->AddToObject($class);
ok ($id,$msg);
# Does our class have a custom field?
my $cfs = $class->ArticleCustomFields;
isa_ok($cfs, 'RT::CustomFields');
is($cfs->Count, 1, "We only have one custom field");
my $found_cf = $cfs->First;
is ($cf->id, $found_cf->id, "it's the right one");
($id,$msg) = $cf->RemoveFromObject($class);
is($class->ArticleCustomFields->Count, 0, "All gone!");
# Put it back. we want to go forward.
($id,$msg) = $cf->AddToObject($class);
ok ($id,$msg);
use_ok('RT::Article');
my $art = RT::Article->new($RT::SystemUser);
($id,$msg) =$art->Create(Class => $class->id,
Name => 'Sample'.$$,
Description => 'A sample article');
ok($id,"Created article ".$id." - " .$msg);
# make sure there is one transaction.
my $txns = $art->Transactions;
is($txns->Count, 1, "One txn");
my $txn = $txns->First;
is ($txn->ObjectType, 'RT::Article');
is ($txn->ObjectId , $id , "It's the right article");
is ($txn->Type, 'Create', "It's a create!");
my $art_cfs = $art->CustomFields();
is ($art_cfs->Count, 1, "It has a custom field");
my $values = $art->CustomFieldValues($art_cfs->First);
is ($values->Count, 0);
$art->AddCustomFieldValue(Field => $cf->id, Value => 'Testing');
$values = $art->CustomFieldValues($art_cfs->First->id);
# We added the custom field
is ($values->Count, 1);
is ($values->First->Content, 'Testing', "We added the CF");
is ($art->Transactions->Count,2, "We added a second transaction for the custom field addition");
my $txn2 = $art->Transactions->Last;
is ($txn2->ObjectId, $art->id);
is ($txn2->id, ($txn->id +1));
is ($txn2->Type, 'CustomField');
is($txn2->NewValue, 'Testing');
ok (!$txn2->OldValue, "It had no old value");
1;
|