Commit | Line | Data |
c7ded7aa |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
d258fcb2 |
7 | use FindBin qw/$Bin/; |
8 | use lib "$Bin/lib"; |
d9d04ded |
9 | use Catalyst::Utils; |
4348c28b |
10 | use HTTP::Request::Common; |
6f8be318 |
11 | use Test::Exception; |
c7ded7aa |
12 | |
4348c28b |
13 | plan tests => 11; |
c7ded7aa |
14 | |
15 | use_ok('Catalyst::Test'); |
16 | |
17 | eval "get('http://localhost')"; |
18 | isnt( $@, "", "get returns an error message with no app specified"); |
19 | |
20 | eval "request('http://localhost')"; |
21 | isnt( $@, "", "request returns an error message with no app specified"); |
d9d04ded |
22 | |
4348c28b |
23 | # FIXME - These vhosts in tests tests should be somewhere else... |
24 | |
d9d04ded |
25 | sub customize { Catalyst::Test::_customize_request(@_) } |
26 | |
27 | { |
28 | my $req = Catalyst::Utils::request('/dummy'); |
29 | customize( $req ); |
30 | is( $req->header('Host'), undef, 'normal request is unmodified' ); |
31 | } |
32 | |
33 | { |
34 | my $req = Catalyst::Utils::request('/dummy'); |
35 | customize( $req, { host => 'customized.com' } ); |
36 | like( $req->header('Host'), qr/customized.com/, 'request is customizable via opts hash' ); |
37 | } |
38 | |
39 | { |
40 | my $req = Catalyst::Utils::request('/dummy'); |
41 | local $Catalyst::Test::default_host = 'localized.com'; |
42 | customize( $req ); |
43 | like( $req->header('Host'), qr/localized.com/, 'request is customizable via package var' ); |
44 | } |
45 | |
46 | { |
47 | my $req = Catalyst::Utils::request('/dummy'); |
48 | local $Catalyst::Test::default_host = 'localized.com'; |
49 | customize( $req, { host => 'customized.com' } ); |
50 | like( $req->header('Host'), qr/customized.com/, 'opts hash takes precedence over package var' ); |
51 | } |
52 | |
53 | { |
54 | my $req = Catalyst::Utils::request('/dummy'); |
55 | local $Catalyst::Test::default_host = 'localized.com'; |
56 | customize( $req, { host => '' } ); |
57 | is( $req->header('Host'), undef, 'default value can be temporarily cleared via opts hash' ); |
58 | } |
d258fcb2 |
59 | |
60 | # Back compat test, extra args used to be ignored, now a hashref of options. |
61 | use_ok('Catalyst::Test', 'TestApp', 'foobar'); |
4348c28b |
62 | |
63 | # Back compat test, ensure that request ignores anything which isn't a hash. |
64 | lives_ok { |
65 | request(GET('/dummy'), 'foo'); |
66 | } 'scalar additional param to request method ignored'; |
67 | lives_ok { |
68 | request(GET('/dummy'), []); |
69 | } 'array additional param to request method ignored'; |