diff options
Diffstat (limited to 't')
-rwxr-xr-x | t/20-app-dthumb.t | 10 | ||||
-rwxr-xr-x | t/21-app-dthumb.files.t | 83 | ||||
-rw-r--r-- | t/cmp/index.names | 26 | ||||
-rw-r--r-- | t/cmp/index.no-names | 22 | ||||
-rw-r--r-- | t/imgdir/no_image | 0 |
5 files changed, 134 insertions, 7 deletions
diff --git a/t/20-app-dthumb.t b/t/20-app-dthumb.t index 18923be..5f3479d 100755 --- a/t/20-app-dthumb.t +++ b/t/20-app-dthumb.t @@ -4,7 +4,7 @@ use warnings; use 5.010; use autodie; -use Test::More tests => 18; +use Test::More tests => 17; use_ok('App::Dthumb'); @@ -33,15 +33,11 @@ is($dthumb->{config}->{lightbox}, 0, 'Lightbox disabled'); $dthumb = App::Dthumb->new('no-names' => 1); is($dthumb->{config}->{names}, 0, 'Image names disabled'); +is($dthumb->version(), $App::Dthumb::VERSION, '$dthumb->version()'); + $dthumb = App::Dthumb->new(); @{$dthumb->{files}} = qw(a.png b.png c.png d.jpg); @{$dthumb->{old_thumbnails}} = 'e.png'; is_deeply($dthumb->{files}, [$dthumb->get_files()], '$dthumb->get_files()'); - -$dthumb = App::Dthumb->new(dir_images => 't/imgdir'); -$dthumb->read_directories(); - -is_deeply($dthumb->{old_thumbnails}, ['invalid.png'], '{old_thumbnails}'); -is_deeply($dthumb->{files}, ['one.png', 'two.png'], '{files}'); diff --git a/t/21-app-dthumb.files.t b/t/21-app-dthumb.files.t new file mode 100755 index 0000000..06bea47 --- /dev/null +++ b/t/21-app-dthumb.files.t @@ -0,0 +1,83 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; +use autodie; + +use Test::More; + +eval "use File::Slurp"; +plan skip_all => 'File::Slurp required' if $@; + +plan tests => 9; + +use_ok('App::Dthumb'); + +my %conf = ( + file_index => 't/out/index', + dir_images => 't/imgdir', +); +my @create_failed; + +my $dthumb = App::Dthumb->new(%conf); +isa_ok($dthumb, 'App::Dthumb'); + +for my $file (qw(one.png two.png)) { + $dthumb->create_thumbnail_html($file); +} +$dthumb->write_out_html(); + +is(read_file('t/out/index'), read_file('t/cmp/index.names'), + 'create_thumbnail_html / write_out_html'); + +unlink('t/out/index'); + + + +$conf{names} = 0; +$dthumb = App::Dthumb->new(%conf); + +for my $file (qw(one.png two.png)) { + $dthumb->create_thumbnail_html($file); +} +$dthumb->write_out_html(); + +is(read_file('t/out/index'), read_file('t/cmp/index.no-names'), + 'create_thumbnail_html / write_out_html with names = 0'); + +unlink('t/out/index'); + + + +$dthumb = App::Dthumb->new(dir_images => 't/out'); +$dthumb->create_files(); + +ok(-d 't/out/.thumbs', '->create_files creates thumb dir'); +ok(-d 't/out/.dthumb', '->create_files creates data dir'); + +for my $file ($dthumb->{data}->list_archived()) { + if (not -e "t/out/.dthumb/${file}") { + push(@create_failed, $file); + } + else { + unlink("t/out/.dthumb/${file}"); + } +} +rmdir('t/out/.thumbs'); +rmdir('t/out/.dthumb'); + +if (@create_failed) { + fail("->create_files missed out " . join(' ', @create_failed)); +} +else { + pass("->create_files all okay"); +} + + + +$dthumb = App::Dthumb->new(%conf); + +$dthumb->read_directories(); + +is_deeply($dthumb->{old_thumbnails}, ['invalid.png'], '{old_thumbnails}'); +is_deeply($dthumb->{files}, ['one.png', 'two.png'], '{files}'); diff --git a/t/cmp/index.names b/t/cmp/index.names new file mode 100644 index 0000000..c682ae1 --- /dev/null +++ b/t/cmp/index.names @@ -0,0 +1,26 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title>dthumb</title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> + <link rel="stylesheet" type="text/css" href=".dthumb/main.css"/> + <link rel="stylesheet" type="text/css" href=".dthumb/lightbox.css"/> + <script type="text/javascript" src=".dthumb/lightbox.js"></script> +</head> +<body><div> +<div class="image-container"> + <a rel="lightbox" href="one.png" title="one.png"> + <img src="t/imgdir/.thumbs/one.png" alt="one.png" /></a> + <br /> + <a style="text-decoration: none;" href="one.png">one.png</a> +</div> +<div class="image-container"> + <a rel="lightbox" href="two.png" title="two.png"> + <img src="t/imgdir/.thumbs/two.png" alt="two.png" /></a> + <br /> + <a style="text-decoration: none;" href="two.png">two.png</a> +</div> +</div> +</body> +</html> diff --git a/t/cmp/index.no-names b/t/cmp/index.no-names new file mode 100644 index 0000000..5022b19 --- /dev/null +++ b/t/cmp/index.no-names @@ -0,0 +1,22 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" + "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> +<head> + <title>dthumb</title> + <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> + <link rel="stylesheet" type="text/css" href=".dthumb/main.css"/> + <link rel="stylesheet" type="text/css" href=".dthumb/lightbox.css"/> + <script type="text/javascript" src=".dthumb/lightbox.js"></script> +</head> +<body><div> +<div class="image-container"> + <a rel="lightbox" href="one.png" title="one.png"> + <img src="t/imgdir/.thumbs/one.png" alt="one.png" /></a> +</div> +<div class="image-container"> + <a rel="lightbox" href="two.png" title="two.png"> + <img src="t/imgdir/.thumbs/two.png" alt="two.png" /></a> +</div> +</div> +</body> +</html> diff --git a/t/imgdir/no_image b/t/imgdir/no_image new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/t/imgdir/no_image |