response
[ikiwiki.git] / t / bazaar.t
blob6e58f48f1c4e6183ea6a03d8c194317e5b2f2759
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 my $dir;
5 BEGIN {
6 $dir = "/tmp/ikiwiki-test-bzr.$$";
7 my $bzr=`which bzr`;
8 chomp $bzr;
9 if (! -x $bzr) {
10 eval q{
11 use Test::More skip_all => "bzr not available"
14 if (! mkdir($dir)) {
15 die $@;
18 use Test::More tests => 17;
20 BEGIN { use_ok("IkiWiki"); }
22 %config=IkiWiki::defaultconfig();
23 $config{rcs} = "bzr";
24 $config{srcdir} = "$dir/repo";
25 IkiWiki::loadplugins();
26 IkiWiki::checkconfig();
28 # XXX
29 # This is a workaround for bzr's new requirement that bzr whoami be run
30 # before committing. This makes the test suite work with an unconfigured
31 # bzr, but ignores the need to have a properly configured bzr before
32 # using ikiwiki with bzr.
33 $ENV{HOME}=$dir;
34 system 'bzr whoami test@example.com';
36 system "bzr init $config{srcdir}";
38 use CGI::Session;
39 my $session=CGI::Session->new;
40 $session->param("name", "Joe User");
42 # Web commit
43 my $test1 = readfile("t/test1.mdwn");
44 writefile('test1.mdwn', $config{srcdir}, $test1);
45 IkiWiki::rcs_add("test1.mdwn");
46 IkiWiki::rcs_commit(
47 file => "test1.mdwn",
48 message => "Added the first page",
49 token => "moo",
50 session => $session);
52 my @changes;
53 @changes = IkiWiki::rcs_recentchanges(3);
55 is($#changes, 0);
56 is($changes[0]{message}[0]{"line"}, "Added the first page");
57 is($changes[0]{pages}[0]{"page"}, "test1");
58 is($changes[0]{user}, "Joe User");
60 # Manual commit
61 my $username = "Foo Bar";
62 my $user = "$username <foo.bar\@example.com>";
63 my $message = "Added the second page";
65 my $test2 = readfile("t/test2.mdwn");
66 writefile('test2.mdwn', $config{srcdir}, $test2);
67 system "bzr add --quiet $config{srcdir}/test2.mdwn";
68 system "bzr commit --quiet --author \"$user\" -m \"$message\" $config{srcdir}";
70 @changes = IkiWiki::rcs_recentchanges(3);
72 is($#changes, 1);
73 is($changes[0]{message}[0]{"line"}, $message);
74 is($changes[0]{user}, $username);
75 is($changes[0]{pages}[0]{"page"}, "test2");
77 is($changes[1]{pages}[0]{"page"}, "test1");
79 my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
80 ok($ctime >= time() - 20);
82 my $mtime = IkiWiki::rcs_getmtime("test2.mdwn");
83 ok($mtime >= time() - 20);
85 writefile('test3.mdwn', $config{srcdir}, $test1);
86 IkiWiki::rcs_add("test3.mdwn");
87 IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
88 IkiWiki::rcs_commit_staged(
89 message => "Added the 4th page",
90 session => $session,
93 @changes = IkiWiki::rcs_recentchanges(4);
95 is($#changes, 2);
96 is($changes[0]{pages}[0]{"page"}, "test4");
98 ok(mkdir($config{srcdir}."/newdir"));
99 IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
100 IkiWiki::rcs_commit_staged(
101 message => "Added the 5th page",
102 session => $session,
105 @changes = IkiWiki::rcs_recentchanges(4);
107 is($#changes, 3);
108 is($changes[0]{pages}[0]{"page"}, "newdir/test5");
110 IkiWiki::rcs_remove("newdir/test5.mdwn");
111 IkiWiki::rcs_commit_staged(
112 message => "Remove the 5th page",
113 session => $session,
116 system "rm -rf $dir";