File: | t/0-basic.t |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | 1 1 1 | 1272034648562804 13468 10 | use Test::More; | ||||
2 | 1 1 1 | 481 2137 6 | use Test::Exception; | ||||
3 | 1 1 1 | 361 934567 19 | use Catalyst (); | ||||
4 | 1 1 1 | 210 928 31 | use FindBin; | ||||
5 | 1 1 1 | 3 1 96613 | use Path::Class::File; | ||||
6 | |||||||
7 | # setup our Catalyst :-) | ||||||
8 | 1 | 305903 | my $c = Catalyst->new(); | ||||
9 | 1 | 462 | $c->setup_log(); | ||||
10 | 1 | 1002 | $c->setup_home("$FindBin::Bin"); | ||||
11 | |||||||
12 | # | ||||||
13 | # test start... | ||||||
14 | # | ||||||
15 | # can we use it? | ||||||
16 | 1 | 709 | use_ok 'Catalyst::Controller::Combine'; | ||||
17 | |||||||
18 | # check for public methods | ||||||
19 | 1 | 321 | can_ok('Catalyst::Controller::Combine' => qw(do_combine default uri_for)); | ||||
20 | |||||||
21 | # check for private methods | ||||||
22 | 1 | 371 | can_ok('Catalyst::Controller::Combine' => qw(_collect_files _check_dependencies)); | ||||
23 | |||||||
24 | # instantiate | ||||||
25 | 1 | 316 | my $controller; | ||||
26 | 1 1 | 10 92 | lives_ok { $controller = $c->setup_component('Catalyst::Controller::Combine') } 'setup component worked'; | ||||
27 | |||||||
28 | 1 | 265 | is(ref($controller), 'Catalyst::Controller::Combine', 'controller class looks good'); | ||||
29 | |||||||
30 | # checking default attributes | ||||||
31 | 1 | 448 | is($controller->dir, 'static/combine', 'default directory looks good'); | ||||
32 | 1 | 639 | is($controller->extension, 'combine', 'default extension looks good'); | ||||
33 | 1 | 435 | is(ref($controller->depend), 'HASH', 'default dependency is HASH'); | ||||
34 | 1 1 | 392 6 | ok(scalar(keys(%{$controller->depend})) == 0, 'default dependency is empty'); | ||||
35 | 1 | 225 | is($controller->minifier, 'minify', 'default minify sub looks good'); | ||||
36 | |||||||
37 | # | ||||||
38 | # set some defaults and see if low level functions are working | ||||||
39 | # | ||||||
40 | 1 | 396 | $controller->dir('static/js'); | ||||
41 | 1 | 13 | $controller->extension('js'); | ||||
42 | |||||||
43 | # case 1: no file at all | ||||||
44 | 1 1 | 15 78 | lives_ok {$controller->_collect_files('Catalyst')} 'collect #1 works'; | ||||
45 | 1 | 222 | is_deeply($controller->{parts}, [], 'no parts'); | ||||
46 | 1 | 457 | is_deeply($controller->{files}, [], 'no files'); | ||||
47 | 1 | 421 | is_deeply($controller->{seen}, {}, 'nothing seen'); | ||||
48 | |||||||
49 | # case 2: one file, no extension given | ||||||
50 | 1 1 | 437 77 | lives_ok {$controller->_collect_files('Catalyst', 'js1')} 'collect #2 works'; | ||||
51 | 1 | 233 | is_deeply($controller->{parts}, ['js1'], '1 part'); | ||||
52 | 1 | 539 | is_deeply($controller->{files}, ["" . Path::Class::File->new($FindBin::Bin, qw(root static js js1.js))], '1 file'); | ||||
53 | 1 | 784 | is_deeply($controller->{seen}, {js1 => 0}, '1 file seen once'); | ||||
54 | |||||||
55 | # case 3: one file, extension given | ||||||
56 | 1 1 | 534 77 | lives_ok {$controller->_collect_files('Catalyst', 'js1.js')} 'collect #3 works'; | ||||
57 | 1 | 219 | is_deeply($controller->{parts}, ['js1'], '1 part'); | ||||
58 | 1 | 526 | is_deeply($controller->{files}, ["" . Path::Class::File->new($FindBin::Bin, qw(root static js js1.js))], '1 file'); | ||||
59 | 1 | 777 | is_deeply($controller->{seen}, {js1 => 0}, '1 file seen once'); | ||||
60 | |||||||
61 | # case 4: one file, strange extension given | ||||||
62 | 1 1 | 533 80 | lives_ok {$controller->_collect_files('Catalyst', 'js1.xxx')} 'collect #4 works'; | ||||
63 | 1 | 217 | is_deeply($controller->{parts}, [], 'no parts'); | ||||
64 | 1 | 423 | is_deeply($controller->{files}, [], 'no files'); | ||||
65 | 1 | 489 | is_deeply($controller->{seen}, {}, 'nothing seen'); | ||||
66 | |||||||
67 | # case 5: non existing file, no extension given | ||||||
68 | 1 1 | 430 78 | lives_ok {$controller->_collect_files('Catalyst', 'jsxx1')} 'collect #5 works'; | ||||
69 | 1 | 217 | is_deeply($controller->{parts}, [], 'no parts'); | ||||
70 | 1 | 419 | is_deeply($controller->{files}, [], 'no files'); | ||||
71 | 1 | 415 | is_deeply($controller->{seen}, {}, 'no files seen'); | ||||
72 | |||||||
73 | # case 6: combination of existing and non existing files | ||||||
74 | 1 1 | 422 78 | lives_ok {$controller->_collect_files('Catalyst', 'js1.js', 'jsx.js', 'jsy', 'js2')} 'collect #6 works'; | ||||
75 | 1 | 223 | is_deeply($controller->{parts}, ['js1', 'js2'], '2 parts'); | ||||
76 | 1 | 727 | is_deeply($controller->{files}, | ||||
77 | ["" . Path::Class::File->new($FindBin::Bin, qw(root static js js1.js)), | ||||||
78 | "" . Path::Class::File->new($FindBin::Bin, qw(root static js js2.js))], '2 files'); | ||||||
79 | 1 | 1092 | is_deeply($controller->{seen}, {js1 => 0, js2 => 0}, '2 file seen once'); | ||||
80 | |||||||
81 | # | ||||||
82 | # response generation | ||||||
83 | # | ||||||
84 | 1 1 | 623 80 | lives_ok {$controller->do_combine($c, 'js1')} 'do_combine #1 works'; | ||||
85 | 1 | 322 | like($c->response->body, qr{/\* \s javascript \s 1 \s \*\/\s*}xms, 'response looks good'); | ||||
86 | |||||||
87 | 1 | 210 | done_testing; |