File Coverage: t/1-inherit.t

# File Coverage

File: | t/1-inherit.t
Coverage: | 100.0%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 1272034650710471 12902 9 | use Test::More;
2 | 1 1 1 |  |  | 1 |  | 460 2092 5 | use Test::Exception;
3 | 1 1 1 |  |  | 1 |  | 349 932317 17 | use Catalyst ();
4 | 1 1 1 |  |  | 1 |  | 175 2 16 | use Catalyst::Controller::Combine ();
5 | 1 1 1 |  |  | 1 |  | 196 939 31 | use FindBin;
6 | 1 1 1 |  |  | 1 |  | 3 1 27 | use Path::Class::File;
7 |
8 |  |  |  |  |  |  | # a simple package
9 |  |  |  |  |  |  | {
10 | 1 |  |  |  |  | 408125 | package MyApp::Controller::Js;
11 | 1 1 1 |  |  | 1 |  | 2 2 7 | use Moose;
12 | 1 |  |  |  |  | 10 | extends 'Catalyst::Controller::Combine';
13 |
14 | 1 |  |  |  |  | 3465 | __PACKAGE__->config(
15 |  |  |  |  |  |  | # dir => 'static/js', # redundant, defaults to static/<<action_namespace>>
16 |  |  |  |  |  |  | # extension => 'js', # redundant, defaults to <<action_namespace>>
17 |  |  |  |  |  |  | depend => {
18 |  |  |  |  |  |  | js2 => 'js1',
19 |  |  |  |  |  |  | },
20 |  |  |  |  |  |  | # will be guessed from extension
21 |  |  |  |  |  |  | # mimetype => 'application/javascript',
22 |  |  |  |  |  |  | );
23 |  |  |  |  |  |  | }
24 |
25 |  |  |  |  |  |  | # setup our Catalyst :-)
26 | 1 |  |  |  |  | 184 | my $c = Catalyst->new();
27 | 1 |  |  |  |  | 388 | $c->setup_log();
28 | 1 |  |  |  |  | 918 | $c->setup_home("$FindBin::Bin");
29 |
30 | 1 |  |  |  |  | 693 | my $controller;
31 | 1 1 |  |  | 1 |  | 11 105 | lives_ok { $controller = $c->setup_component('MyApp::Controller::Js') } 'setup component worked';
32 |
33 | 1 |  |  |  |  | 340 | is(ref($controller), 'MyApp::Controller::Js', 'controller class looks good');
34 | 1 |  |  |  |  | 487 | ok($controller->isa('Catalyst::Controller::Combine'), 'is a Catalyst::Controller::Combine');
35 |
36 |  |  |  |  |  |  | # checking default attributes
37 | 1 |  |  |  |  | 217 | is($controller->dir, 'static/js', 'default directory looks good');
38 | 1 |  |  |  |  | 652 | is($controller->extension, 'js', 'default extension looks good');
39 | 1 |  |  |  |  | 428 | is(ref($controller->depend), 'HASH', 'default dependency is HASH');
40 | 1 |  |  |  |  | 398 | is_deeply($controller->depend, {js2 => 'js1'}, 'default dependency looks good');
41 | 1 |  |  |  |  | 579 | is($controller->minifier, 'minify', 'default minify sub looks good');
42 |
43 |  |  |  |  |  |  | # case 1: one file, no extension given
44 | 1 1 |  |  | 1 |  | 405 91 | lives_ok {$controller->_collect_files($c, 'js1')} 'collect #1 works';
45 | 1 |  |  |  |  | 220 | is_deeply($controller->{parts}, ['js1'], '1 part');
46 | 1 |  |  |  |  | 530 | is_deeply($controller->{files}, ["" . Path::Class::File->new($FindBin::Bin, qw(root static js js1.js))], '1 file');
47 | 1 |  |  |  |  | 794 | is_deeply($controller->{seen}, {js1 => 0}, '1 file seen once');
48 |
49 |  |  |  |  |  |  | # case 2: one file, no extension given -- dependency should add one
50 | 1 1 |  |  | 1 |  | 530 78 | lives_ok {$controller->_collect_files($c, 'js2')} 'collect #2 works';
51 | 1 |  |  |  |  | 220 | is_deeply($controller->{parts}, ['js1','js2'], '2 parts');
52 | 1 |  |  |  |  | 629 | is_deeply($controller->{files},
53 |  |  |  |  |  |  | ["" . Path::Class::File->new($FindBin::Bin, qw(root static js js1.js)),
54 |  |  |  |  |  |  | "" . Path::Class::File->new($FindBin::Bin, qw(root static js js2.js))], '2 files');
55 |  |  |  |  |  |  | # "$FindBin::Bin/root/static/js/js1.js","$FindBin::Bin/root/static/js/js2.js"], '2 files');
56 | 1 |  |  |  |  | 1097 | is_deeply($controller->{seen}, {js1 => 1, js2 => 0}, '2 files seen once');
57 |
58 |  |  |  |  |  |  | # case 3: two files, no extension given
59 | 1 1 |  |  | 1 |  | 624 77 | lives_ok {$controller->_collect_files($c, 'js1','js2')} 'collect #3 works';
60 | 1 |  |  |  |  | 219 | is_deeply($controller->{parts}, ['js1','js2'], '2 parts');
61 | 1 |  |  |  |  | 651 | is_deeply($controller->{files},
62 |  |  |  |  |  |  | ["" . Path::Class::File->new($FindBin::Bin, qw(root static js js1.js)),
63 |  |  |  |  |  |  | "" . Path::Class::File->new($FindBin::Bin, qw(root static js js2.js))], '2 files');
64 | 1 |  |  |  |  | 1099 | is_deeply($controller->{seen}, {js1 => 1, js2 => 0}, '2 files seen once');
65 |
66 | 1 |  |  |  |  | 688 | done_testing;