/trunk/t/00-init.t

http://perlwikipedia.googlecode.com/ · Raku · 71 lines · 71 code · 0 blank · 0 comment · 0 complexity · 8217ba6300ea03a9ee3d38dd1674076b MD5 · raw file

  1. use strict;
  2. use warnings;
  3. use Test::More 0.96 tests => 4;
  4. BEGIN {
  5. my $bail_diagnostic = <<'END';
  6. There was a problem loading the module. Typically,
  7. this means you have installed MediaWiki::Bot without
  8. the prerequisites. Please check the documentation for
  9. installation instructions, or ask for help from the
  10. members of perlwikibot@googlegroups.com.
  11. The test suite will bail out now; doing more testing is
  12. pointless since everything will fail.
  13. END
  14. use_ok('MediaWiki::Bot') or BAIL_OUT($bail_diagnostic);
  15. };
  16. # Provide some info to the tester
  17. unless ($ENV{AUTOMATED_TESTING}) {
  18. diag <<'END';
  19. Thanks for using MediaWiki::Bot. If any of these
  20. tests fail, or you need any other assistance with
  21. the module, please email our support mailing list
  22. at perlwikibot@googlegroups.com, or submit a bug
  23. to our tracker http://perlwikipedia.googlecode.com
  24. END
  25. diag <<'END' if (!defined($ENV{'PWPUsername'}) and !defined($ENV{'PWPPassword'}));
  26. If you want, you can log in for editing tests.
  27. To log in for those tests, stop the test suite now,
  28. set the environment variables PWPUsername and
  29. PWPPassword, and run the test suite.
  30. END
  31. sleep(2);
  32. }
  33. my $bot = new_ok('MediaWiki::Bot'); # outside subtest b/c reused later
  34. # Some deeper diagnostics
  35. my $useragent = 'MediaWiki::Bot tests (00-init.t)';
  36. my $host = '127.0.0.1';
  37. my $assert = 'bot';
  38. my $operator = 'MediaWiki::Bot tester';
  39. subtest 'diag-one' => sub {
  40. plan tests => 5;
  41. my $test_one = MediaWiki::Bot->new({
  42. agent => $useragent,
  43. host => $host,
  44. path => '',
  45. assert => $assert,
  46. operator => $operator,
  47. });
  48. is($test_one->{api}->{ua}->agent(), $useragent, 'Specified useragent set correctly');
  49. is($test_one->{assert}, $assert, 'Specified assert set orrectly');
  50. is($test_one->{operator}, $operator, 'Specified operator set correctly');
  51. is($test_one->{api}->{config}->{api_url}, "http://$host/api.php", 'api.php with null path is OK'); # Issue 111: Null $path value returns "w"
  52. like($bot->{api}->{ua}->agent(), qr{^MediaWiki::Bot/(v?\d\.\d\.\d(_\d)?|dev)$}, 'Useragent built correctly');
  53. };
  54. subtest 'diag-two' => sub {
  55. plan tests => 2;
  56. my $test_two = MediaWiki::Bot->new({
  57. host => $host,
  58. path => undef,
  59. operator => $operator,
  60. });
  61. is( $test_two->{api}->{config}->{api_url}, 'http://127.0.0.1/w/api.php', 'api.php with undef path is OK');
  62. like($test_two->{api}->{ua}->agent(), qr/\Q$operator\E/, 'operator appears in the useragent');
  63. };