]> git.donarmstrong.com Git - debbugs.git/blob - t/07_bugreport.t
Control: Add missing full stop at the end of "Changed" messages
[debbugs.git] / t / 07_bugreport.t
1 # -*- mode: cperl;-*-
2
3
4 use Test::More tests => 16;
5
6 use warnings;
7 use strict;
8
9 # Here, we're going to shoot messages through a set of things that can
10 # happen.
11
12 # First, we're going to send mesages to receive.
13 # To do so, we'll first send a message to submit,
14 # then send messages to the newly created bugnumber.
15
16 use IO::File;
17 use File::Temp qw(tempdir);
18 use Cwd qw(getcwd);
19 use Debbugs::MIME qw(create_mime_message);
20 use File::Basename qw(dirname basename);
21 use Test::WWW::Mechanize;
22 # The test functions are placed here to make things easier
23 use lib qw(t/lib);
24 use DebbugsTest qw(:all);
25
26 my %config;
27 eval {
28      %config = create_debbugs_configuration(debug => exists $ENV{DEBUG}?$ENV{DEBUG}:0);
29 };
30 if ($@) {
31      BAIL_OUT($@);
32 }
33
34 # Output some debugging information if there's an error
35 END{
36      if ($ENV{DEBUG}) {
37           foreach my $key (keys %config) {
38                diag("$key: $config{$key}\n");
39           }
40      }
41 }
42
43 # create a bug
44 send_message(to=>'submit@bugs.something',
45              headers => [To   => 'submit@bugs.something',
46                          From => 'foo@bugs.something',
47                          Subject => 'Submitting a bug',
48                         ],
49              body => <<EOF) or fail('Unable to send message');
50 Package: foo
51 Severity: normal
52
53 This is a silly bug
54 EOF
55
56
57 # test bugreport.cgi
58
59 # start up an HTTP::Server::Simple
60 my $bugreport_cgi_handler = sub {
61      # I do not understand why this is necessary.
62      $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
63      my $content = qx(perl -I. -T cgi/bugreport.cgi);
64      $content =~ s/^\s*Content-Type:[^\n]+\n*//si;
65      print $content;
66 };
67
68 my $port = 11342;
69
70 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($bugreport_cgi_handler,$port),
71    'forked HTTP::Server::Simple successfully');
72
73 my $mech = Test::WWW::Mechanize->new();
74
75 $mech->get_ok('http://localhost:'.$port.'/?bug=1',
76               'Page received ok');
77 ok($mech->content() =~ qr/\<title\>\#1.+Submitting a bug/i,
78    'Title of bug is submitting a bug');
79
80 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mbox=yes',
81               'Page received ok');
82 ok($mech->content() =~ qr/Subject: Submitting a bug/i,
83    'Subject of bug maibox is right');
84 ok($mech->content() =~ qr/^From /m,
85    'Starts with a From appropriately');
86
87 $mech->get_ok('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
88               'Page received ok');
89 print STDERR $mech->content();
90 ok($mech->content() !~ qr/[\x01\x02\x03\x05\x06\x07]/i,
91    'No unescaped states');
92
93 # now test the output of some control commands
94 my @control_commands =
95      (
96       reassign_foo => {command => 'reassign',
97                        value   => 'bar',
98                        regex => qr{<strong>bug reassigned from package &#39;<a href="pkgreport\.cgi\?package=foo">foo</a>&#39; to &#39;<a href="pkgreport\.cgi\?package=bar">bar</a>},
99                       },
100       forwarded_foo      => {command => 'forwarded',
101                              value   => 'https://foo.invalid/bugs?id=1',
102                              regex   => qr{<strong>Set bug forwarded-to-address to &#39;<a href="https://foo\.invalid/bugs\?id=1">https://foo\.invalid/bugs\?id=1</a>&#39;\.},
103                             },
104       forwarded_foo_2    => {command => 'forwarded',
105                              value   => 'https://foo.example/bugs?id=1',
106                              regex   => qr{<strong>Changed bug forwarded-to-address to &#39;<a href="https://foo\.example/bugs\?id=1">https://foo\.example/bugs\?id=1</a>&#39; from &#39;<a href="https://foo\.invalid/bugs\?id=1">https://foo\.invalid/bugs\?id=1</a>&#39;\.},
107                             },
108       clone        => {command => 'clone',
109                        value   => '-1',
110                        regex   => qr{<strong>Bug <a href="bugreport.cgi\?bug=1">1</a> cloned as bug <a href="bugreport.cgi\?bug=2">2</a>},
111                       },
112      );
113
114 while (my ($command,$control_command) = splice(@control_commands,0,2)) {
115   # just check to see that control doesn't explode
116   $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
117     and $control_command->{value} !~ /^\s/;
118   send_message(to => 'control@bugs.something',
119                headers => [To   => 'control@bugs.something',
120                            From => 'foo@bugs.something',
121                            Subject => "Munging a bug with $command",
122                           ],
123                body => <<EOF) or fail 'message to control@bugs.something failed';
124 debug 10
125 $control_command->{command} 1$control_command->{value}
126 thanks
127 EOF
128                                   ;
129   # Now test that the output has changed accordingly
130   $mech->get_ok('http://localhost:'.$port.'/?bug=1',
131                 'Page received ok');
132   like($mech->content(), $control_command->{regex},
133        'Page matches regex');
134 }
135
136 # Other tests for bugs in the page should be added here eventually
137