6 use RT::Test tests => 11;
12 use_ok 'RT::CustomField';
14 my $classname = 'TestClass';
15 my $class = RT::Class->new( $RT::SystemUser );
17 $class->Load( $classname );
18 unless ( $class->Id ) {
19 my ($id, $msg) = $class->Create(
21 Description => 'class for cf tests',
23 ok $id, "created class '$classname' #$id"
24 or diag "error: $msg";
26 ok 1, "class '$classname' exists";
31 my $cfname = 'TestCF'. $suffix;
32 my $cf = RT::CustomField->new( $RT::SystemUser );
34 my ($id, $msg) = $cf->Create(
36 LookupType => 'RT::Class-RT::Article',
37 Type => 'Select', MaxValues => 1,
38 Description => 'singleselect cf for tests',
40 ok $id, "created cf '$cfname' #$id"
41 or diag "error: $msg";
46 my ($status, $msg) = $cf->AddToObject( $class );
47 ok $status, "attached the cf to the class"
48 or diag "error: $msg";
51 # create two cf-values
53 my ($status, $msg) = $cf->AddValue( Name => 'Value1' );
54 ok $status, "added a value to the cf" or diag "error: $msg";
56 ($status, $msg) = $cf->AddValue( Name => 'Value2' );
57 ok $status, "added a value to the cf" or diag "error: $msg";
60 my $article1name = 'TestArticle1'.$suffix;
61 my $article1 = RT::Article->new($RT::SystemUser);
62 $article1->Create( Name => $article1name, Summary => 'Test', Class => $class->Id);
63 $article1->AddCustomFieldValue(Field => $cf->Id, Value => 'Value1');
65 my $article2name = 'TestArticle2'.$suffix;
66 my $article2 = RT::Article->new($RT::SystemUser);
67 $article2->Create( Name => $article2name, Summary => 'Test', Class => $class->Id);
68 $article2->AddCustomFieldValue(Field => $cf->Id, Value => 'Value2');
70 # search for articles containing 1st value
72 my $articles = RT::Articles->new( $RT::SystemUser );
74 $articles->Limit( FIELD => "Class", SUBCLAUSE => 'ClassMatch', VALUE => $class->Id);
75 $articles->LimitCustomField( FIELD => $cf->Id, VALUE => 'Value1' );
76 is $articles->Count, 1, 'found correct number of articles';
80 my $articles = RT::Articles->new($RT::SystemUser);
82 $articles->Limit( FIELD => "Class", SUBCLAUSE => 'ClassMatch', VALUE => $class->Id);
83 $articles->LimitCustomField( FIELD => $cf, VALUE => 'Value1' );
84 is $articles->Count, 1, 'found correct number of articles';
88 my $articles = RT::Articles->new($RT::SystemUser);
89 $articles->UnLimit( );
90 $articles->Limit( FIELD => "Class", SUBCLAUSE => 'ClassMatch', VALUE => $class->Id);
91 $articles->LimitCustomField( FIELD => $cf->Name, VALUE => 'Value1' );
92 is $articles->Count, 1, 'found correct number of articles';