Debian Codegraph @

t/classes/Dancer2-Core-Role-HasConfig/with.t

raw
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 # undefine ENV vars used as defaults for app environment in these tests
7 local $ENV{DANCER_ENVIRONMENT};
8 local $ENV{PLACK_ENV};
9
10 {
11
12 package Dev;
13 use Moo;
14 with 'Dancer2::Core::Role::HasConfig';
15
16 sub name {'Dev'}
17 sub _build_config {
18 return {
19 content_type => 'text/html',
20 charset => 'UTF-8',
21 environment => 'development',
22 template => 'Tiny',
23 }
24 }
25
26 }
27
28 my $d = Dev->new();
29 is $d->does('Dancer2::Core::Role::HasConfig'), 1,
30 'role Dancer2::Core::Role::Config is consumed';
31
32 is $d->config->{'environment'}, 'development', 'Correct config value';
33 is $d->config->{'template'}, 'Tiny', 'Correct config value';
34 is $d->settings->{'charset'}, 'UTF-8', 'Correct config value normalized';
35
36 $d->setting( 'entry_one', 'value_one', 'entry_two', 'value_two' );
37 is $d->config->{'entry_one'}, 'value_one', 'Correct config value set';
38 is $d->config->{'entry_two'}, 'value_two', 'Correct config value set';
39 ok $d->has_setting('entry_one'), 'Has value we set previously';
40 isnt $d->has_setting('entry_missing'), 1, 'Correctly missing value';
41
42 done_testing;