Commit | Line | Data |
6bc86362 |
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 | |
97ae89ab |
13 | use Test::More tests => 8; |
6bc86362 |
14 | use Test::Exception; |
15 | |
16 | BEGIN { |
17 | diag( |
2d40faef |
18 | "\n###################################################################\n", |
6bc86362 |
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 | |
ab0b00e3 |
32 | use Test::WWW::Mechanize::Catalyst; |
6bc86362 |
33 | my $m = Test::WWW::Mechanize::Catalyst->new; |
34 | |
cfd812d6 |
35 | my $skip = 0; |
36 | TRY_CONNECT: { |
37 | eval { $m->get('/') }; |
6bc86362 |
38 | |
97ae89ab |
39 | if ($@ || $m->content =~ /Can't connect to \w+:$PORT/) { |
cfd812d6 |
40 | $skip = $@ || $m->content; |
41 | } |
42 | } |
43 | |
44 | SKIP: { |
97ae89ab |
45 | skip $skip, 7 if $skip; |
cfd812d6 |
46 | lives_ok { $m->get_ok( '/', 'Get a multi Content-Type response' ) } |
47 | 'Survive to a multi Content-Type sting'; |
48 | |
49 | is( $m->ct, 'text/html', 'Multi Content-Type Content-Type' ); |
50 | $m->title_is( 'Root', 'Multi Content-Type title' ); |
51 | $m->content_contains( "Hello, test \x{263A}!", 'Multi Content-Type body' ); |
97ae89ab |
52 | |
53 | # Test a redirect with a remote server now too. |
54 | $m->get_ok( '/hello' ); |
55 | is($m->uri, "$ENV{CATALYST_SERVER}/"); |
cfd812d6 |
56 | } |
6bc86362 |
57 | |
58 | END { |
d6fc3a22 |
59 | if ( $pid && $pid != 0 ) { |
6bc86362 |
60 | kill 9, $pid; |
61 | } |
62 | } |
63 | |
64 | 1; |
65 | |