5 use RT::Test tests => 53;
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");
25 my $class2 = RT::Class->new($RT::SystemUser);
26 ($ret, $msg) = $class2->Create('Name' => 'tlaTestClass2-'.$$,
27 'Description' => 'Another general-purpose test class');
28 ok($ret, "Test class 2 created");
31 # Create a hierarchy of test topics
32 my $topic1 = RT::Topic->new($RT::SystemUser);
33 my $topic11 = RT::Topic->new($RT::SystemUser);
34 my $topic12 = RT::Topic->new($RT::SystemUser);
35 my $topic2 = RT::Topic->new($RT::SystemUser);
36 my $topic_class2= RT::Topic->new($RT::SystemUser);
37 my $gtopic = RT::Topic->new($RT::SystemUser);
38 ($ret, $msg) = $topic1->Create('Parent' => 0,
39 'Name' => 'tlaTestTopic1-'.$$,
40 'ObjectType' => 'RT::Class',
41 'ObjectId' => $class->Id);
42 ok($ret, "Topic 1 created");
43 ($ret, $msg) = $topic11->Create('Parent' => $topic1->Id,
44 'Name' => 'tlaTestTopic1.1-'.$$,
45 'ObjectType' => 'RT::Class',
46 'ObjectId' => $class->Id);
47 ok($ret, "Topic 1.1 created");
48 ($ret, $msg) = $topic12->Create('Parent' => $topic1->Id,
49 'Name' => 'tlaTestTopic1.2-'.$$,
50 'ObjectType' => 'RT::Class',
51 'ObjectId' => $class->Id);
52 ok($ret, "Topic 1.2 created");
53 ($ret, $msg) = $topic2->Create('Parent' => 0,
54 'Name' => 'tlaTestTopic2-'.$$,
55 'ObjectType' => 'RT::Class',
56 'ObjectId' => $class->Id);
57 ok($ret, "Topic 2 created");
58 ($ret, $msg) = $topic_class2->Create('Parent' => 0,
59 'Name' => 'tlaTestTopicClass2-'.$$,
60 'ObjectType' => 'RT::Class',
61 'ObjectId' => $class2->Id);
62 ok($ret, "Topic Class2 created");
63 ($ret, $msg) = $gtopic->Create('Parent' => 0,
64 'Name' => 'tlaTestTopicGlobal-'.$$,
65 'ObjectType' => 'RT::System',
66 'ObjectId' => $RT::System->Id );
67 ok($ret, "Global Topic created");
69 # Create some article custom fields
71 my $questionCF = RT::CustomField->new($RT::SystemUser);
72 my $answerCF = RT::CustomField->new($RT::SystemUser);
73 ($ret, $msg) = $questionCF->Create('Name' => 'Question-'.$$,
76 'LookupType' => 'RT::Class-RT::Article',
77 'Description' => 'The question to be answered',
79 ok($ret, "Question CF created: $msg");
80 ($ret, $msg) = $answerCF->Create('Name' => 'Answer-'.$$,
83 'LookupType' => 'RT::Class-RT::Article',
84 'Description' => 'The answer to the question',
86 ok($ret, "Answer CF created: $msg");
88 # Attach the custom fields to our class
89 ($ret, $msg) = $questionCF->AddToObject($class);
90 ok($ret, "Question CF added to class: $msg");
91 ($ret, $msg) = $answerCF->AddToObject($class);
92 ok($ret, "Answer CF added to class: $msg");
93 my ($qid, $aid) = ($questionCF->Id, $answerCF->Id);
95 my %cvals = ('article1q' => 'Some question about swallows',
96 'article1a' => 'Some answer about Europe and Africa',
97 'article2q' => 'Another question about Monty Python',
98 'article2a' => 'Romani ite domum',
99 'article3q' => 'Why should I eat my supper?',
100 'article3a' => 'There are starving children in Africa',
101 'article4q' => 'What did Brian originally write?',
102 'article4a' => 'Romanes eunt domus');
104 # Create an article or two with our custom field values.
106 my $article1 = RT::Article->new($RT::SystemUser);
107 my $article2 = RT::Article->new($RT::SystemUser);
108 my $article3 = RT::Article->new($RT::SystemUser);
109 my $article4 = RT::Article->new($RT::SystemUser);
110 ($ret, $msg) = $article1->Create(Name => 'First article '.$$,
111 Summary => 'blah blah 1',
113 Topics => [$topic1->Id],
114 "CustomField-$qid" => $cvals{'article1q'},
115 "CustomField-$aid" => $cvals{'article1a'},
117 ok($ret, "article 1 created");
118 ($ret, $msg) = $article2->Create(Name => 'Second article '.$$,
119 Summary => 'foo bar 2',
121 Topics => [$topic11->Id],
122 "CustomField-$qid" => $cvals{'article2q'},
123 "CustomField-$aid" => $cvals{'article2a'},
125 ok($ret, "article 2 created");
126 ($ret, $msg) = $article3->Create(Name => 'Third article '.$$,
127 Summary => 'ping pong 3',
129 Topics => [$topic12->Id],
130 "CustomField-$qid" => $cvals{'article3q'},
131 "CustomField-$aid" => $cvals{'article3a'},
133 ok($ret, "article 3 created");
134 ($ret, $msg) = $article4->Create(Name => 'Fourth article '.$$,
135 Summary => 'hoi polloi 4',
137 Topics => [$topic2->Id],
138 "CustomField-$qid" => $cvals{'article4q'},
139 "CustomField-$aid" => $cvals{'article4a'},
141 ok($ret, "article 4 created");
144 my $parser = RT::EmailParser->new();
145 $parser->ParseMIMEEntityFromScalar('From: root@localhost
147 Subject: test ticket for articles
149 This is some form of new request.
150 May as well say something about Africa.');
152 my $ticket = RT::Ticket->new($RT::SystemUser);
154 ($ret, $obj, $msg) = $ticket->Create(Queue => 'General',
155 Subject => 'test ticket for articles '.$$,
156 MIMEObj => $parser->Entity);
157 ok($ret, "Test ticket for articles created: $msg");
160 #### Right. That's our data. Now begin the real testing.
162 isa_ok($m, 'Test::WWW::Mechanize');
163 ok($m->login, 'logged in');
164 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
167 $m->content_contains($article3->Name);
168 $m->follow_link_ok( {text => $article3->Name}, 'Articles -> '. $article3->Name );
169 $m->title_is("Article #" . $article3->Id . ": " . $article3->Name);
170 $m->follow_link_ok( { text => 'Modify'}, 'Article -> Modify' );
173 $m->content_like(qr/Refers to/, "found links edit box");
174 my $ticket_id = $ticket->Id;
175 my $turi = "t:$ticket_id";
176 my $a1uri = 'a:'.$article1->Id;
177 $m->submit_form(form_name => 'EditArticle',
178 fields => { $article3->Id.'-RefersTo' => $turi,
179 'RefersTo-'.$article3->Id => $a1uri }
182 $m->content_like(qr/Ticket.*$ticket_id/, "Ticket linkto was created");
183 $m->content_like(qr/URI.*$a1uri/, "Article linkfrom was created");
186 # Now try to extract an article from a link.
187 $m->get_ok($url."/Ticket/Display.html?id=".$ticket->Id,
188 "Loaded ticket display");
189 $m->content_like(qr/Extract Article/, "Article extraction link shows up");
190 $m->follow_link_ok( { text => 'Extract Article' }, '-> Extract Article' );
191 $m->content_contains($class->Name);
192 $m->follow_link_ok( { text => $class->Name }, 'Extract Article -> '. $class->Name );
193 $m->content_like(qr/Select topics for this article/i, 'selecting topic');
195 $m->set_visible([option => $topic1->Name]);
198 $m->set_visible([option => $answerCF->Name]);
200 $m->title_like(qr/Create a new article/, "got edit page from extraction");
201 $m->submit_form(form_name => 'EditArticle');
202 $m->title_like(qr/Modify article/);
203 $m->follow_link_ok( { text => 'Display' }, '-> Display' );
204 $m->content_like(qr/Africa/, "Article content exist");
205 $m->content_contains($ticket->Subject,
206 "Article references originating ticket");
208 diag("Test creating a ticket in Class2 and make sure we don't see Class1 Topics") if $ENV{TEST_VERBOSE};
210 $m->follow_link_ok( { text => 'Articles', url_regex => qr!^/Articles/! },
212 $m->follow_link_ok( {text => 'New Article' }, 'Articles -> New Article' );
213 $m->follow_link_ok( {text => 'in class '.$class2->Name }, 'New Article -> in class '.$class2->Name );
214 $m->content_lacks( $topic1->Name, "Topic1 from Class1 isn't shown" );
215 $m->content_lacks( $topic11->Name, "Topic11 from Class1 isn't shown" );
216 $m->content_lacks( $topic12->Name, "Topic12 from Class1 isn't shown" );
217 $m->content_lacks( $topic2->Name, "Topic2 from Class1 isn't shown" );
218 $m->content_contains( $gtopic->Name, "Global Topic is shown" );
219 $m->content_contains( $topic_class2->Name, "Class2 topic is shown" );