]> Dogcows Code - chaz/p5-CGI-Ex/blob - t/3_conf_00_base.t
CGI::Ex 2.00
[chaz/p5-CGI-Ex] / t / 3_conf_00_base.t
1 # -*- Mode: Perl; -*-
2
3 =head1 NAME
4
5 3_conf_00_base.t - Test for the basic functionality of CGI::Ex::Conf
6
7 =cut
8
9 use strict;
10 use Test::More tests => 24;
11
12 use_ok('CGI::Ex::Conf');
13
14 my $dir = __FILE__;
15 $dir =~ tr|\\|/|; # should probably use File::Spec
16 $dir =~ s|[^/]+$|../samples| || die "Couldn't determine dir";
17 $dir =~ s|^t/|./t/|; # to satisfy conf
18
19 my $obj = CGI::Ex::Conf->new({
20 paths => ["$dir/conf_path_1", "$dir/conf_path_3"],
21 });
22
23 ### most test for the reading of files
24 ### are actually performed in the validation tests
25
26 ok($obj);
27
28 my $hash = $obj->read('apples.pl');
29 ok($hash);
30 ok($hash->{quantity});
31
32 $hash = $obj->read('apples.pl');
33 ok($hash);
34 ok($hash->{quantity});
35
36
37 local $CGI::Ex::Conf::DIRECTIVE = 'FIRST';
38 $hash = $obj->read('apples.pl');
39 ok($hash);
40 ok($hash->{quantity} == 20);
41 ok($hash->{foo} eq 'file1');
42
43 local $CGI::Ex::Conf::DIRECTIVE = 'LAST';
44 $hash = $obj->read('apples.pl');
45 ok($hash);
46 ok($hash->{quantity} == 30);
47 ok($hash->{foo} eq 'file2');
48
49 $hash = $obj->read('apples.pl', {directive => 'MERGE'});
50 ok($hash);
51 ok($hash->{quantity} == 30);
52 ok($hash->{foo} eq 'file1'); # has immutable value
53
54
55 local $obj->{directive} = 'FIRST';
56 $hash = $obj->read('oranges.pl');
57 ok($hash);
58 ok($hash->{quantity} == 20);
59 ok($hash->{foo} eq 'file1');
60
61 local $obj->{directive} = 'LAST';
62 $hash = $obj->read('oranges.pl');
63 ok($hash);
64 ok($hash->{quantity} == 30);
65 ok($hash->{foo} eq 'file2');
66
67 local $obj->{directive} = 'MERGE';
68 $hash = $obj->read('oranges.pl');
69 ok($hash);
70 ok($hash->{quantity} == 20); # has immutable key so all values are immutable
71 ok($hash->{foo} eq 'file1'); # has immutable key so all values are immutable
72
73
This page took 0.032089 seconds and 4 git commands to generate.