Merge branch 'ready/postform-no'
authorSimon McVittie <smcv@debian.org>
Fri, 12 Sep 2014 20:46:04 +0000 (21:46 +0100)
committerSimon McVittie <smcv@debian.org>
Fri, 12 Sep 2014 20:46:04 +0000 (21:46 +0100)
IkiWiki/Plugin/inline.pm
t/inline.t [new file with mode: 0755]

index 123dfd36489c8536450971c95267ef30261abcc9..f578526cc0da9fe1c369c5d1e709fe21f5154341 100644 (file)
@@ -329,8 +329,12 @@ sub preprocess_inline (@) {
 
        my $ret="";
 
-       if (length $config{cgiurl} && ! $params{preview} && (exists $params{rootpage} ||
-           (exists $params{postform} && yesno($params{postform}))) &&
+       my $postform = (exists $params{rootpage});
+       if (exists $params{postform}) {
+               $postform = yesno($params{postform});
+       }
+
+       if (length $config{cgiurl} && ! $params{preview} && $postform &&
            IkiWiki->can("cgi_editpage")) {
                # Add a blog post form, with feed buttons.
                my $formtemplate=template_depends("blogpost.tmpl", $params{page}, blind_cache => 1);
diff --git a/t/inline.t b/t/inline.t
new file mode 100755 (executable)
index 0000000..b34cd27
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More;
+use IkiWiki;
+
+my $blob;
+
+ok(! system("rm -rf t/tmp"));
+ok(! system("mkdir t/tmp"));
+
+sub write_old_file {
+       my $name = shift;
+       my $content = shift;
+
+       writefile($name, "t/tmp/in", $content);
+       ok(utime(333333333, 333333333, "t/tmp/in/$name"));
+}
+
+write_old_file("protagonists.mdwn",
+       '[[!inline pages="protagonists/*" rootpage="protagonists/new"]]');
+write_old_file("friends.mdwn",
+       '[[!inline pages="friends/*" postform=yes]]');
+write_old_file("antagonists.mdwn",
+       '[[!inline pages="antagonists/*"]]');
+write_old_file("enemies.mdwn",
+       '[[!inline pages="enemies/*" postform=no rootpage=enemies]]');
+foreach my $page (qw(protagonists/shepard protagonists/link
+               antagonists/saren antagonists/ganondorf
+               friends/liara friends/midna
+               enemies/benezia enemies/zant)) {
+       write_old_file("$page.mdwn", "this page is *$page*");
+}
+
+ok(! system("make -s ikiwiki.out"));
+
+my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tmp/in t/tmp/out -verbose";
+
+ok(! system($command));
+
+ok(! system("$command -refresh"));
+
+$blob = readfile("t/tmp/out/protagonists.html");
+like($blob, qr{Add a new post}, 'rootpage=yes gives postform');
+like($blob, qr{<input type="hidden" name="from" value="protagonists/new"},
+       'explicit rootpage is /protagonists/new');
+
+$blob = readfile("t/tmp/out/friends.html");
+like($blob, qr{Add a new post}, 'postform=yes forces postform');
+like($blob, qr{<input type="hidden" name="from" value="friends"},
+       'implicit rootpage is /friends');
+
+$blob = readfile("t/tmp/out/antagonists.html");
+unlike($blob, qr{Add a new post}, 'default is no postform');
+
+$blob = readfile("t/tmp/out/enemies.html");
+unlike($blob, qr{Add a new post}, 'postform=no forces no postform');
+
+done_testing;