aboutsummaryrefslogtreecommitdiff
path: root/t/comments.t
blob: f2e32c46e9e214e5bbfac8d5f326cba3219d7474 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/perl
use warnings;
use strict;
use Cwd qw(getcwd);
use Test::More;
use IkiWiki;

ok(! system("rm -rf t/tmp"));
ok(mkdir "t/tmp");
ok(! system("cp -R t/tinyblog t/tmp/in"));
ok(mkdir "t/tmp/in/post" or -d "t/tmp/in/post");

my $installed = $ENV{INSTALLED_TESTS};

my @command;
if ($installed) {
	@command = qw(ikiwiki);
}
else {
	ok(! system("make -s ikiwiki.out"));
	@command = ("perl", "-I".getcwd, qw(./ikiwiki.out
		--underlaydir=underlays/basewiki
		--set underlaydirbase=underlays
		--templatedir=templates));
}

my $comment;

$comment = <<EOF;
[[!comment username="neil"
  date="1969-07-20T20:17:40Z"
  content="I landed"]]
EOF
#ok(eval { writefile("post/comment_3._comment", "t/tmp/in", $comment); 1 });
writefile("post/comment_3._comment", "t/tmp/in", $comment);

$comment = <<EOF;
[[!comment username="christopher"
  date="1969-02-12T07:00:00Z"
  content="I explored"]]
EOF
writefile("post/comment_2._comment", "t/tmp/in", $comment);

$comment = <<EOF;
[[!comment username="william"
  date="1969-01-14T12:00:00Z"
  content="I conquered"]]
EOF
writefile("post/comment_1._comment", "t/tmp/in", $comment);

# Give the files mtimes in the wrong order
ok(utime(111111111, 111111111, "t/tmp/in/post/comment_3._comment"));
ok(utime(222222222, 222222222, "t/tmp/in/post/comment_2._comment"));
ok(utime(333333333, 333333333, "t/tmp/in/post/comment_1._comment"));

# Build the wiki
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)));

# Check that the comments are in the right order

sub slurp {
    open my $fh, "<", shift or return undef;
    local $/;
    my $content = <$fh>;
    close $fh or return undef;
    return $content;
}

my $content = slurp("t/tmp/out/post/index.html");
ok(defined $content);
ok($content =~ m/I conquered.*I explored.*I landed/s);

done_testing();