90723a987817b4d4c52988ee68a5bf3fc4a0bb11
[poe-component-irc-plugin-infobot.git] / t / POE-Component-IRC-Plugin-Infobot.t
1 #!/usr/bin/perl -wT
2 use strict;
3 use warnings;
4
5 use Taint::Util qw/taint/;
6 use Test::MockObject;
7 use Test::More tests => 16;
8
9 BEGIN { use_ok('POE::Component::IRC::Plugin::Infobot') };
10
11 no warnings 'redefine';
12 sub POE::Component::IRC::Plugin::Infobot::getstr {
13 my $rstrings = shift;
14 sprintf @{$rstrings}[0], @_
15 }
16 use warnings 'redefine';
17
18 my $last_msg;
19 my $last_ctcp;
20
21 sub yield {
22 $last_msg = $_[3] if $_[1] eq 'privmsg';
23 $last_ctcp = $_[3] if $_[1] eq 'ctcp';
24 }
25
26 my $mockirc = Test::MockObject->new;
27 $mockirc->mock(yield => \&yield)->set_always(nick_name => 'bot');
28
29 my $self = POE::Component::IRC::Plugin::Infobot->new(filename => undef);
30
31 sub runtest{
32 my ($message, $expect, $comment, $private) = @_;
33 undef $last_msg;
34 undef $last_ctcp;
35 $self->S_public($mockirc, \'mgv!marius@ieval.ro', \([ '#chan' ]), \$message) unless $private;
36 $self->S_msg($mockirc, \'mgv!marius@ieval.ro', undef, \$message) if $private;
37 is($last_msg // $last_ctcp, $expect, $comment)
38 }
39
40 runtest 'bot: a is b', 'sure, mgv', 'add';
41 runtest 'bot: a is b', 'I already had it that way, mgv', 'add same factoid twice';
42 runtest 'bot: a is c', '... but a is b!', 'redefine factoid';
43 runtest 'a?', 'a is b', 'query';
44 runtest 'bot: forget a', 'mgv: I forgot a', 'forget';
45 runtest 'bot: forget a', 'I didn\'t have anything matching a, mgv', 'forget inexistent factoid';
46 runtest 'a?', undef, 'query for inexistent factoid';
47 runtest 'bot: a?', 'I don\'t know, mgv', 'addressed query for inexistent factoid';
48
49 runtest 'bot: b is <reply> c', 'sure, mgv', 'add with reply';
50 runtest 'b?', 'c', 'check reply';
51 runtest 'bot: c is <action> d', 'sure, mgv', 'add with action';
52 runtest 'c?', 'ACTION d', 'check action';
53
54 runtest 'x is y', 'sure, mgv', 'private add', 1;
55 runtest 'x?', 'x is y', 'private query', 1;
56 runtest 'forget x', 'mgv: I forgot x', 'private forget', 1;
This page took 0.026097 seconds and 3 git commands to generate.