From 79ff1f886b48e6b43ddd0ad3e3c6155e5826c4c5 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 13 Mar 2011 13:55:12 +0100 Subject: Add App::Dthumb tests for create_files, create_thumbnail_html and write_out_html --- Build.PL | 1 + lib/App/Dthumb.pm | 8 +++++ t/20-app-dthumb.t | 10 ++---- t/21-app-dthumb.files.t | 83 +++++++++++++++++++++++++++++++++++++++++++++++++ t/cmp/index.names | 26 ++++++++++++++++ t/cmp/index.no-names | 22 +++++++++++++ t/imgdir/no_image | 0 7 files changed, 143 insertions(+), 7 deletions(-) create mode 100755 t/21-app-dthumb.files.t create mode 100644 t/cmp/index.names create mode 100644 t/cmp/index.no-names create mode 100644 t/imgdir/no_image diff --git a/Build.PL b/Build.PL index ab66c54..2844668 100644 --- a/Build.PL +++ b/Build.PL @@ -6,6 +6,7 @@ use Module::Build; my $build = Module::Build->new( build_requires => { + 'File::Slurp' => 0, 'Test::More' => 0, 'Test::Compile' => 0, 'Test::Pod' => 0, diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index 0d7ae7b..b1ad0a8 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -348,6 +348,14 @@ sub write_out_html { close($fh); } + +=head2 version + +Return B version string. + +=cut + + sub version { return $VERSION; } 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 @@ + + + + dthumb + + + + + +
+
+ + one.png +
+ one.png +
+
+ + two.png +
+ two.png +
+
+ + 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 @@ + + + + dthumb + + + + + +
+
+ + one.png +
+
+ + two.png +
+
+ + diff --git a/t/imgdir/no_image b/t/imgdir/no_image new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3