5 use RT::Test tests => undef;
14 my ($url, $m) = RT::Test->started_ok;
16 # Variables to test return values
20 my $class = RT::Class->new($RT::SystemUser);
21 ($ret, $msg) = $class->Create('Name' => 'First-class',
22 'Description' => 'A general-purpose test class');
23 ok($ret, "Test class created");
25 ($ret, $msg) = $class->Create('Name' => 'Second-class',
26 'Description' => 'Another class');
27 ok($ret, "Test class created");
29 my $questionCF = RT::CustomField->new($RT::SystemUser);
30 my $answerCF = RT::CustomField->new($RT::SystemUser);
31 my $ticketCF = RT::CustomField->new($RT::SystemUser);
32 ($ret, $msg) = $questionCF->Create('Name' => 'Question-'.$$,
35 'LookupType' => 'RT::Class-RT::Article',
36 'Description' => 'The question to be answered',
38 ok($ret, "Question CF created: $msg");
39 ($ret, $msg) = $answerCF->Create('Name' => 'Answer-'.$$,
42 'LookupType' => 'RT::Class-RT::Article',
43 'Description' => 'The answer to the question',
45 ok($ret, "Answer CF created: $msg");
47 ($ret, $msg) = $ticketCF->Create('Name' => 'Class',
50 'LookupType' => 'RT::Queue-RT::Ticket',
52 ok($ret, "Ticket CF 'Class' created: $msg");
54 # Attach the custom fields to our class
55 ($ret, $msg) = $questionCF->AddToObject($class);
56 ok($ret, "Question CF added to class: $msg");
57 ($ret, $msg) = $answerCF->AddToObject($class);
58 ok($ret, "Answer CF added to class: $msg");
59 my ($qid, $aid) = ($questionCF->Id, $answerCF->Id);
61 my $global_queue = RT::Queue->new($RT::SystemUser);
62 ($ret, $msg) = $ticketCF->AddToObject($global_queue);
63 ok($ret, "Ticket CF added globally: $msg");
65 my %cvals = ('article1q' => 'Some question about swallows',
66 'article1a' => 'Some answer about Europe and Africa',
67 'article2q' => 'Another question about Monty Python',
68 'article2a' => 'Romani ite domum',
69 'article3q' => 'Why should I eat my supper?',
70 'article3a' => 'There are starving children in Africa',
71 'article4q' => 'What did Brian originally write?',
72 'article4a' => 'This is an answer that is longer than 255 '
73 . 'characters so these tests will be sure to use the LargeContent '
74 . 'SQL as well as the normal SQL that would be generated if this '
75 . 'was an answer that was shorter than 255 characters. This second '
76 . 'sentence has a few extra characters to get this string to go '
77 . 'over the 255 character boundary. Lorem ipsum.');
79 # Create an article or two with our custom field values.
81 my $article1 = RT::Article->new($RT::SystemUser);
82 my $article2 = RT::Article->new($RT::SystemUser);
83 my $article3 = RT::Article->new($RT::SystemUser);
84 my $article4 = RT::Article->new($RT::SystemUser);
85 ($ret, $msg) = $article1->Create(Name => 'First article '.$$,
86 Summary => 'blah blah 1',
88 "CustomField-$qid" => $cvals{'article1q'},
89 "CustomField-$aid" => $cvals{'article1a'},
91 ok($ret, "article 1 created");
92 ($ret, $msg) = $article2->Create(Name => 'Second article '.$$,
93 Summary => 'foo bar 2',
95 "CustomField-$qid" => $cvals{'article2q'},
96 "CustomField-$aid" => $cvals{'article2a'},
98 ok($ret, "article 2 created");
99 ($ret, $msg) = $article3->Create(Name => 'Third article '.$$,
100 Summary => 'ping pong 3',
102 "CustomField-$qid" => $cvals{'article3q'},
103 "CustomField-$aid" => $cvals{'article3a'},
105 ok($ret, "article 3 created");
106 ($ret, $msg) = $article4->Create(Name => 'Fourth article '.$$,
107 Summary => 'hoi polloi 4',
109 "CustomField-$qid" => $cvals{'article4q'},
110 "CustomField-$aid" => $cvals{'article4a'},
112 ok($ret, "article 4 created");
114 isa_ok($m, 'Test::WWW::Mechanize');
115 ok($m->login, 'logged in');
116 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
119 # In all of the search results below, the results page should
120 # have the summary text of the article it occurs in.
122 # Case sensitive search on small field.
123 DoArticleSearch($m, $class->Name, 'Africa');
124 $m->text_contains('Search results'); # Did we do a search?
125 $m->text_contains('blah blah 1');
127 # Case insensitive search on small field.
128 DoArticleSearch($m, $class->Name, 'africa');
129 $m->text_contains('Search results'); # Did we do a search?
130 $m->text_contains('blah blah 1');
132 # Case sensitive search on large field.
133 DoArticleSearch($m, $class->Name, 'ipsum');
134 $m->text_contains('Search results'); # Did we do a search?
135 $m->text_contains('hoi polloi 4');
137 # Case insensitive search on large field.
138 DoArticleSearch($m, $class->Name, 'lorem');
139 $m->text_contains('Search results'); # Did we do a search?
141 local $TODO = 'Case insensitive search on LONGBLOB not available in MySQL'
142 if RT->Config->Get('DatabaseType') eq 'mysql';
143 $m->text_contains('hoi polloi 4');
149 # When you send $m to this sub, it must be on a page with
153 my $class_name = shift;
154 my $search_text = shift;
156 $m->follow_link_ok( {text => 'Articles'}, 'Articles Search');
157 $m->follow_link_ok( {text => 'in class '. $class_name}, 'Articles in class '. $class_name);
158 $m->text_contains('First article');
160 $m->submit_form_ok( {
163 'Article~' => $search_text
165 }, "Search for $search_text"