]> git.donarmstrong.com Git - deb_pkgs/libapache-gallery-perl.git/blob - t/004_cache_dir.t
[svn-inject] Installing original source of libapache-gallery-perl (0.99-svn060811)
[deb_pkgs/libapache-gallery-perl.git] / t / 004_cache_dir.t
1 use Apache::Gallery;
2 my $tests;
3 BEGIN {
4         $tests=8;
5         eval { require Test::MockObject };
6         if ($@) {
7                 print("1..$tests\n");
8                 for (1..$tests) {
9                         print ("ok $_ # skip Test::MockObject not found\n");
10                 }
11                 exit 0;
12         }
13 }
14 use Test::More tests => $tests;
15 use File::Spec;
16
17 # Test these cases:
18 # +--------------------------------------------------+
19 # | No. | GalleryCacheDir | Virtual | Strip Filename |
20 # |  1  |      undef      |    y    |       y        |
21 # |  2  |      undef      |    y    |       n        |
22 # |  3  |      undef      |    n    |       y        |
23 # |  4  |      undef      |    n    |       n        |
24 # |  5  |  't/cachetest'  |    y    |       y        |
25 # |  6  |  't/cachetest'  |    y    |       n        |
26 # |  7  |  't/cachetest'  |    n    |       y        |
27 # |  8  |  't/cachetest'  |    n    |       n        |
28 # +-----+-----------------+---------+----------------+
29
30 sub request {
31         my ($cachedir, $virtual) = @_;
32         my $r=Test::MockObject->new();
33         $r->set_always('location', '/location');
34         $r->set_always('uri', '/uripath1/uripath2/urifile');
35         $r->set_always('dir_config', $cachedir);
36         my $server=Test::MockObject->new();
37         $server->set_always('is_virtual', $virtual);
38         $server->set_always('server_hostname', 'hostname' );
39         $r->set_always('server', $server);
40
41         return $r;
42 }
43
44 my $r=request(undef, 1);
45 is(Apache::Gallery::cache_dir($r, 1), '/var/tmp/Apache-Gallery/hostname/uripath1/uripath2');
46 is(Apache::Gallery::cache_dir($r, 0), '/var/tmp/Apache-Gallery/hostname/uripath1/uripath2/urifile');
47
48 $r=request(undef, 0);
49 is(Apache::Gallery::cache_dir($r, 1), '/var/tmp/Apache-Gallery/location/uripath1/uripath2');
50 is(Apache::Gallery::cache_dir($r, 0), '/var/tmp/Apache-Gallery/location/uripath1/uripath2/urifile');
51
52 $r=request('t/cachetest', 1);
53 is(Apache::Gallery::cache_dir($r, 1), 't/cachetest/uripath1/uripath2');
54 is(Apache::Gallery::cache_dir($r, 0), 't/cachetest/uripath1/uripath2/urifile');
55
56 $r=request('t/cachetest', 0);
57 is(Apache::Gallery::cache_dir($r, 1), 't/cachetest/uripath1/uripath2');
58 is(Apache::Gallery::cache_dir($r, 0), 't/cachetest/uripath1/uripath2/urifile');