aboutsummaryrefslogtreecommitdiff
path: root/t/album.t
diff options
context:
space:
mode:
Diffstat (limited to 't/album.t')
-rwxr-xr-xt/album.t153
1 files changed, 153 insertions, 0 deletions
diff --git a/t/album.t b/t/album.t
new file mode 100755
index 000000000..2807f2247
--- /dev/null
+++ b/t/album.t
@@ -0,0 +1,153 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+BEGIN {
+ foreach my $module (qw(Image::Magick)) {
+ eval qq{use $module};
+ if ($@) {
+ eval qq{
+ use Test::More skip_all => "$module not available"
+ }
+ }
+ }
+}
+use Test::More 'no_plan';
+
+BEGIN { use_ok("IkiWiki"); }
+
+my $blob;
+
+ok(! system("rm -rf t/tmp"));
+ok(mkdir("t/tmp"));
+ok(mkdir("t/tmp/in"));
+ok(mkdir("t/tmp/in/myalbum"));
+
+my $image = Image::Magick->new;
+$image->Set(size => '640x480');
+$image->Read('canvas:red');
+$image->Draw(fill => 'yellow', primitive => 'rectangle',
+ points => '0,0 100,100');
+$image->Write('t/tmp/in/myalbum/r.jpg');
+
+$image = Image::Magick->new;
+$image->Set(size => '480x640');
+$image->Read('canvas:green');
+$image->Draw(fill => 'yellow', primitive => 'rectangle',
+ points => '0,0 100,100');
+$image->Write('t/tmp/in/myalbum/g.png');
+
+$image = Image::Magick->new;
+$image->Set(size => '640x640');
+$image->Read('canvas:blue');
+$image->Draw(fill => 'yellow', primitive => 'rectangle',
+ points => '0,0 100,100');
+$image->Write('t/tmp/in/myalbum/b.gif');
+
+writefile("myalbum.mdwn", "t/tmp/in", <<END);
+## Section: green
+[[!albumsection filter="*/g"]]
+## Assorted
+[[!album sort="title"]]
+END
+writefile("myalbum/page.mdwn", "t/tmp/in", "not an image");
+writefile("style.css", "t/tmp/in", readfile("doc/style.css"));
+
+ok(! system("make -s ikiwiki.out"));
+
+my $command = "perl -Iblib/lib ./ikiwiki.out -set usedirs=0 -plugin album -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tmp/in t/tmp/out -verbose";
+
+ok(! system($command));
+# make sure subsequent changes will have a newer mtime
+sleep(1);
+
+# myalbum is an album and a trail
+# the album's members are inlined into it
+# the albumsection displays all matching pages (only myalbum/g)
+# the album displays the rest
+$blob = readfile("t/tmp/out/myalbum.html");
+like($blob, qr{
+ ^<h2[^>]*>Section:\s+green</h2>$
+ .*?
+ <a\s+href="\./myalbum/g\.html">
+ .*?
+ <img\s+src="\./myalbum/g/96x96-g\.png"
+ .*?
+ ^<h2[^>]*>Assorted</h2>$
+ .*?
+ <a\s+href="\./myalbum/b\.html">
+ .*?
+ <img\s+src="\./myalbum/b/96x96-b\.gif"
+ .*?
+ <a\s+href="\./myalbum/r\.html">
+ .*?
+ <img\s+src="\./myalbum/r/96x96-r\.jpg"
+ }msx);
+unlike($blob, qr{myalbum/page\.html});
+
+# myalbum/b is part of the trail defined by myalbum
+$blob = readfile("t/tmp/out/myalbum/b.html");
+like($blob, qr{
+ <link\s+rel="prev"\s+href="\./g\.html"
+ .*?
+ <link\s+rel="up"\s+href="\.\./myalbum\.html"
+ .*?
+ <link\s+rel="next"\s+href="\./r\.html"
+ }msx);
+# myalbum/b shows the full-size image
+like($blob, qr{
+ <div\s+id="album-img">
+ .*?
+ <img\s+src="\./b\.gif"
+ }msx);
+
+# change some stuff and refresh
+$blob = readfile("t/tmp/in/.ikiwiki/transient/myalbum/b.mdwn");
+like($blob, qr{\[\[!albumimage\s.*\]\]}msx);
+$blob =~ s/^(\s*)title="+$/${1}title="a blue box"/msx;
+writefile("myalbum/b.mdwn", "t/tmp/in", "hello, world!\n\n$blob");
+
+# make sure subsequent changes take effect
+ok(! system("$command -refresh"));
+
+# myalbum is an album and a trail
+# the album's members are inlined into it
+# the albumsection displays all matching pages (only myalbum/g)
+# the album displays the rest
+$blob = readfile("t/tmp/out/myalbum.html");
+like($blob, qr{
+ ^<h2[^>]*>Section:\s+green</h2>$
+ .*?
+ <a\s+href="\./myalbum/g\.html">
+ .*?
+ <img\s+src="\./myalbum/g/96x96-g\.png"
+ .*?
+ ^<h2[^>]*>Assorted</h2>$
+ .*?
+ <a\s+href="\./myalbum/b\.html">
+ .*?
+ <img\s+src="\./myalbum/b/96x96-b\.gif"
+ .*?
+ <a\s+href="\./myalbum/r\.html">
+ .*?
+ <img\s+src="\./myalbum/r/96x96-r\.jpg"
+ }msx);
+unlike($blob, qr{myalbum/page\.html});
+
+# myalbum/b is part of the trail defined by myalbum
+$blob = readfile("t/tmp/out/myalbum/b.html");
+like($blob, qr{
+ <link\s+rel="prev"\s+href="\./g\.html"
+ .*?
+ <link\s+rel="up"\s+href="\.\./myalbum\.html"
+ .*?
+ <link\s+rel="next"\s+href="\./r\.html"
+ }msx);
+# myalbum/b shows the full-size image, now with title and additional text
+like($blob, qr{<title>a blue box</title>});
+like($blob, qr{
+ <p>hello,\s+world!</p>
+ .*?
+ <div\s+id="album-img">
+ .*?
+ <img\s+src="\./b\.gif"
+ }msx);