Initial commit
[app-gallery.git] / t / App-Gallery.t
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4
5 use File::Temp qw/tempdir/;
6 use File::Slurp;
7 use File::Spec::Functions;
8 use Image::Magick;
9
10 use Test::More tests => 11;
11 BEGIN { use_ok('App::Gallery') };
12
13 sub test_img_size {
14 my ($width, $height, $file) = @_;
15 my $image = Image::Magick->new;
16 $image->Read($file);
17 my ($actual_width, $actual_height) = $image->Get(qw/width height/);
18 is $width, $actual_width, 'image width';
19 is $height, $actual_height, 'image height';
20 }
21
22 my @imgs = <t/*.png>;
23 my $dir = tempdir ('app-gallery.XXXX', TMPDIR => 1, CLEANUP => 1);
24 my $dir1 = catdir $dir, 'test1';
25 my $dir2 = catdir $dir, 'test2';
26
27 App::Gallery->run({out => $dir1, title => 'Some title', width => 200, height => 200}, @imgs);
28
29 my $html = read_file catfile $dir1, 'index.html';
30 is $html, <<'EOF', 'index.html as expected';
31 <!DOCTYPE html>
32 <title>Some title</title>
33 <meta charset="utf-8">
34 <style>
35 .imgwrap {
36 display: inline-block;
37 margin: 6px 3px;
38 vertical-align: center;
39 text-align: center;
40 }
41 </style>
42 <link rel="stylesheet" href="style.css">
43
44 <h1>Some title</h1>
45 <div>
46 <div class=imgwrap><a href='full/100x400.png'><img src='thumb/100x400.png'></a></div>
47 <div class=imgwrap><a href='full/800x200.png'><img src='thumb/800x200.png'></a></div>
48 </div>
49 EOF
50
51 test_img_size (50, 200, catfile $dir1, 'thumb', '100x400.png');
52 test_img_size (200, 50, catfile $dir1, 'thumb', '800x200.png');
53
54 App::Gallery->run({out => $dir2, tmpl => catfile 't', 'example-tmpl'}, @imgs);
55
56 $html = read_file catfile $dir2, 'index.html';
57 is $html, <<'EOF', 'index.html as expected';
58 <!DOCTYPE html>
59 <title>Gallery</title>
60 <meta charset="utf-8">
61 <link rel="stylesheet" href="style.css">
62
63 <div>
64 <div><a href='full/100x400.png'><img src='thumb/100x400.png'></a></div>
65 <div><a href='full/800x200.png'><img src='thumb/800x200.png'></a></div>
66 </div>
67 EOF
68
69 test_img_size (100, 400, catfile $dir2, 'thumb', '100x400.png');
70 test_img_size (600, 150, catfile $dir2, 'thumb', '800x200.png');
This page took 0.028261 seconds and 4 git commands to generate.