Fix starting the server, test still fucked however
[catagits/Test-WWW-Mechanize-Catalyst.git] / t / multi_content_type.t
CommitLineData
6bc86362 1#!perl
2use strict;
3use warnings;
4use lib qw(lib t/lib);
5
6my $PORT;
7
8BEGIN {
9 $PORT = $ENV{TWMC_TEST_PORT} || 7357;
6bc86362 10}
11
71896b6e 12use Test::More;
6bc86362 13use Test::Exception;
14
15BEGIN {
16 diag(
2d40faef 17 "\n###################################################################\n",
6bc86362 18 "Starting an external Catalyst HTTP server on port $PORT\n",
19 "To change the port, please set the TWMC_TEST_PORT env variable.\n",
20 "(The server will be automatically shut-down right after the tests).\n",
21 "###################################################################\n"
22 );
23}
24
25# Let's catch interrupts to force the END block execution.
26$SIG{INT} = sub { warn "INT:$$"; exit };
27
28use_ok 'ExternalCatty';
6435acdc 29my $pid;
30($pid, $PORT) = ExternalCatty->background($PORT);
31$ENV{CATALYST_SERVER} ||= "http://localhost:$PORT";
6bc86362 32
ab0b00e3 33use Test::WWW::Mechanize::Catalyst;
6bc86362 34my $m = Test::WWW::Mechanize::Catalyst->new;
35
71896b6e 36# Yeah, sorry - wait for the forked process to spin up...
37sleep 10;
38
cfd812d6 39my $skip = 0;
40TRY_CONNECT: {
41 eval { $m->get('/') };
6bc86362 42
97ae89ab 43 if ($@ || $m->content =~ /Can't connect to \w+:$PORT/) {
cfd812d6 44 $skip = $@ || $m->content;
dedbb26e 45 diag $m;
cfd812d6 46 }
47}
48
49SKIP: {
a4f0f1f6 50 skip $skip, 9 if $skip;
cfd812d6 51 lives_ok { $m->get_ok( '/', 'Get a multi Content-Type response' ) }
52 'Survive to a multi Content-Type sting';
53
54 is( $m->ct, 'text/html', 'Multi Content-Type Content-Type' );
55 $m->title_is( 'Root', 'Multi Content-Type title' );
56 $m->content_contains( "Hello, test \x{263A}!", 'Multi Content-Type body' );
97ae89ab 57
58 # Test a redirect with a remote server now too.
59 $m->get_ok( '/hello' );
60 is($m->uri, "$ENV{CATALYST_SERVER}/");
64c13f8e 61
62 $m->get_ok( '/host' );
63 $m->content_contains('Host: localhost:$PORT') or diag $m->content;
64
cfd812d6 65}
6bc86362 66
67END {
d6fc3a22 68 if ( $pid && $pid != 0 ) {
6bc86362 69 kill 9, $pid;
70 }
71}
72
71896b6e 73done_testing;
74
6bc86362 751;
76