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