5 use RT::Test tests => 29;
11 my $class = RT::Class->new($RT::SystemUser);
12 my ( $id, $msg ) = $class->Create( Name => 'CollectionTest-' . $$ );
15 # Add a custom field to our class
16 use_ok('RT::CustomField');
17 my $cf = RT::CustomField->new($RT::SystemUser);
18 isa_ok($cf, 'RT::CustomField');
20 ($id,$msg) = $cf->Create( Name => 'Articles::Sample-'.$$,
21 Description => 'Test text cf',
22 LookupType => RT::Article->CustomFieldLookupType,
31 ($id,$msg) = $cf->AddToObject($class);
36 my $art = RT::Article->new($RT::SystemUser);
37 ( $id, $msg ) = $art->Create(
39 Name => 'Collection-1-' . $$,
40 Summary => 'Coll-1-' . $$,
41 'CustomField-'.$cf->Name => 'Test-'.$$
51 my $arts = RT::Articles->new($RT::SystemUser);
52 $arts->LimitName( VALUE => 'Collection-1-' . $$ . 'fake' );
54 "Found no artlcles with names matching something that is not there" );
56 my $arts2 = RT::Articles->new($RT::SystemUser);
57 $arts2->LimitName( VALUE => 'Collection-1-' . $$ );
58 is( $arts2->Count, 1, 'Found one with names matching the word "test"' );
60 $arts = RT::Articles->new($RT::SystemUser);
61 $arts->LimitSummary( VALUE => 'Coll-1-' . $$ . 'fake' );
63 'Found no artlcles with summarys matching something that is not there' );
65 $arts2 = RT::Articles->new($RT::SystemUser);
66 $arts2->LimitSummary( VALUE => 'Coll-1-' . $$ );
67 is( $arts2->Count, 1, 'Found one with summarys matching the word "Coll-1"' );
69 my $new_art = RT::Article->new($RT::SystemUser);
70 ( $id, $msg ) = $new_art->Create(
72 Name => 'CFSearchTest1' . $$,
73 'CustomField-'.$cf->Name => 'testing' . $$
76 ok( $id, $msg . " Created a second testable article" );
79 $arts = RT::Articles->new($RT::SystemUser);
80 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => "esting".$$ );
81 is( $arts->Count, 1, "Found 1 cf values matching 'esting" . $$ . "' for an unspecified field");
83 $arts = RT::Articles->new($RT::SystemUser);
84 $arts->LimitCustomField( OPERATOR => '=', VALUE => "esting".$$ );
85 is( $arts->Count, 0, "Found 0 cf values EXACTLY matching 'esting" . $$ . "' for an unspecified field");
87 $arts = RT::Articles->new($RT::SystemUser);
88 $arts->LimitCustomField( OPERATOR => '=', VALUE => "testing".$$ );
89 is( $arts->Count, 1, "Found 0 cf values EXACTLY matching 'testing" . $$ . "' for an unspecified field");
92 $arts = RT::Articles->new($RT::SystemUser);
93 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$ );
94 is( $arts->Count, 2, "Found 1 cf values matching '" . $$ . "' for an unspecified field");
97 # Test searching on named custom fields
98 $arts = RT::Articles->new($RT::SystemUser);
99 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => $cf->Name );
100 is( $arts->Count, 2, "Found 1 Article with cf values matching '".$$."' for CF named " .$cf->Name);
102 $arts = RT::Articles->new($RT::SystemUser);
103 $arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => 'NO-SUCH-CF' );
104 is( $arts->Count,0, "Found no cf values matching '".$$."' for CF 'NO-SUCH-CF' " );
106 $arts = RT::Articles->new($RT::SystemUser);
107 $arts->Limit(FIELD =>'Class', VALUE => $class->id);
109 $arts->LimitCustomField(
110 OPERATOR => 'NOT LIKE',
116 "Found 1 articles with custom field values not matching blah");
118 $arts = RT::Articles->new($RT::SystemUser);
119 $arts->Limit(FIELD =>'Class', VALUE => $class->id);
120 $arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'est', FIELD => $cf->id );
121 is( $arts->Count , 0, "Found 0 cf values not matching 'est' for CF ".$cf->id. " " . join(',', map {$_->id} @{$arts->ItemsArrayRef}));
122 $arts = RT::Articles->new($RT::SystemUser);
123 $arts->Limit(FIELD =>'Class', VALUE => $class->id);
124 $arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'BOGUS', FIELD => $cf->id );
125 is( $arts->Count , 2, "Found 2 articles not matching 'BOGUS' for CF ".$cf->id);
127 my $ac = RT::Articles->new($RT::SystemUser);
128 ok( $ac->isa('RT::Articles') );
129 ok( $ac->isa('DBIx::SearchBuilder') );
130 ok( $ac->LimitRefersTo('http://dead.link') );
133 $ac = RT::Articles->new($RT::SystemUser);
134 ok( $ac->LimitReferredToBy('http://dead.link') );