6 use RT::Test tests => 29;
12 my $class = RT::Class->new($RT::SystemUser);
13 my ( $id, $msg ) = $class->Create( Name => 'CollectionTest-' . $$ );
16 # Add a custom field to our class
17 use_ok('RT::CustomField');
18 my $cf = RT::CustomField->new($RT::SystemUser);
19 isa_ok($cf, 'RT::CustomField');
21 ($id,$msg) = $cf->Create( Name => 'Articles::Sample-'.$$,
22 Description => 'Test text cf',
23 LookupType => RT::Article->CustomFieldLookupType,
32 ($id,$msg) = $cf->AddToObject($class);
37 my $art = RT::Article->new($RT::SystemUser);
38 ( $id, $msg ) = $art->Create(
40 Name => 'Collection-1-' . $$,
41 Summary => 'Coll-1-' . $$,
42 'CustomField-'.$cf->Name => 'Test-'.$$
52 my $arts = RT::Articles->new($RT::SystemUser);
53 $arts->LimitName( VALUE => 'Collection-1-' . $$ . 'fake' );
55 "Found no artlcles with names matching something that is not there" );
57 my $arts2 = RT::Articles->new($RT::SystemUser);
58 $arts2->LimitName( VALUE => 'Collection-1-' . $$ );
59 is( $arts2->Count, 1, 'Found one with names matching the word "test"' );
61 $arts = RT::Articles->new($RT::SystemUser);
62 $arts->LimitSummary( VALUE => 'Coll-1-' . $$ . 'fake' );
64 'Found no artlcles with summarys matching something that is not there' );
66 $arts2 = RT::Articles->new($RT::SystemUser);
67 $arts2->LimitSummary( VALUE => 'Coll-1-' . $$ );
68 is( $arts2->Count, 1, 'Found one with summarys matching the word "Coll-1"' );
70 my $new_art = RT::Article->new($RT::SystemUser);
71 ( $id, $msg ) = $new_art->Create(
73 Name => 'CFSearchTest1' . $$,
74 'CustomField-'.$cf->Name => 'testing' . $$
77 ok( $id, $msg . " Created a second testable article" );
80 $arts = RT::Articles->new($RT::SystemUser);
81 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => "esting".$$ );
82 is( $arts->Count, 1, "Found 1 cf values matching 'esting" . $$ . "' for an unspecified field");
84 $arts = RT::Articles->new($RT::SystemUser);
85 $arts->LimitCustomField( OPERATOR => '=', VALUE => "esting".$$ );
86 is( $arts->Count, 0, "Found 0 cf values EXACTLY matching 'esting" . $$ . "' for an unspecified field");
88 $arts = RT::Articles->new($RT::SystemUser);
89 $arts->LimitCustomField( OPERATOR => '=', VALUE => "testing".$$ );
90 is( $arts->Count, 1, "Found 0 cf values EXACTLY matching 'testing" . $$ . "' for an unspecified field");
93 $arts = RT::Articles->new($RT::SystemUser);
94 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$ );
95 is( $arts->Count, 2, "Found 1 cf values matching '" . $$ . "' for an unspecified field");
98 # Test searching on named custom fields
99 $arts = RT::Articles->new($RT::SystemUser);
100 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => $cf->Name );
101 is( $arts->Count, 2, "Found 1 Article with cf values matching '".$$."' for CF named " .$cf->Name);
103 $arts = RT::Articles->new($RT::SystemUser);
104 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => 'NO-SUCH-CF' );
105 is( $arts->Count,0, "Found no cf values matching '".$$."' for CF 'NO-SUCH-CF' " );
107 $arts = RT::Articles->new($RT::SystemUser);
108 $arts->Limit(FIELD =>'Class', VALUE => $class->id);
110 $arts->LimitCustomField(
111 OPERATOR => 'NOT LIKE',
117 "Found 1 articles with custom field values not matching blah");
119 $arts = RT::Articles->new($RT::SystemUser);
120 $arts->Limit(FIELD =>'Class', VALUE => $class->id);
121 $arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'est', FIELD => $cf->id );
122 is( $arts->Count , 0, "Found 0 cf values not matching 'est' for CF ".$cf->id. " " . join(',', map {$_->id} @{$arts->ItemsArrayRef}));
123 $arts = RT::Articles->new($RT::SystemUser);
124 $arts->Limit(FIELD =>'Class', VALUE => $class->id);
125 $arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'BOGUS', FIELD => $cf->id );
126 is( $arts->Count , 2, "Found 2 articles not matching 'BOGUS' for CF ".$cf->id);
128 my $ac = RT::Articles->new($RT::SystemUser);
129 ok( $ac->isa('RT::Articles') );
130 ok( $ac->isa('DBIx::SearchBuilder') );
131 ok( $ac->LimitRefersTo('http://dead.link') );
134 $ac = RT::Articles->new($RT::SystemUser);
135 ok( $ac->LimitReferredToBy('http://dead.link') );