summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-03-13 15:13:53 +0100
committerDaniel Friesel <derf@finalrewind.org>2011-03-13 15:13:53 +0100
commitcda9db59d13094ab9026fb8f2096e21ed1b458fd (patch)
tree32341c6df1a51460f3a16a170f289254adafdc80
parent79ff1f886b48e6b43ddd0ad3e3c6155e5826c4c5 (diff)
App::Dthumb: Add tests for create_thumbnail_image
-rwxr-xr-xt/22-app-dthumb.image.t80
1 files changed, 80 insertions, 0 deletions
diff --git a/t/22-app-dthumb.image.t b/t/22-app-dthumb.image.t
new file mode 100755
index 0000000..8b83cbb
--- /dev/null
+++ b/t/22-app-dthumb.image.t
@@ -0,0 +1,80 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.010;
+use autodie;
+
+use Test::More;
+
+eval "use Test::MockObject";
+plan skip_all => 'Test::MockObject required' if $@;
+
+plan tests => 14;
+
+my @iml_scale_args;
+my $iml_quality;
+my $iml_save;
+my ($iml_w, $iml_h);
+
+my $mock = Test::MockObject->new();
+$mock->fake_module(
+ 'Image::Imlib2',
+ load => sub { return bless({}, $_[0]) },
+ create_scaled_image => sub { @iml_scale_args = @_[1,2]; return $_[0] },
+ set_quality => sub { $iml_quality = $_[1] },
+ save => sub { $iml_save = $_[1] },
+ width => sub { return $iml_w },
+ height => sub { return $iml_h },
+);
+
+sub reset_mock_vars {
+ $iml_quality = undef;
+ $iml_save = undef;
+ @iml_scale_args = ();
+}
+
+
+use_ok('App::Dthumb');
+
+my $dthumb = App::Dthumb->new(
+ size => 100,
+ quality => 90,
+);
+
+isa_ok($dthumb, 'App::Dthumb');
+
+$iml_w = 2;
+$iml_h = 2;
+
+$dthumb->create_thumbnail_image('a.png');
+
+is(@iml_scale_args, 0, 'Small image: Do not scale');
+is($iml_quality, 90, 'Set quality');
+is($iml_save, './.thumbs/a.png', 'Save thumbnail');
+
+reset_mock_vars();
+$iml_w = 100;
+$iml_h = 100;
+$dthumb->create_thumbnail_image('a.png');
+
+is(@iml_scale_args, 0, 'Exact match: Do not scale');
+is($iml_quality, 90, 'Set quality');
+is($iml_save, './.thumbs/a.png', 'Save thumbnail');
+
+reset_mock_vars();
+$iml_w = 200;
+$iml_h = 100;
+$dthumb->create_thumbnail_image('a.png');
+
+is_deeply([@iml_scale_args], [100, 0], 'W too big: scale to fit X');
+is($iml_quality, 90, 'Set quality');
+is($iml_save, './.thumbs/a.png', 'Save thumbnail');
+
+reset_mock_vars();
+$iml_w = 100;
+$iml_h = 200;
+$dthumb->create_thumbnail_image('a.png');
+
+is_deeply([@iml_scale_args], [0, 100], 'H too big: scale to fit Y');
+is($iml_quality, 90, 'Set quality');
+is($iml_save, './.thumbs/a.png', 'Save thumbnail');