]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - t/git-cgi.t
+1 the feature request
[git.ikiwiki.info.git] / t / git-cgi.t
index 7058c33e34f26b84326c1e4a8a0f3a2a13fad84b..3556bc0387179bbc2959ff871561f127c9c20276 100755 (executable)
@@ -1,7 +1,9 @@
 #!/usr/bin/perl
+use utf8;
 use warnings;
 use strict;
 
+use Encode;
 use Test::More;
 
 BEGIN {
@@ -35,7 +37,7 @@ my $installed = $ENV{INSTALLED_TESTS};
 
 my @command;
 if ($installed) {
-       @command = qw(ikiwiki);
+       @command = qw(ikiwiki --plugin inline);
 }
 else {
        ok(! system("make -s ikiwiki.out"));
@@ -62,7 +64,7 @@ sub write_setup_file {
                cgiurl => 'http://example.com/cgi-bin/ikiwiki.cgi',
                cgi_wrapper => getcwd.'/t/tmp/ikiwiki.cgi',
                cgi_wrappermode => '0751',
-               add_plugins => [qw(anonok lockedit recentchanges)],
+               add_plugins => [qw(anonok attachment lockedit recentchanges)],
                disable_plugins => [qw(emailauth openid passwordauth)],
                anonok_pagespec => 'writable/*',
                locked_pages => '!writable/*',
@@ -112,6 +114,7 @@ sub run_cgi {
 
        my $cgi = CGI->new($args{params});
        my $query_string = $cgi->query_string();
+       diag $query_string;
 
        if ($method eq 'POST') {
                $defaults{REQUEST_METHOD} = 'POST';
@@ -132,7 +135,7 @@ sub run_cgi {
                } keys(%envvars);
        });
 
-       return $out;
+       return decode_utf8($out);
 }
 
 sub run_git {
@@ -142,7 +145,12 @@ sub run_git {
        my ($in, $out);
        ok(run(['git', @$args], \$in, \$out, init => sub {
                chdir 't/tmp/in' or die $!;
-               $ENV{EMAIL} = 'nobody@ikiwiki-tests.invalid';
+               my $name = 'The IkiWiki Tests';
+               my $email = 'nobody@ikiwiki-tests.invalid';
+               if ($args->[0] eq 'commit') {
+                       $ENV{GIT_AUTHOR_NAME} = $ENV{GIT_COMMITTER_NAME} = $name;
+                       $ENV{GIT_AUTHOR_EMAIL} = $ENV{GIT_COMMITTER_EMAIL} = $email;
+               }
        }), "$desc at $filename:$line");
        return $out;
 }
@@ -158,6 +166,13 @@ sub test {
        write_old_file('doc/writable/one.mdwn', 't/tmp/in', 'This is the first test page');
        write_old_file('doc/writable/two.mdwn', 't/tmp/in', 'This is the second test page');
        write_old_file('doc/writable/three.mdwn', 't/tmp/in', 'This is the third test page');
+       write_old_file('doc/writable/three.bin', 't/tmp/in', 'An attachment');
+       write_old_file('doc/writable/blog.mdwn', 't/tmp/in',
+               '[[!inline pages="writable/blog/*" actions=yes rootpage=writable/blog postform=yes show=0]]');
+       write_old_file('doc/writable/__172__blog.mdwn', 't/tmp/in',
+               '[[!inline pages="writable/¬blog/*" actions=yes rootpage="writable/¬blog" postform=yes show=0]]');
+       write_old_file('doc/writable/中文.mdwn', 't/tmp/in',
+               '[[!inline pages="writable/中文/*" actions=yes rootpage="writable/中文" postform=yes show=0]]');
 
        unless ($installed) {
                ok(! system(qw(cp -pRL doc/wikiicons t/tmp/in/doc/)));
@@ -177,6 +192,10 @@ sub test {
        like($content, qr{This is the first test page});
        my $orig_sha1 = run_git(['rev-list', '--max-count=1', 'HEAD']);
 
+       # We have to wait 1 second here so that new writes are guaranteed
+       # to have a strictly larger mtime.
+       sleep 1;
+
        # Test the git hook, which accepts git commits
        writefile('doc/writable/one.mdwn', 't/tmp/in',
                'This is new content for the first test page');
@@ -214,11 +233,16 @@ sub test {
        # Another edit
        writefile('doc/writable/three.mdwn', 't/tmp/in',
                'Also new content for the third page');
+       unlink('t/tmp/in/doc/writable/three.bin');
+       writefile('doc/writable/three.bin', 't/tmp/in',
+               'Changed attachment');
        run_git(['add', '.']);
        run_git(['commit', '-m', 'Git commit']);
        ok(-e 't/tmp/out/writable/three/index.html');
        $content = readfile('t/tmp/out/writable/three/index.html');
        like($content, qr{Also new content for the third page});
+       $content = readfile('t/tmp/out/writable/three.bin');
+       like($content, qr{Changed attachment});
        my $third_revertable_sha1 = run_git(['rev-list', '--max-count=1', 'HEAD']);
        isnt($orig_sha1, $third_revertable_sha1);
        isnt($second_revertable_sha1, $third_revertable_sha1);
@@ -276,6 +300,10 @@ sub test {
        $content = readfile('t/tmp/in/two.mdwn');
        like($content, qr{Here is new content for the second page});
 
+       # We have to wait 1 second here so that new writes are guaranteed
+       # to have a strictly larger mtime.
+       sleep 1;
+
        # This one can legitimately be reverted
        $content = run_cgi(method => 'post',
                params => {
@@ -293,6 +321,35 @@ sub test {
        ok(-e 't/tmp/out/writable/three/index.html');
        $content = readfile('t/tmp/out/writable/three/index.html');
        like($content, qr{This is the third test page});
+       $content = readfile('t/tmp/out/writable/three.bin');
+       like($content, qr{An attachment});
+
+       $content = readfile('t/tmp/out/writable/blog/index.html');
+       like($content, qr{<input type="hidden" name="from" value="writable/blog"});
+       $content = run_cgi(method => 'get',
+               params => {
+                       do => 'blog',
+                       from => 'writable/blog',
+                       subpage => '1',
+                       title => 'hello',
+               },
+       );
+       like($content, qr{<option selected="selected" value="writable/blog/hello">writable/blog/hello</option>});
+
+       # Regression test for a bug in which we couldn't use an
+       # alphanumeric, but non-ASCII, root page.
+       $content = readfile('t/tmp/out/writable/中文/index.html');
+       like($content, qr{<input type="hidden" name="from" value="writable/中文"});
+       $content = run_cgi(method => 'get',
+               params => {
+                       do => 'blog',
+                       from => 'writable/中文',
+                       subpage => '1',
+                       title => 'hello',
+               },
+       );
+       like($content, qr{<option selected="selected" value="writable/中文/hello">writable/中文/hello</option>});
+       unlike($content, qr{Error: bad page name});
 }
 
 test();