6 use RT::Test tests => 23;
15 my ($url, $m) = RT::Test->started_ok;
17 # Variables to test return values
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");
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-'.$$,
33 'LookupType' => 'RT::Class-RT::Article',
34 'Description' => 'The question to be answered',
36 ok($ret, "Question CF created: $msg");
37 ($ret, $msg) = $answerCF->Create('Name' => 'Answer-'.$$,
40 'LookupType' => 'RT::Class-RT::Article',
41 'Description' => 'The answer to the question',
43 ok($ret, "Answer CF created: $msg");
45 ($ret, $msg) = $ticketCF->Create('Name' => 'Class',
48 'LookupType' => 'RT::Queue-RT::Ticket',
50 ok($ret, "Ticket CF 'Class' created: $msg");
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);
59 my $global_queue = RT::Queue->new($RT::SystemUser);
60 ($ret, $msg) = $ticketCF->AddToObject($global_queue);
61 ok($ret, "Ticket CF added globally: $msg");
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');
72 # Create an article or two with our custom field values.
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',
81 "CustomField-$qid" => $cvals{'article1q'},
82 "CustomField-$aid" => $cvals{'article1a'},
84 ok($ret, "article 1 created");
85 ($ret, $msg) = $article2->Create(Name => 'Second article '.$$,
86 Summary => 'foo bar 2',
88 "CustomField-$qid" => $cvals{'article2q'},
89 "CustomField-$aid" => $cvals{'article2a'},
91 ok($ret, "article 2 created");
92 ($ret, $msg) = $article3->Create(Name => 'Third article '.$$,
93 Summary => 'ping pong 3',
95 "CustomField-$qid" => $cvals{'article3q'},
96 "CustomField-$aid" => $cvals{'article3a'},
98 ok($ret, "article 3 created");
99 ($ret, $msg) = $article4->Create(Name => 'Fourth article '.$$,
100 Summary => 'hoi polloi 4',
102 "CustomField-$qid" => $cvals{'article4q'},
103 "CustomField-$aid" => $cvals{'article4a'},
105 ok($ret, "article 4 created");
107 isa_ok($m, 'Test::WWW::Mechanize');
108 ok($m->login, 'logged in');
109 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/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);