]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/comments.t
reminds me of bugs/ table can not deal with Chinese
[git.ikiwiki.info.git] / t / comments.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Cwd qw(getcwd);
5 use Test::More;
6 use IkiWiki;
8 ok(! system("rm -rf t/tmp"));
9 ok(mkdir "t/tmp");
10 ok(! system("cp -R t/tinyblog t/tmp/in"));
11 ok(mkdir "t/tmp/in/post" or -d "t/tmp/in/post");
13 my $installed = $ENV{INSTALLED_TESTS};
15 my @command;
16 if ($installed) {
17         @command = qw(ikiwiki);
18 }
19 else {
20         ok(! system("make -s ikiwiki.out"));
21         @command = ("perl", "-I".getcwd, qw(./ikiwiki.out
22                 --underlaydir=underlays/basewiki
23                 --set underlaydirbase=underlays
24                 --templatedir=templates));
25 }
27 my $comment;
29 $comment = <<EOF;
30 [[!comment username="neil"
31   date="1969-07-20T20:17:40Z"
32   content="I landed"]]
33 EOF
34 #ok(eval { writefile("post/comment_3._comment", "t/tmp/in", $comment); 1 });
35 writefile("post/comment_3._comment", "t/tmp/in", $comment);
37 $comment = <<EOF;
38 [[!comment username="christopher"
39   date="1969-02-12T07:00:00Z"
40   content="I explored"]]
41 EOF
42 writefile("post/comment_2_10a49d69282155c5c3e66dc58f64f956._comment", "t/tmp/in", $comment);
44 $comment = <<EOF;
45 [[!comment username="william"
46   date="1969-01-14T12:00:00Z"
47   content="I conquered"]]
48 EOF
49 writefile("post/comment_1._comment", "t/tmp/in", $comment);
51 # Give the files mtimes in the wrong order
52 ok(utime(111111111, 111111111, "t/tmp/in/post/comment_3._comment"));
53 ok(utime(222222222, 222222222, "t/tmp/in/post/comment_2_10a49d69282155c5c3e66dc58f64f956._comment"));
54 ok(utime(333333333, 333333333, "t/tmp/in/post/comment_1._comment"));
56 # Build the wiki
57 ok(! system(@command, qw(--verbose --plugin comments --url=http://example.com --cgiurl=http://example.com/ikiwiki.cgi --rss --atom --set comments_pagespec=* t/tmp/in t/tmp/out)));
59 # Check that the comments are in the right order
61 sub slurp {
62     open my $fh, "<", shift or return undef;
63     local $/;
64     my $content = <$fh>;
65     close $fh or return undef;
66     return $content;
67 }
69 my $content = slurp("t/tmp/out/post/index.html");
70 ok(defined $content);
71 like($content, qr/I conquered.*I explored.*I landed/s);
73 $content = slurp("t/tmp/out/post/index.atom");
74 ok(defined $content);
75 like($content, qr{
76         <link\s*href="http://example\.com/post/[#]comment-[[:xdigit:]]+"
77         .*
78         <link\s*href="http://example\.com/post/[#]comment-[[:xdigit:]]+"
79         .*
80         <link\s*href="http://example\.com/post/[#]comment-[[:xdigit:]]+"
81 }sx, 'Each comment gets an appropriate permalink in <link>');
82 unlike($content, qr{<link\s*href=.*/post/comment_[123]/});
83 unlike($content, qr{<link\s*href=.*/post/comment_[123]_[[:xdigit:]]+/});
85 done_testing();