5 use RT::Test tests => 44;
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' => 'tlaTestClass-'.$$,
22 'Description' => 'A general-purpose test class');
23 ok($ret, "Test class created");
26 my $questionCF = RT::CustomField->new($RT::SystemUser);
27 my $answerCF = RT::CustomField->new($RT::SystemUser);
28 my $ticketCF = RT::CustomField->new($RT::SystemUser);
29 ($ret, $msg) = $questionCF->Create('Name' => 'Question-'.$$,
32 'LookupType' => 'RT::Class-RT::Article',
33 'Description' => 'The question to be answered',
35 ok($ret, "Question CF created: $msg");
36 ($ret, $msg) = $answerCF->Create('Name' => 'Answer-'.$$,
39 'LookupType' => 'RT::Class-RT::Article',
40 'Description' => 'The answer to the question',
42 ok($ret, "Answer CF created: $msg");
44 ($ret, $msg) = $ticketCF->Create('Name' => 'Class',
47 'LookupType' => 'RT::Queue-RT::Ticket',
49 ok($ret, "Ticket CF 'Class' created: $msg");
51 # Attach the custom fields to our class
52 ($ret, $msg) = $questionCF->AddToObject($class);
53 ok($ret, "Question CF added to class: $msg");
54 ($ret, $msg) = $answerCF->AddToObject($class);
55 ok($ret, "Answer CF added to class: $msg");
56 my ($qid, $aid) = ($questionCF->Id, $answerCF->Id);
58 my $global_queue = RT::Queue->new($RT::SystemUser);
59 ($ret, $msg) = $ticketCF->AddToObject($global_queue);
60 ok($ret, "Ticket CF added globally: $msg");
62 my %cvals = ('article1q' => 'Some question about swallows',
63 'article1a' => 'Some answer about Europe and Africa',
64 'article2q' => 'Another question about Monty Python',
65 'article2a' => 'Romani ite domum',
66 'article3q' => 'Why should I eat my supper?',
67 'article3a' => 'There are starving children in Africa',
68 'article4q' => 'What did Brian originally write?',
69 'article4a' => 'This is an answer that is longer than 255 '
70 . 'characters so these tests will be sure to use the LargeContent '
71 . 'SQL as well as the normal SQL that would be generated if this '
72 . 'was an answer that was shorter than 255 characters. This second '
73 . 'sentence has a few extra characters to get this string to go '
74 . 'over the 255 character boundary. Lorem ipsum.');
76 # Create an article or two with our custom field values.
78 my $article1 = RT::Article->new($RT::SystemUser);
79 my $article2 = RT::Article->new($RT::SystemUser);
80 my $article3 = RT::Article->new($RT::SystemUser);
81 my $article4 = RT::Article->new($RT::SystemUser);
82 ($ret, $msg) = $article1->Create(Name => 'First article '.$$,
83 Summary => 'blah blah 1',
85 "CustomField-$qid" => $cvals{'article1q'},
86 "CustomField-$aid" => $cvals{'article1a'},
88 ok($ret, "article 1 created");
89 ($ret, $msg) = $article2->Create(Name => 'Second article '.$$,
90 Summary => 'foo bar 2',
92 "CustomField-$qid" => $cvals{'article2q'},
93 "CustomField-$aid" => $cvals{'article2a'},
95 ok($ret, "article 2 created");
96 ($ret, $msg) = $article3->Create(Name => 'Third article '.$$,
97 Summary => 'ping pong 3',
99 "CustomField-$qid" => $cvals{'article3q'},
100 "CustomField-$aid" => $cvals{'article3a'},
102 ok($ret, "article 3 created");
103 ($ret, $msg) = $article4->Create(Name => 'Fourth article '.$$,
104 Summary => 'hoi polloi 4',
106 "CustomField-$qid" => $cvals{'article4q'},
107 "CustomField-$aid" => $cvals{'article4a'},
109 ok($ret, "article 4 created");
111 isa_ok($m, 'Test::WWW::Mechanize');
112 ok($m->login, 'logged in');
113 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
116 # In all of the search results below, the results page should
117 # have the summary text of the article it occurs in.
119 # Case sensitive search on small field.
120 DoArticleSearch($m, $class->Name, 'Africa');
121 $m->text_contains('Search results'); # Did we do a search?
122 $m->text_contains('blah blah 1');
124 # Case insensitive search on small field.
125 DoArticleSearch($m, $class->Name, 'africa');
126 $m->text_contains('Search results'); # Did we do a search?
127 $m->text_contains('blah blah 1');
129 # Case sensitive search on large field.
130 DoArticleSearch($m, $class->Name, 'ipsum');
131 $m->text_contains('Search results'); # Did we do a search?
132 $m->text_contains('hoi polloi 4');
134 # Case insensitive search on large field.
135 DoArticleSearch($m, $class->Name, 'lorem');
136 $m->text_contains('Search results'); # Did we do a search?
138 local $TODO = 'Case insensitive search on LONGBLOB not available in MySQL'
139 if RT->Config->Get('DatabaseType') eq 'mysql';
140 $m->text_contains('hoi polloi 4');
143 # When you send $m to this sub, it must be on a page with
147 my $class_name = shift;
148 my $search_text = shift;
150 $m->follow_link_ok( {text => 'Search'}, 'Articles -> Search');
151 $m->follow_link_ok( {text => 'in class '. $class_name}, 'Articles in class '. $class_name);
152 $m->text_contains('First article');
154 $m->submit_form_ok( {
157 'Article~' => $search_text
159 }, "Search for $search_text"