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