completed the tests to use .pl config only
[catagits/Catalyst-Plugin-ConfigLoader.git] / t / 25-setting-config-file.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use lib "$FindBin::Bin/lib";
6
7 use Test::More;
8
9 BEGIN {
10
11     # Remove all relevant env variables to avoid accidental fail
12     foreach my $name ( grep { m{^(CATALYST|MOCKAPP)} } keys %ENV ) {
13         delete $ENV{ $name };
14     }
15
16     eval { require Catalyst; Catalyst->VERSION( '5.80001' ); };
17
18     plan skip_all => 'Catalyst 5.80001 required' if $@;
19     plan tests => 18;
20
21     use Catalyst::Test ();
22
23 }
24
25 ## TestApp1: a .conf config file exists but should not be loaded
26 {
27
28     Catalyst::Test->import('TestApp1');
29
30     note( "TestApp1" );
31
32     ok my ( $res, $c ) = ctx_request( '/' ), 'context object';
33
34     isa_ok( $c, "TestApp1" );
35
36     subtest "normal config loaded" => sub {
37
38         is( get( '/appconfig/foo' ), "bar1", "config var foo ok" );
39
40         ## a config var not set will give a blank web page hence ""
41         is( get( '/appconfig/bar' ), "", "config var in custom config" );
42
43     };
44     is( get( '/appconfig/bar' ), "", "custom config not loaded" );
45 }
46
47 ## TestApp2: config points to a file in addition to normal config and
48 ## should get loaded
49 {
50     Catalyst::Test->import('TestApp2');
51
52     note( "TestApp2" );
53
54     ok my ( $res, $c ) = ctx_request( '/' ), 'context object';
55
56     isa_ok( $c, "TestApp2" );
57
58     subtest "normal config loaded" => sub {
59
60         is( get( '/appconfig/foo' ), "bar2", "config var foo" );
61
62         is( get( '/appconfig/unspecified_variable' ), "", "unknown config var" );
63
64     };
65
66     is( get( '/appconfig/bar' ), "baz2", "custom config loaded" );
67 }
68
69 ## TestApp3: config points to a directory
70 {
71     Catalyst::Test->import('TestApp3');
72
73     note( "TestApp3" );
74
75     ok my ( $res, $c ) = ctx_request( '/' ), 'context object';
76
77     isa_ok( $c, "TestApp3" );
78
79     subtest "normal config loaded" => sub {
80
81         is( get( '/appconfig/foo' ), "bar3", "config var foo" );
82
83         is( get( '/appconfig/unspecified_variable' ), "", "unknown config var" );
84
85     };
86
87     is( get( '/appconfig/test3_conf3' ), "a_value", "custom config var3 set" );
88     is( get( '/appconfig/test3_conf4' ), "", "custom config var4 not set" );
89
90 }
91
92 ## TestApp4: config points to a directory with a suffix
93 {
94     Catalyst::Test->import('TestApp4');
95
96     note( "TestApp4" );
97
98     ok my ( $res, $c ) = ctx_request( '/' ), 'context object';
99
100     isa_ok( $c, "TestApp4" );
101
102     subtest "normal config loaded" => sub {
103
104         is( get( '/appconfig/foo' ), "bar4", "config var foo" );
105
106         is( get( '/appconfig/unspecified_variable' ), "", "unknown config var" );
107
108     };
109
110     is( get( '/appconfig/test4_conf3' ), "a_value", "custom config var3 set" );
111     is( get( '/appconfig/test4_conf4' ), "", "custom config var4 not set" );
112
113 }