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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
use strict;
use warnings;
use RT::Test tests => 29;
use_ok 'RT::Articles';
use_ok 'RT::Classes';
use_ok 'RT::Class';
my $class = RT::Class->new($RT::SystemUser);
my ( $id, $msg ) = $class->Create( Name => 'CollectionTest-' . $$ );
ok( $id, $msg );
# Add a custom field to our class
use_ok('RT::CustomField');
my $cf = RT::CustomField->new($RT::SystemUser);
isa_ok($cf, 'RT::CustomField');
($id,$msg) = $cf->Create( Name => 'Articles::Sample-'.$$,
Description => 'Test text cf',
LookupType => RT::Article->CustomFieldLookupType,
Type => 'Freeform'
);
ok($id,$msg);
($id,$msg) = $cf->AddToObject($class);
ok ($id,$msg);
my $art = RT::Article->new($RT::SystemUser);
( $id, $msg ) = $art->Create(
Class => $class->id,
Name => 'Collection-1-' . $$,
Summary => 'Coll-1-' . $$,
'CustomField-'.$cf->Name => 'Test-'.$$
);
ok( $id, $msg );
my $arts = RT::Articles->new($RT::SystemUser);
$arts->LimitName( VALUE => 'Collection-1-' . $$ . 'fake' );
is( $arts->Count, 0,
"Found no artlcles with names matching something that is not there" );
my $arts2 = RT::Articles->new($RT::SystemUser);
$arts2->LimitName( VALUE => 'Collection-1-' . $$ );
is( $arts2->Count, 1, 'Found one with names matching the word "test"' );
$arts = RT::Articles->new($RT::SystemUser);
$arts->LimitSummary( VALUE => 'Coll-1-' . $$ . 'fake' );
is( $arts->Count, 0,
'Found no artlcles with summarys matching something that is not there' );
$arts2 = RT::Articles->new($RT::SystemUser);
$arts2->LimitSummary( VALUE => 'Coll-1-' . $$ );
is( $arts2->Count, 1, 'Found one with summarys matching the word "Coll-1"' );
my $new_art = RT::Article->new($RT::SystemUser);
( $id, $msg ) = $new_art->Create(
Class => $class->id,
Name => 'CFSearchTest1' . $$,
'CustomField-'.$cf->Name => 'testing' . $$
);
ok( $id, $msg . " Created a second testable article" );
$arts = RT::Articles->new($RT::SystemUser);
$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => "esting".$$ );
is( $arts->Count, 1, "Found 1 cf values matching 'esting" . $$ . "' for an unspecified field");
$arts = RT::Articles->new($RT::SystemUser);
$arts->LimitCustomField( OPERATOR => '=', VALUE => "esting".$$ );
is( $arts->Count, 0, "Found 0 cf values EXACTLY matching 'esting" . $$ . "' for an unspecified field");
$arts = RT::Articles->new($RT::SystemUser);
$arts->LimitCustomField( OPERATOR => '=', VALUE => "testing".$$ );
is( $arts->Count, 1, "Found 0 cf values EXACTLY matching 'testing" . $$ . "' for an unspecified field");
$arts = RT::Articles->new($RT::SystemUser);
$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$ );
is( $arts->Count, 2, "Found 1 cf values matching '" . $$ . "' for an unspecified field");
# Test searching on named custom fields
$arts = RT::Articles->new($RT::SystemUser);
$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => $cf->Name );
is( $arts->Count, 2, "Found 1 Article with cf values matching '".$$."' for CF named " .$cf->Name);
$arts = RT::Articles->new($RT::SystemUser);
$arts->LimitCustomField( OPERATOR => 'LIKE', VALUE => $$, FIELD => 'NO-SUCH-CF' );
is( $arts->Count,0, "Found no cf values matching '".$$."' for CF 'NO-SUCH-CF' " );
$arts = RT::Articles->new($RT::SystemUser);
$arts->Limit(FIELD =>'Class', VALUE => $class->id);
$arts->LimitCustomField(
OPERATOR => 'NOT LIKE',
VALUE => 'blah',
FIELD => $cf->id
);
is(
$arts->Count ,2,
"Found 1 articles with custom field values not matching blah");
$arts = RT::Articles->new($RT::SystemUser);
$arts->Limit(FIELD =>'Class', VALUE => $class->id);
$arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'est', FIELD => $cf->id );
is( $arts->Count , 0, "Found 0 cf values not matching 'est' for CF ".$cf->id. " " . join(',', map {$_->id} @{$arts->ItemsArrayRef}));
$arts = RT::Articles->new($RT::SystemUser);
$arts->Limit(FIELD =>'Class', VALUE => $class->id);
$arts->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'BOGUS', FIELD => $cf->id );
is( $arts->Count , 2, "Found 2 articles not matching 'BOGUS' for CF ".$cf->id);
my $ac = RT::Articles->new($RT::SystemUser);
ok( $ac->isa('RT::Articles') );
ok( $ac->isa('DBIx::SearchBuilder') );
ok( $ac->LimitRefersTo('http://dead.link') );
is( $ac->Count, 0 );
$ac = RT::Articles->new($RT::SystemUser);
ok( $ac->LimitReferredToBy('http://dead.link') );
is( $ac->Count, 0 );
|