3 # unit test that creates test images (png, svg, multi-page pdf), runs ikiwiki
4 # on them, checks the resulting images for plausibility based on their image
5 # sizes, and checks if they vanish when not required in the build process any
8 # if you have trouble here, be aware that there are three debian packages that
9 # can provide Image::Magick: perlmagick, libimage-magick-perl and
10 # graphicsmagick-libmagick-dev-compat
18 BEGIN { use_ok("IkiWiki"); }
19 BEGIN { use_ok("Image::Magick"); }
21 my $magick = new Image::Magick;
22 my $SVGS_WORK = defined $magick->QueryFormat("svg");
24 $magick->Read("t/img/twopages.pdf");
25 my $PDFS_WORK = defined $magick->Get("width");
27 ok(! system("rm -rf t/tmp; mkdir -p t/tmp/in"));
29 ok(! system("cp t/img/redsquare.png t/tmp/in/redsquare.png"));
30 # colons in filenames are a corner case for img
31 ok(! system("cp t/img/redsquare.png t/tmp/in/hello:world.png"));
32 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c.png"));
33 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d.png"));
34 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d:e:f:g:h:i:j.png"));
37 writefile("bluesquare.svg", "t/tmp/in",
38 '<svg width="30" height="30"><rect x="0" y="0" width="30" height="30" fill="blue"/></svg>');
41 # using different image sizes for different pages, so the pagenumber selection can be tested easily
42 ok(! system("cp t/img/twopages.pdf t/tmp/in/twopages.pdf"));
44 my $maybe_svg_img = "";
46 $maybe_svg_img = "[[!img bluesquare.svg size=10x]]";
49 my $maybe_pdf_img = "";
51 $maybe_pdf_img = <<EOF;
52 [[!img twopages.pdf size=12x]]
53 [[!img twopages.pdf size=16x pagenumber=1]]
57 writefile("imgconversions.mdwn", "t/tmp/in", <<EOF
58 [[!img redsquare.png]]
59 [[!img redsquare.png size=10x]]
60 [[!img redsquare.png size=30x50]] expecting 30x30
61 [[!img hello:world.png size=x8]] expecting 8x8
62 [[!img a:b:c.png size=x4]]
63 [[!img a:b:c:d:e:f:g:h:i:j.png size=x6]]
68 ok(utime(333333333, 333333333, "t/tmp/in/imgconversions.mdwn"));
70 ok(! system("make -s ikiwiki.out"));
72 my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -templatedir=templates -plugin img t/tmp/in t/tmp/out -verbose";
74 ok(! system($command));
78 my $im = Image::Magick->new();
79 my $r = $im->Read(":$filename");
80 return "no image" if $r;
81 my $w = $im->Get("width");
82 my $h = $im->Get("height");
86 my $outpath = "t/tmp/out/imgconversions";
87 my $outhtml = readfile("$outpath.html");
89 is(size("$outpath/10x-redsquare.png"), "10x10");
90 ok(! -e "$outpath/30x-redsquare.png");
91 ok($outhtml =~ /width="30" height="30".*expecting 30x30/);
94 skip "SVG support not installed (try libmagickcore-extra)", 1
96 # if this fails, you need libmagickcore-6.q16-2-extra installed
97 is(size("$outpath/10x-bluesquare.png"), "10x10");
101 skip "PDF support not installed (try ghostscript)", 2
103 is(size("$outpath/12x-twopages.png"), "12x12");
104 is(size("$outpath/16x-p1-twopages.png"), "16x2");
107 ok($outhtml =~ /width="8" height="8".*expecting 8x8/);
108 is(size("$outpath/x8-hello:world.png"), "8x8");
109 is(size("$outpath/x4-a:b:c.png"), "4x4");
110 is(size("$outpath/x6-a:b:c:d:e:f:g:h:i:j.png"), "6x6");
112 # now let's remove them again
114 if (1) { # for easier testing
115 writefile("imgconversions.mdwn", "t/tmp/in", "nothing to see here");
117 ok(! system("$command --refresh"));
119 ok(! -e "$outpath/10x-redsquare.png");
120 ok(! -e "$outpath/10x-bluesquare.png");
121 ok(! -e "$outpath/12x-twopages.png");
122 ok(! -e "$outpath/16x-p1-twopages.png");
123 ok(! -e "$outpath/x8-hello:world.png");
124 ok(! -e "$outpath/x4-a:b:c.png");
125 ok(! -e "$outpath/x6-a:b:c:d:e:f:g:h:i:j.png");
128 ok(! system("rm -rf t/tmp"));