Fix my retardedness with ::MVC:: warning having no conditional. Pull all the stuff...
[catagits/Catalyst-Runtime.git] / t / unit_load_catalyst_test.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use FindBin qw/$Bin/;
8 use lib "$Bin/lib";
9 use Catalyst::Utils;
10 use HTTP::Request::Common;
11 use Test::Exception;
12
13 plan tests => 11;
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");
22
23 # FIXME - These vhosts in tests tests should be somewhere else...
24
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 }
59
60 # Back compat test, extra args used to be ignored, now a hashref of options.
61 use_ok('Catalyst::Test', 'TestApp', 'foobar');
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';