72146604b8922ab75238390f7c096cddc258ee06
[catagits/Catalyst-Plugin-ConfigLoader-Environment.git] / t / 01-live.t
1 #!/usr/bin/perl
2 # 01-live.t 
3 # Copyright (c) 2006 Jonathan Rockway <jrockway@cpan.org>
4
5 use Test::More tests => 12;
6 use FindBin qw($Bin);
7 use lib "$Bin/lib";
8 BEGIN {
9     $ENV{TESTAPP_foo} = 'foo';
10     $ENV{TESTAPP_bar} = 'bar';
11     $ENV{TESTAPP_foo_bar_baz} = 'quux';
12     $ENV{TESTAPP_quux} = q%[1,2,3,4]%;
13     $ENV{TESTAPP_View::TestView_foo} = "Test View's foo!";
14     $ENV{TESTAPP_View::TestView_quux} = q%[1,2,3,"Test View's quux!",{"foo":"bar"}]%;
15     $ENV{TESTAPP_View__TestView_bar} = "Test View's bar!";
16     $ENV{TESTAPP_Model__TestModel} = q%{"bar":"baz"}%;
17     
18 }
19
20 use Catalyst::Test 'TestApp';
21
22 ok(my $r = request('/'), 'request /');
23 ok($r->is_success, 'that worked');
24
25 my $config = eval $r->content;
26 ok(ref $config, 'got config');
27
28 is($config->{foo}, 'foo', 'got foo');
29 is($config->{bar}, 'bar', 'got bar');
30 is($config->{foo_bar_baz}, 'quux', 'got foo_bar_baz');
31 is_deeply($config->{quux}, [1,2,3,4], 'JSON for simple param');
32
33 my $view = get('/foo/foo');
34 is($view, "Test View's foo!", 'got View::TestView->foo');
35
36 $view = get('/foo/bar');
37 is($view, "Test View's bar!", 'got View::TestView->bar');
38
39 $view = get('/foo/quux');
40 eval $view;
41 no warnings 'once';
42 is_deeply($quux, [1,2,3,"Test View's quux!",{ foo => 'bar'}], 
43           'JSON for :: sub-param');
44
45 $r = request('/model');
46 ok($r->is_success, 'got /model');
47 my $model_attributes = eval $r->content;
48 is_deeply($model_attributes,
49           {
50               foo => 'bar', # From __PACKAGE__ default config
51               bar => 'baz', # Merged from my environment hash
52           },
53           'JSON for top-level :: param with hash merge');