RT 4.2.11, ticket#13852
[freeside.git] / rt / t / articles / articles.t
1
2 use strict;
3 use warnings;
4
5 use RT::Test tests => 29;
6
7 use_ok 'RT::Articles';
8 use_ok 'RT::Classes';
9 use_ok 'RT::Class';
10
11 my $class = RT::Class->new($RT::SystemUser);
12 my ( $id, $msg ) = $class->Create( Name => 'CollectionTest-' . $$ );
13 ok( $id, $msg );
14
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');
19
20 ($id,$msg) = $cf->Create( Name => 'Articles::Sample-'.$$,
21              Description => 'Test text cf',
22              LookupType => RT::Article->CustomFieldLookupType,
23              Type => 'Freeform'
24              );
25
26
27
28 ok($id,$msg);
29
30
31 ($id,$msg) = $cf->AddToObject($class);
32 ok ($id,$msg);
33
34
35
36 my $art = RT::Article->new($RT::SystemUser);
37 ( $id, $msg ) = $art->Create(
38     Class   => $class->id,
39     Name    => 'Collection-1-' . $$,
40     Summary => 'Coll-1-' . $$,
41     'CustomField-'.$cf->Name => 'Test-'.$$
42 );
43
44 ok( $id, $msg );
45
46
47
48
49
50
51 my $arts = RT::Articles->new($RT::SystemUser);
52 $arts->LimitName( VALUE => 'Collection-1-' . $$ . 'fake' );
53 is( $arts->Count, 0,
54     "Found no artlcles with names matching something that is not there" );
55
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"' );
59
60 $arts = RT::Articles->new($RT::SystemUser);
61 $arts->LimitSummary( VALUE => 'Coll-1-' . $$ . 'fake' );
62 is( $arts->Count, 0,
63     'Found no artlcles with summarys matching something that is not there' );
64
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"' );
68
69 my $new_art = RT::Article->new($RT::SystemUser);
70 ( $id, $msg ) = $new_art->Create(
71     Class          => $class->id,
72     Name           => 'CFSearchTest1' . $$,
73     'CustomField-'.$cf->Name  => 'testing' . $$
74 );
75
76 ok( $id, $msg . " Created a second testable article" );
77
78
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");
82
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");
86
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");
90
91
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");
95
96
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);
101
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'  " );
105
106 $arts = RT::Articles->new($RT::SystemUser);
107 $arts->Limit(FIELD =>'Class', VALUE => $class->id);
108         
109 $arts->LimitCustomField(
110     OPERATOR => 'NOT LIKE',
111     VALUE    => 'blah',
112     FIELD    => $cf->id
113 );
114 is(
115     $arts->Count ,2,
116     "Found 1 articles with custom field values not matching blah");
117
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);
126
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') );
131 is( $ac->Count, 0 );
132
133 $ac = RT::Articles->new($RT::SystemUser);
134 ok( $ac->LimitReferredToBy('http://dead.link') );
135 is( $ac->Count, 0 );
136