Initial commit
[app-gallery.git] / t / App-Gallery.t
CommitLineData
b1336dac
MG
1#!/usr/bin/perl
2use strict;
3use warnings;
4
5use File::Temp qw/tempdir/;
6use File::Slurp;
7use File::Spec::Functions;
8use Image::Magick;
9
10use Test::More tests => 11;
11BEGIN { use_ok('App::Gallery') };
12
13sub 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
22my @imgs = <t/*.png>;
23my $dir = tempdir ('app-gallery.XXXX', TMPDIR => 1, CLEANUP => 1);
24my $dir1 = catdir $dir, 'test1';
25my $dir2 = catdir $dir, 'test2';
26
27App::Gallery->run({out => $dir1, title => 'Some title', width => 200, height => 200}, @imgs);
28
29my $html = read_file catfile $dir1, 'index.html';
30is $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>
49EOF
50
51test_img_size (50, 200, catfile $dir1, 'thumb', '100x400.png');
52test_img_size (200, 50, catfile $dir1, 'thumb', '800x200.png');
53
54App::Gallery->run({out => $dir2, tmpl => catfile 't', 'example-tmpl'}, @imgs);
55
56$html = read_file catfile $dir2, 'index.html';
57is $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>
67EOF
68
69test_img_size (100, 400, catfile $dir2, 'thumb', '100x400.png');
70test_img_size (600, 150, catfile $dir2, 'thumb', '800x200.png');
This page took 0.013263 seconds and 4 git commands to generate.