summaryrefslogtreecommitdiff
path: root/t/bazaar.t
blob: 3e54ec4dc8f57ee7601f572d090a5dd66f04a822 (plain)
  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 || ! mkdir($dir)) {
  10. eval q{
  11. use Test::More skip_all => "bzr not available or could not make test dir"
  12. }
  13. }
  14. }
  15. use Test::More tests => 17;
  16. BEGIN { use_ok("IkiWiki"); }
  17. %config=IkiWiki::defaultconfig();
  18. $config{rcs} = "bzr";
  19. $config{srcdir} = "$dir/repo";
  20. IkiWiki::loadplugins();
  21. IkiWiki::checkconfig();
  22. system "bzr init $config{srcdir}";
  23. use CGI::Session;
  24. my $session=CGI::Session->new;
  25. $session->param("name", "Joe User");
  26. # Web commit
  27. my $test1 = readfile("t/test1.mdwn");
  28. writefile('test1.mdwn', $config{srcdir}, $test1);
  29. IkiWiki::rcs_add("test1.mdwn");
  30. IkiWiki::rcs_commit(
  31. file => "test1.mdwn",
  32. message => "Added the first page",
  33. token => "moo",
  34. session => $session);
  35. my @changes;
  36. @changes = IkiWiki::rcs_recentchanges(3);
  37. is($#changes, 0);
  38. is($changes[0]{message}[0]{"line"}, "Added the first page");
  39. is($changes[0]{pages}[0]{"page"}, "test1");
  40. is($changes[0]{user}, "Joe User");
  41. # Manual commit
  42. my $username = "Foo Bar";
  43. my $user = "$username <foo.bar\@example.com>";
  44. my $message = "Added the second page";
  45. my $test2 = readfile("t/test2.mdwn");
  46. writefile('test2.mdwn', $config{srcdir}, $test2);
  47. system "bzr add --quiet $config{srcdir}/test2.mdwn";
  48. system "bzr commit --quiet --author \"$user\" -m \"$message\" $config{srcdir}";
  49. @changes = IkiWiki::rcs_recentchanges(3);
  50. is($#changes, 1);
  51. is($changes[0]{message}[0]{"line"}, $message);
  52. is($changes[0]{user}, $username);
  53. is($changes[0]{pages}[0]{"page"}, "test2");
  54. is($changes[1]{pages}[0]{"page"}, "test1");
  55. my $ctime = IkiWiki::rcs_getctime("test2.mdwn");
  56. ok($ctime >= time() - 20);
  57. my $mtime = IkiWiki::rcs_getmtime("test2.mdwn");
  58. ok($mtime >= time() - 20);
  59. writefile('test3.mdwn', $config{srcdir}, $test1);
  60. IkiWiki::rcs_add("test3.mdwn");
  61. IkiWiki::rcs_rename("test3.mdwn", "test4.mdwn");
  62. IkiWiki::rcs_commit_staged(
  63. message => "Added the 4th page",
  64. session => $session,
  65. );
  66. @changes = IkiWiki::rcs_recentchanges(4);
  67. is($#changes, 2);
  68. is($changes[0]{pages}[0]{"page"}, "test4");
  69. ok(mkdir($config{srcdir}."/newdir"));
  70. IkiWiki::rcs_rename("test4.mdwn", "newdir/test5.mdwn");
  71. IkiWiki::rcs_commit_staged(
  72. message => "Added the 5th page",
  73. session => $session,
  74. );
  75. @changes = IkiWiki::rcs_recentchanges(4);
  76. is($#changes, 3);
  77. is($changes[0]{pages}[0]{"page"}, "newdir/test5");
  78. IkiWiki::rcs_remove("newdir/test5.mdwn");
  79. IkiWiki::rcs_commit_staged(
  80. message => "Remove the 5th page",
  81. session => $session,
  82. );
  83. system "rm -rf $dir";