]> git.donarmstrong.com Git - debbugs.git/blob - t/08_pkgreport.t
df4861d9d0f22f7cd87e5cdae63c4e8796b8360f
[debbugs.git] / t / 08_pkgreport.t
1 # -*- mode: cperl;-*-
2
3
4 use Test::More tests => 3;
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 $pkgreport_cgi_handler = sub {
61      # I do not understand why this is necessary.
62      $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
63      # We cd here because pkgreport uses require ./common.pl
64      my $content = qx(cd cgi; perl -I.. -T pkgreport.cgi);
65      # Strip off the Content-Type: stuff
66      $content =~ s/^\s*Content-Type:[^\n]+\n*//si;
67      print $content;
68 };
69
70 my $port = 11342;
71
72 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($pkgreport_cgi_handler,$port),
73    'forked HTTP::Server::Simple successfully');
74
75
76 my $mech = Test::WWW::Mechanize->new(autocheck => 1);
77
78 $mech->get_ok('http://localhost:'.$port.'/?pkg=foo');
79
80 # I'd like to use $mech->title_ok(), but I'm not sure why it doesn't
81 # work.
82 ok($mech->content()=~ qr/package foo/i,
83    'Package title seems ok',
84   );
85
86 # Test more stuff here