3 use Test::More tests => 20;
8 # Here, we're going to shoot messages through a set of things that can
11 # First, we're going to send mesages to receive.
12 # To do so, we'll first send a message to submit,
13 # then send messages to the newly created bugnumber.
16 use File::Temp qw(tempdir);
18 use Debbugs::MIME qw(create_mime_message);
19 use File::Basename qw(dirname basename);
20 # The test functions are placed here to make things easier
22 use DebbugsTest qw(:all);
24 use Test::WWW::Mechanize;
26 # HTTP::Server:::Simple defines a SIG{CHLD} handler that breaks system; undef it here.
30 %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
36 my $sendmail_dir = $config{sendmail_dir};
37 my $spool_dir = $config{spool_dir};
38 my $config_dir = $config{config_dir};
42 diag("spool_dir: $spool_dir\n");
43 diag("config_dir: $config_dir\n");
44 diag("sendmail_dir: $sendmail_dir\n");
48 # We're going to use create mime message to create these messages, and
49 # then just send them to receive.
52 send_message(to=>'submit@bugs.something',
53 headers => [To => 'submit@bugs.something',
54 From => 'foo@bugs.something',
55 Subject => 'Submiting a bug '.$bug,
57 body => <<EOF) or fail('Unable to send message');
61 This is a silly bug $bug
65 # next, we check to see that (at least) the proper messages have been
66 # sent out. 1) ack to submitter 2) mail to maintainer
68 # This keeps track of the previous size of the sendmail directory
71 num_messages_sent($SD_SIZE,10,
73 'submit messages appear to have been sent out properly',
77 # now send a message to the bug
79 send_message(to => '1@bugs.something',
80 headers => [To => '1@bugs.something',
81 From => 'foo@bugs.something',
82 Subject => 'Sending a message to a bug',
84 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
92 num_messages_sent($SD_SIZE,2,
94 '1@bugs.something messages appear to have been sent out properly');
96 # just check to see that control doesn't explode
97 send_message(to => 'control@bugs.something',
98 headers => [To => 'control@bugs.something',
99 From => 'foo@bugs.something',
100 Subject => 'Munging a bug',
102 body => <<EOF) or fail 'message to control@bugs.something failed';
107 # now we need to check to make sure the control message was processed without errors
108 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
109 'control@bugs.something message was parsed without errors');
110 eval "use Debbugs::Status qw(read_bug writebug);";
111 my $status = read_bug(bug=>10);
112 ok($status->{blockedby} eq '2','bug 10 is blocked by 2 (and only 2)');
113 $status = read_bug(bug=>2);
114 ok($status->{blocks} eq '10','bug 2 blocks 10 (and only 10)');
116 send_message(to => 'control@bugs.something',
117 headers => [To => 'control@bugs.something',
118 From => 'foo@bugs.something',
119 Subject => 'Munging a bug',
121 body => <<EOF) or fail 'message to control@bugs.something failed';
126 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
127 'control@bugs.something message was parsed without errors');
128 $status = read_bug(bug=>10);
129 ok(is_deeply([sort split /\ /,$status->{blockedby}],[qw(2 3 4)]),'bug 10 is blocked by exactly 2, 3, and 4');
130 send_message(to => 'control@bugs.something',
131 headers => [To => 'control@bugs.something',
132 From => 'foo@bugs.something',
133 Subject => 'Munging a bug',
135 body => <<EOF) or fail 'message to control@bugs.something failed';
140 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
141 'control@bugs.something message was parsed without errors');
143 $status = read_bug(bug=>10);
144 ok(is_deeply([sort split /\ /,$status->{blockedby}],[qw(3 4)]),'bug 10 is blocked by exactly 3 and 4');
145 $status = read_bug(bug=>3);
146 ok($status->{blocks} eq '10','bug 3 blocks exactly 10');
148 send_message(to => 'control@bugs.something',
149 headers => [To => 'control@bugs.something',
150 From => 'foo@bugs.something',
151 Subject => 'Munging a bug',
153 body => <<EOF) or fail 'message to control@bugs.something failed';
157 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
158 'control@bugs.something message was parsed without errors');
161 $status = read_bug(bug=>3);
162 ok($status->{blockedby} eq '5','bug 3 is blocked by exactly 5');
164 # Check how this blocked bug is presented on the web interface
166 # start up an HTTP::Server::Simple
167 my $bugreport_cgi_handler = sub {
168 # I do not understand why this is necessary.
169 $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
170 my $content = qx(perl -I. -T cgi/bugreport.cgi);
171 $content =~ s/^\s*Content-Type:[^\n]+\n*//si;
177 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($bugreport_cgi_handler,$port),
178 'forked HTTP::Server::Simple successfully');
180 my $mech = Test::WWW::Mechanize->new();
182 $mech->get_ok('http://localhost:'.$port.'/?bug=10',
185 ok($mech->content() =~ qr//i,
186 'Title of bug is \'Submitting a bug\'');
188 ok($mech->content() =~ qr/Added blocking bug\(s\) of <a[^>]+10[^>]+>10<\/a>: <a[^>]+2[^>]+>2<\/a>/i,
189 '\'Added blocking bug(s) of x: y\' received markup');
191 $mech->get_ok('http://localhost:'.$port.'/?bug=2',
194 ok($mech->content() =~ qr/Added indication that bug <a[^>]+2[^>]+>2<\/a> blocks <a[^>]+10[^>]+>10<\/a>/i,
195 '\'indication that bug x blocks y\' received markup');