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