Commit latest CPAN ver of TWMC to repo
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / multi_content_type.t
1 #!perl
2 use strict;
3 use warnings;
4 use lib qw(lib t/lib);
5
6 my $PORT;
7
8 BEGIN {
9     $PORT = $ENV{TWMC_TEST_PORT} || 7357;
10     $ENV{CATALYST_SERVER} ||= "http://localhost:$PORT";
11 }
12
13 use Test::More tests => 6;
14 use Test::Exception;
15
16 BEGIN {
17     diag(
18         "###################################################################\n",
19         "Starting an external Catalyst HTTP server on port $PORT\n",
20         "To change the port, please set the TWMC_TEST_PORT env variable.\n",
21         "(The server will be automatically shut-down right after the tests).\n",
22         "###################################################################\n"
23     );
24 }
25
26 # Let's catch interrupts to force the END block execution.
27 $SIG{INT} = sub { warn "INT:$$"; exit };
28
29 use_ok 'ExternalCatty';
30 my $pid = ExternalCatty->background($PORT);
31
32 use Test::WWW::Mechanize::Catalyst 'ExternalCatty';
33 my $m = Test::WWW::Mechanize::Catalyst->new;
34
35 lives_ok { $m->get_ok( '/', 'Get a multi Content-Type response' ) }
36 'Survive to a multi Content-Type sting';
37
38 is( $m->ct, 'text/html', 'Multi Content-Type Content-Type' );
39 $m->title_is( 'Root', 'Multi Content-Type title' );
40 $m->content_contains( "Hello, test \x{263A}!", 'Multi Content-Type body' );
41
42 END {
43     if ( $pid > 0 ) {
44         kill 9, $pid;
45     }
46 }
47
48 1;
49