Almost-minimal filesystem based blog.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

142 lines
2.8 KiB

  1. #!/usr/bin/perl
  2. =pod
  3. =head1 NAME
  4. test.pl - a set of basic tests for Wala.pm
  5. =head1 SYNOPSIS
  6. Given a working installation and configuration file:
  7. ./test.pl
  8. =head1 DESCRIPTION
  9. This section to-come.
  10. =head1 MISSING TESTS
  11. These items aren't tested at all, at the moment. A number of them aren't
  12. particularly trivial to test.
  13. sub get_diff
  14. sub get_latest_diff_date
  15. sub write_page
  16. sub add_to_page
  17. sub log_page_edit
  18. sub parse_cookies
  19. sub set_cookies
  20. sub setup
  21. sub parse_parameters
  22. sub write_diff
  23. sub merge_diff
  24. =head1 SEE ALSO
  25. validate.pl in the WalaWiki distribution.
  26. =cut
  27. use strict;
  28. use warnings;
  29. use lib 'lib';
  30. #use Test::HTML::W3C 'show_detail';
  31. use Test::Simple tests => 11;
  32. use Wala;
  33. # TESTS
  34. section ('configuration');
  35. our (%WalaConf, %DISPLAY_CONF);
  36. do 'p1k3.conf.pl';
  37. ok (%WalaConf, 'External configuration hash defined.');
  38. ok (my $w = Wala->new(%WalaConf), 'Got Wala object.');
  39. # This will turn off stuff that breaks testing.
  40. $w->TestMode(1);
  41. section ('individual subroutine tests');
  42. my $username = $w->get_username;
  43. ok ($username eq 'Anonymous',
  44. "get_username returns $username.");
  45. ok (Wala::get_mtime('Wala.pm') =~ m/\d+/,
  46. 'get_mtime returns digits.');
  47. ok (Wala::mygmtime(0) eq 'Thu, 01-Jan-1970 00:00:00 GMT',
  48. 'mygmtime(0) returns epoch');
  49. # Hack. Depends on ./log
  50. LOGFILE: {
  51. my $tmp = $w->LogFile;
  52. $w->LogFile("./log");
  53. ok ($w->recent_changes(1) =~ m/\d+ \w+ \w+.*$/,
  54. 'recent_changes(1) returns an appropriate logfile line.');
  55. $w->LogFile($tmp);
  56. }
  57. ok ($w->spamcheck("http://spamcheckfunction.com", "TEST", "TEST") == 1,
  58. 'spamcheck trips on a URL');
  59. section ('starting link code testing');
  60. my $scriptname = $w->ScriptName;
  61. ok (
  62. $w->convert_wikiwords('TestWord')
  63. =~ m/<a href="$scriptname\?.*?TestWord"/,
  64. 'Return link for TestWord'
  65. );
  66. ok (
  67. $w->convert_wikiwords('[TestWord|T Word]')
  68. =~ m/<a href="$scriptname\?.*?TestWord".*?>T Word</,
  69. 'Return labeled link for TestWord'
  70. );
  71. ok (
  72. Wala::get_bracketed_link("[http://p1k3.com/ p1k3]")
  73. eq qq{<a href="http://p1k3.com/" class="external">p1k3</a>},
  74. 'Return bracketed link'
  75. );
  76. # this isn't doing what I'd like it to.
  77. ok (
  78. Wala::pagelinks('PageLink [other page link]'),
  79. 'Pagelinks sub finds ' . Wala::pagelinks('PageLink [other page link]') . ' links'
  80. );
  81. # END OF TESTS
  82. # Utility routines.
  83. sub hash_print {
  84. my %hash = @_;
  85. my $string;
  86. for my $key (keys %hash) {
  87. $string .= "\n$key: $hash{$key}";
  88. }
  89. return $string;
  90. }
  91. sub pause {
  92. my $time = shift;
  93. #print " pausing $time seconds\n";
  94. sleep $time;
  95. }
  96. sub section {
  97. my $msg = shift;
  98. print "\n-- $msg --\n\n";
  99. }