Fix behaviour on privmsg and add tests for privmsg
[poe-component-irc-plugin-seen.git] / t / POE-Component-IRC-Plugin-Seen.t
1 use v5.14;
2 use strict;
3 use warnings;
4
5 use Test::More tests => 10;
6 use Test::MockObject;
7
8 BEGIN { *CORE::GLOBAL::localtime = sub { 'now' } }
9
10 BEGIN { use_ok('POE::Component::IRC::Plugin::Seen') };
11
12 # Variable setup
13 my $last_msg;
14
15 my $mockirc = Test::MockObject->new;
16 $mockirc->mock(yield => sub { $last_msg = $_[3] if $_[1] eq 'privmsg'})->set_always(nick_name => 'bot');
17
18 my $self = POE::Component::IRC::Plugin::Seen->new;
19 my $channels = [ '#chan' ];
20 my $rmgv = \'mgv!marius@ieval.ro';
21
22 # Sub setup
23 sub runtest{
24 my ($message, $expect, $comment, $privmsg) = @_;
25 undef $last_msg;
26 $self->S_public($mockirc, $rmgv, \$channels, \$message) unless $privmsg;
27 $self->S_msg($mockirc, $rmgv, \$channels, \$message) if $privmsg;
28 is($last_msg, $expect, $comment)
29 }
30
31 runtest 'something', undef, 'initialize';
32 runtest 'seen mgv', 'I last saw mgv now on #chan saying something', 'public';
33
34 $self->S_ctcp_action($mockirc, $rmgv, \$channels, \'sleeping');
35 runtest '!seen mgv', 'I last saw mgv now on #chan doing: * sleeping', 'ctcp_action';
36
37 $self->S_join($mockirc, $rmgv, \'#chan');
38 runtest 'bot: seen mgv', 'I last saw mgv now joining #chan', 'join';
39
40 $self->S_part($mockirc, $rmgv, \'#chan', \'');
41 runtest 'bot: !seen mgv', 'I last saw mgv now parting #chan', 'part without message';
42
43 $self->S_part($mockirc, $rmgv, \'#chan', \'buh-bye');
44 runtest 'bot: seen mgv', "I last saw mgv now parting #chan with message 'buh-bye'", 'part with message';
45
46 runtest 'bot: seen asd', "I haven't seen asd", "haven't seen";
47
48 # Private messages
49 runtest 'seen asd', "I haven't seen asd", "haven't seen", 1;
50 runtest ' !seen asd', "I haven't seen asd", "haven't seen", 1;
This page took 0.022334 seconds and 4 git commands to generate.