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]]
69 ok(! system("make -s ikiwiki.out"));
71 my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -templatedir=templates -plugin img t/tmp/in t/tmp/out -verbose";
73 ok(! system($command));
77 my $im = Image::Magick->new();
78 my $r = $im->Read(":$filename");
79 return "no image" if $r;
80 my $w = $im->Get("width");
81 my $h = $im->Get("height");
85 my $outpath = "t/tmp/out/imgconversions";
86 my $outhtml = readfile("$outpath.html");
88 is(size("$outpath/10x-redsquare.png"), "10x10");
89 ok(! -e "$outpath/30x-redsquare.png");
90 ok($outhtml =~ /width="30" height="30".*expecting 30x30/);
93 skip "SVG support not installed (try libmagickcore-extra)", 1
95 # if this fails, you need libmagickcore-6.q16-2-extra installed
96 is(size("$outpath/10x-bluesquare.png"), "10x10");
100 skip "PDF support not installed (try ghostscript)", 2
102 is(size("$outpath/12x-twopages.png"), "12x12");
103 is(size("$outpath/16x-p1-twopages.png"), "16x2");
106 ok($outhtml =~ /width="8" height="8".*expecting 8x8/);
107 is(size("$outpath/x8-hello:world.png"), "8x8");
108 is(size("$outpath/x4-a:b:c.png"), "4x4");
109 is(size("$outpath/x6-a:b:c:d:e:f:g:h:i:j.png"), "6x6");
111 # now let's remove them again
113 if (1) { # for easier testing
114 writefile("imgconversions.mdwn", "t/tmp/in", "nothing to see here");
116 ok(! system("$command --refresh"));
118 ok(! -e "$outpath/10x-redsquare.png");
119 ok(! -e "$outpath/10x-bluesquare.png");
120 ok(! -e "$outpath/12x-twopages.png");
121 ok(! -e "$outpath/16x-p1-twopages.png");
122 ok(! -e "$outpath/x8-hello:world.png");
123 ok(! -e "$outpath/x4-a:b:c.png");
124 ok(! -e "$outpath/x6-a:b:c:d:e:f:g:h:i:j.png");
127 ok(! system("rm -rf t/tmp"));