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