]> git.donarmstrong.com Git - debbugs.git/blobdiff - t/07_bugreport.t
add calculate_etags and etags_do_not_match methods
[debbugs.git] / t / 07_bugreport.t
index ea33725e6d6967351b0d91ee2339aae6c5daf643..78d89b1d0e1c060442b11793eaa831589476e40a 100644 (file)
@@ -1,7 +1,7 @@
 # -*- mode: cperl;-*-
-# $Id: 05_mail.t,v 1.1 2005/08/17 21:46:17 don Exp $
 
-use Test::More tests => 2;
+
+use Test::More tests => 16;
 
 use warnings;
 use strict;
@@ -22,7 +22,6 @@ use Test::WWW::Mechanize;
 # The test functions are placed here to make things easier
 use lib qw(t/lib);
 use DebbugsTest qw(:all);
-use Data::Dumper;
 
 my %config;
 eval {
@@ -45,7 +44,7 @@ END{
 send_message(to=>'submit@bugs.something',
             headers => [To   => 'submit@bugs.something',
                         From => 'foo@bugs.something',
-                        Subject => 'Submiting a bug',
+                        Subject => 'Submitting a bug',
                        ],
             body => <<EOF) or fail('Unable to send message');
 Package: foo
@@ -61,7 +60,9 @@ EOF
 my $bugreport_cgi_handler = sub {
      # I do not understand why this is necessary.
      $ENV{DEBBUGS_CONFIG_FILE} = "$config{config_dir}/debbugs_config";
-     print qx(perl -I. -T cgi/bugreport.cgi);
+     my $content = qx(perl -I. -T cgi/bugreport.cgi);
+     $content =~ s/^\s*Content-Type:[^\n]+\n*//si;
+     print $content;
 };
 
 my $port = 11342;
@@ -69,7 +70,68 @@ my $port = 11342;
 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($bugreport_cgi_handler,$port),
    'forked HTTP::Server::Simple successfully');
 
-
 my $mech = Test::WWW::Mechanize->new();
 
-$mech->get_ok('http://localhost:'.$port.'/?bug=1');
+$mech->get_ok('http://localhost:'.$port.'/?bug=1',
+             'Page received ok');
+ok($mech->content() =~ qr/\<title\>\#1.+Submitting a bug/i,
+   'Title of bug is submitting a bug');
+
+$mech->get_ok('http://localhost:'.$port.'/?bug=1;mbox=yes',
+              'Page received ok');
+ok($mech->content() =~ qr/Subject: Submitting a bug/i,
+   'Subject of bug maibox is right');
+ok($mech->content() =~ qr/^From /m,
+   'Starts with a From appropriately');
+
+$mech->get_ok('http://localhost:'.$port.'/?bug=1;mboxmaint=yes',
+              'Page received ok');
+print STDERR $mech->content();
+ok($mech->content() !~ qr/[\x01\x02\x03\x05\x06\x07]/i,
+   'No unescaped states');
+
+# now test the output of some control commands
+my @control_commands =
+     (
+      reassign_foo => {command => 'reassign',
+                      value   => 'bar',
+                      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>},
+                     },
+      forwarded_foo      => {command => 'forwarded',
+                            value   => 'https://foo.invalid/bugs?id=1',
+                            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;\.},
+                           },
+      forwarded_foo_2    => {command => 'forwarded',
+                            value   => 'https://foo.example/bugs?id=1',
+                            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;\.},
+                           },
+      clone        => {command => 'clone',
+                      value   => '-1',
+                      regex   => qr{<strong>Bug <a href="bugreport.cgi\?bug=1">1</a> cloned as bug <a href="bugreport.cgi\?bug=2">2</a>},
+                     },
+     );
+
+while (my ($command,$control_command) = splice(@control_commands,0,2)) {
+  # just check to see that control doesn't explode
+  $control_command->{value} = " $control_command->{value}" if length $control_command->{value}
+    and $control_command->{value} !~ /^\s/;
+  send_message(to => 'control@bugs.something',
+              headers => [To   => 'control@bugs.something',
+                          From => 'foo@bugs.something',
+                          Subject => "Munging a bug with $command",
+                         ],
+              body => <<EOF) or fail 'message to control@bugs.something failed';
+debug 10
+$control_command->{command} 1$control_command->{value}
+thanks
+EOF
+                                 ;
+  # Now test that the output has changed accordingly
+  $mech->get_ok('http://localhost:'.$port.'/?bug=1',
+               'Page received ok');
+  like($mech->content(), $control_command->{regex},
+       'Page matches regex');
+}
+
+# Other tests for bugs in the page should be added here eventually
+