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 ok(! system("rm -rf t/tmp; mkdir -p t/tmp/in"));
26 ok(! system("cp t/img/redsquare.png t/tmp/in/redsquare.png"));
27 # colons in filenames are a corner case for img
28 ok(! system("cp t/img/redsquare.png t/tmp/in/hello:world.png"));
29 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c.png"));
30 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d.png"));
31 ok(! system("cp t/img/redsquare.png t/tmp/in/a:b:c:d:e:f:g:h:i:j.png"));
34 writefile("bluesquare.svg", "t/tmp/in",
35 '<svg width="30" height="30"><rect x="0" y="0" width="30" height="30" fill="blue"/></svg>');
38 # using different image sizes for different pages, so the pagenumber selection can be tested easily
39 ok(! system("cp t/img/twopages.pdf t/tmp/in/twopages.pdf"));
41 my $maybe_svg_img = "";
43 $maybe_svg_img = "[[!img bluesquare.svg size=10x]]";
46 writefile("imgconversions.mdwn", "t/tmp/in", <<EOF
47 [[!img redsquare.png]]
48 [[!img redsquare.png size=10x]]
49 [[!img redsquare.png size=30x50]] expecting 30x30
50 [[!img hello:world.png size=x8]] expecting 8x8
51 [[!img a:b:c.png size=x4]]
52 [[!img a:b:c:d:e:f:g:h:i:j.png size=x6]]
54 [[!img twopages.pdf size=12x]]
55 [[!img twopages.pdf size=16x pagenumber=1]]
59 ok(! system("make -s ikiwiki.out"));
61 my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -templatedir=templates -plugin img t/tmp/in t/tmp/out -verbose";
63 ok(! system($command));
67 my $im = Image::Magick->new();
68 my $r = $im->Read(":$filename");
69 return "no image" if $r;
70 my $w = $im->Get("width");
71 my $h = $im->Get("height");
75 my $outpath = "t/tmp/out/imgconversions";
76 my $outhtml = readfile("$outpath.html");
78 is(size("$outpath/10x-redsquare.png"), "10x10");
79 ok(! -e "$outpath/30x-redsquare.png");
80 ok($outhtml =~ /width="30" height="30".*expecting 30x30/);
83 # if this fails, you need libmagickcore-6.q16-2-extra installed
84 is(size("$outpath/10x-emptysquare.png"), "10x10");
87 is(size("$outpath/12x-twopages.png"), "12x12");
88 is(size("$outpath/16x-p1-twopages.png"), "16x2");
89 ok($outhtml =~ /width="8" height="8".*expecting 8x8/);
90 is(size("$outpath/x8-hello:world.png"), "8x8");
91 is(size("$outpath/x4-a:b:c.png"), "4x4");
92 is(size("$outpath/x6-a:b:c:d:e:f:g:h:i:j.png"), "6x6");
94 # now let's remove them again
96 if (1) { # for easier testing
97 writefile("imgconversions.mdwn", "t/tmp/in", "nothing to see here");
99 ok(! system("$command --refresh"));
101 ok(! -e "$outpath/10x-redsquare.png");
102 ok(! -e "$outpath/10x-bluesquare.png");
103 ok(! -e "$outpath/12x-twopages.png");
104 ok(! -e "$outpath/16x-p1-twopages.png");
105 ok(! -e "$outpath/x8-hello:world.png");
106 ok(! -e "$outpath/x4-a:b:c.png");
107 ok(! -e "$outpath/x6-a:b:c:d:e:f:g:h:i:j.png");
110 ok(! system("rm -rf t/tmp"));