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.
28 my %config = create_debbugs_configuration();
31 my $sendmail_dir = $config{sendmail_dir};
32 my $spool_dir = $config{spool_dir};
33 my $config_dir = $config{config_dir};
37 # We're going to use create mime message to create these messages, and
38 # then just send them to receive.
41 send_message(to=>'submit@bugs.something',
42 headers => [To => 'submit@bugs.something',
43 From => 'foo@bugs.something',
44 Subject => 'Submiting a bug '.$bug,
46 body => <<EOF) or fail('Unable to send message');
50 This is a silly bug $bug
54 # next, we check to see that (at least) the proper messages have been
55 # sent out. 1) ack to submitter 2) mail to maintainer
57 # This keeps track of the previous size of the sendmail directory
60 num_messages_sent($SD_SIZE,10,
62 'submit messages appear to have been sent out properly',
66 # now send a message to the bug
68 send_message(to => '1@bugs.something',
69 headers => [To => '1@bugs.something',
70 From => 'foo@bugs.something',
71 Subject => 'Sending a message to a bug',
73 body => <<EOF) or fail('sending message to 1@bugs.someting failed');
81 num_messages_sent($SD_SIZE,2,
83 '1@bugs.something messages appear to have been sent out properly');
85 # just check to see that control doesn't explode
86 send_message(to => 'control@bugs.something',
87 headers => [To => 'control@bugs.something',
88 From => 'foo@bugs.something',
89 Subject => 'Munging a bug',
91 body => <<EOF) or fail 'message to control@bugs.something failed';
96 # now we need to check to make sure the control message was processed without errors
97 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
98 'control@bugs.something message was parsed without errors');
99 eval "use Debbugs::Status qw(read_bug writebug);";
100 my $status = read_bug(bug=>10);
101 ok($status->{blockedby} eq '2','bug 10 is blocked by 2 (and only 2)');
102 $status = read_bug(bug=>2);
103 ok($status->{blocks} eq '10','bug 2 blocks 10 (and only 10)');
105 send_message(to => 'control@bugs.something',
106 headers => [To => 'control@bugs.something',
107 From => 'foo@bugs.something',
108 Subject => 'Munging a bug',
110 body => <<EOF) or fail 'message to control@bugs.something failed';
115 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
116 'control@bugs.something message was parsed without errors');
117 $status = read_bug(bug=>10);
118 ok(is_deeply([sort split /\ /,$status->{blockedby}],[qw(2 3 4)]),'bug 10 is blocked by exactly 2, 3, and 4');
119 send_message(to => 'control@bugs.something',
120 headers => [To => 'control@bugs.something',
121 From => 'foo@bugs.something',
122 Subject => 'Munging a bug',
124 body => <<EOF) or fail 'message to control@bugs.something failed';
129 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
130 'control@bugs.something message was parsed without errors');
132 $status = read_bug(bug=>10);
133 ok(is_deeply([sort split /\ /,$status->{blockedby}],[qw(3 4)]),'bug 10 is blocked by exactly 3 and 4');
134 $status = read_bug(bug=>3);
135 ok($status->{blocks} eq '10','bug 3 blocks exactly 10');
137 send_message(to => 'control@bugs.something',
138 headers => [To => 'control@bugs.something',
139 From => 'foo@bugs.something',
140 Subject => 'Munging a bug',
142 body => <<EOF) or fail 'message to control@bugs.something failed';
146 ok(system('sh','-c','find '.$sendmail_dir.q( -type f | xargs grep -q "Subject: Processed: Munging a bug")) == 0,
147 'control@bugs.something message was parsed without errors');
150 $status = read_bug(bug=>3);
151 ok($status->{blockedby} eq '5','bug 3 is blocked by exactly 5');
153 # Check how this blocked bug is presented on the web interface
155 # start up an HTTP::Server::Simple
156 my $bugreport_cgi_handler = sub {
157 # I do not understand why this is necessary.
158 $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
159 my $content = qx(perl -I. -T cgi/bugreport.cgi);
160 $content =~ s/^\s*Content-Type:[^\n]+\n*//si;
166 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($bugreport_cgi_handler,$port),
167 'forked HTTP::Server::Simple successfully');
169 my $mech = Test::WWW::Mechanize->new();
171 $mech->get_ok('http://localhost:'.$port.'/?bug=10',
174 ok($mech->content() =~ qr//i,
175 'Title of bug is \'Submitting a bug\'');
177 ok($mech->content() =~ qr/Added blocking bug\(s\) of <a[^>]+10[^>]+>10<\/a>: <a[^>]+2[^>]+>2<\/a>/i,
178 '\'Added blocking bug(s) of x: y\' received markup');
180 $mech->get_ok('http://localhost:'.$port.'/?bug=2',
183 ok($mech->content() =~ qr/Added indication that bug <a[^>]+2[^>]+>2<\/a> blocks <a[^>]+10[^>]+>10<\/a>/i,
184 '\'indication that bug x blocks y\' received markup');