first pass RT4 merge, RT#13852
[freeside.git] / rt / t / articles / search-interface.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use RT::Test tests => 23;
7
8 use RT::CustomField;
9 use RT::Queue;
10 use RT::Ticket;
11 use_ok 'RT::Class';
12 use_ok 'RT::Topic';
13 use_ok 'RT::Article';
14
15 my ($url, $m) = RT::Test->started_ok;
16
17 # Variables to test return values
18 my ($ret, $msg);
19
20 # Create a test class
21 my $class = RT::Class->new($RT::SystemUser);
22 ($ret, $msg) = $class->Create('Name' => 'tlaTestClass-'.$$,
23                               'Description' => 'A general-purpose test class');
24 ok($ret, "Test class created");
25
26
27 my $questionCF = RT::CustomField->new($RT::SystemUser);
28 my $answerCF = RT::CustomField->new($RT::SystemUser);
29 my $ticketCF = RT::CustomField->new($RT::SystemUser);
30 ($ret, $msg) = $questionCF->Create('Name' => 'Question-'.$$,
31                            'Type' => 'Text',
32                            'MaxValues' => 1,
33                            'LookupType' => 'RT::Class-RT::Article',
34                            'Description' => 'The question to be answered',
35                            'Disabled' => 0);
36 ok($ret, "Question CF created: $msg");
37 ($ret, $msg) = $answerCF->Create('Name' => 'Answer-'.$$,
38                          'Type' => 'Text',
39                          'MaxValues' => 1,
40                          'LookupType' => 'RT::Class-RT::Article',
41                          'Description' => 'The answer to the question',
42                          'Disabled' => 0);
43 ok($ret, "Answer CF created: $msg");
44
45 ($ret, $msg) = $ticketCF->Create('Name' => 'Class',
46                          'Type' => 'Text',
47                          'MaxValues' => 1,
48                          'LookupType' => 'RT::Queue-RT::Ticket',
49                          'Disabled' => 0);
50 ok($ret, "Ticket CF 'Class' created: $msg");
51
52 # Attach the custom fields to our class
53 ($ret, $msg) = $questionCF->AddToObject($class);
54 ok($ret, "Question CF added to class: $msg");
55 ($ret, $msg) = $answerCF->AddToObject($class);
56 ok($ret, "Answer CF added to class: $msg");
57 my ($qid, $aid) = ($questionCF->Id, $answerCF->Id);
58
59 my $global_queue = RT::Queue->new($RT::SystemUser);
60 ($ret, $msg) = $ticketCF->AddToObject($global_queue);
61 ok($ret, "Ticket CF added globally: $msg");
62
63 my %cvals = ('article1q' => 'Some question about swallows',
64                 'article1a' => 'Some answer about Europe and Africa',
65                 'article2q' => 'Another question about Monty Python',
66                 'article2a' => 'Romani ite domum',
67                 'article3q' => 'Why should I eat my supper?',
68                 'article3a' => 'There are starving children in Africa',
69                 'article4q' => 'What did Brian originally write?',
70                 'article4a' => 'Romanes eunt domus');
71
72 # Create an article or two with our custom field values.
73
74 my $article1 = RT::Article->new($RT::SystemUser);
75 my $article2 = RT::Article->new($RT::SystemUser);
76 my $article3 = RT::Article->new($RT::SystemUser);
77 my $article4 = RT::Article->new($RT::SystemUser);
78 ($ret, $msg) = $article1->Create(Name => 'First article '.$$,
79                                  Summary => 'blah blah 1',
80                                  Class => $class->Id,
81                                  "CustomField-$qid" => $cvals{'article1q'},
82                                  "CustomField-$aid" => $cvals{'article1a'},
83                                  );
84 ok($ret, "article 1 created");
85 ($ret, $msg) = $article2->Create(Name => 'Second article '.$$,
86                                  Summary => 'foo bar 2',
87                                  Class => $class->Id,
88                                  "CustomField-$qid" => $cvals{'article2q'},
89                                  "CustomField-$aid" => $cvals{'article2a'},
90                                  );
91 ok($ret, "article 2 created");
92 ($ret, $msg) = $article3->Create(Name => 'Third article '.$$,
93                                  Summary => 'ping pong 3',
94                                  Class => $class->Id,
95                                  "CustomField-$qid" => $cvals{'article3q'},
96                                  "CustomField-$aid" => $cvals{'article3a'},
97                                  );
98 ok($ret, "article 3 created");
99 ($ret, $msg) = $article4->Create(Name => 'Fourth article '.$$,
100                                  Summary => 'hoi polloi 4',
101                                  Class => $class->Id,
102                                  "CustomField-$qid" => $cvals{'article4q'},
103                                  "CustomField-$aid" => $cvals{'article4a'},
104                                  );
105 ok($ret, "article 4 created");
106
107 isa_ok($m, 'Test::WWW::Mechanize');
108 ok($m->login, 'logged in');
109 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
110     'UI -> Articles' );
111 $m->follow_link_ok( {text => 'Search'}, 'Articles -> Search');
112 $m->follow_link_ok( {text => 'in class '.$class->Name}, 'Articles in class '.$class->Name);
113 $m->content_contains($article1->Name);