Debian Codegraph @

t/04_plugins/12_autojoin/02_join.t

raw
1 use strict;
2 use warnings FATAL => 'all';
3 use lib 't/inc';
4 use POE;
5 use POE::Component::IRC;
6 use POE::Component::IRC::Plugin::AutoJoin;
7 use POE::Component::Server::IRC;
8 use Test::More tests => 4;
9
10 my $bot = POE::Component::IRC->spawn(
11 Flood => 1,
12 plugin_debug => 1,
13 );
14 my $ircd = POE::Component::Server::IRC->spawn(
15 Auth => 0,
16 AntiFlood => 0,
17 );
18 $bot->plugin_add(AutoJoin => POE::Component::IRC::Plugin::AutoJoin->new(
19 Channels => ['#chan1', '#chan2'],
20 ));
21
22 POE::Session->create(
23 package_states => [
24 main => [qw(
25 _start
26 ircd_listener_add
27 ircd_listener_failure
28 _shutdown
29 irc_001
30 irc_join
31 irc_disconnected
32 )],
33 ],
34 );
35
36 $poe_kernel->run();
37
38 sub _start {
39 my ($kernel) = $_[KERNEL];
40
41 $ircd->yield('register', 'all');
42 $ircd->yield('add_listener');
43 $kernel->delay(_shutdown => 60, 'Timed out');
44 }
45
46 sub ircd_listener_failure {
47 my ($kernel, $op, $reason) = @_[KERNEL, ARG1, ARG3];
48 $kernel->yield('_shutdown', "$op: $reason");
49 }
50
51 sub ircd_listener_add {
52 my ($kernel, $port) = @_[KERNEL, ARG0];
53
54 $bot->yield(register => 'all');
55 $bot->yield(connect => {
56 nick => 'TestBot1',
57 server => '127.0.0.1',
58 port => $port,
59 });
60 }
61
62 sub irc_001 {
63 my $irc = $_[SENDER]->get_heap();
64 pass('Logged in');
65 }
66
67 sub irc_join {
68 my ($sender, $heap, $where) = @_[SENDER, HEAP, ARG1];
69 my $irc = $sender->get_heap();
70 $heap->{joined}++;
71
72 $where =~ /^#chan[12]$/
73 ? pass("Joined channel $where")
74 : fail("Joined wrong channel $where");
75 ;
76
77 $irc->yield('quit') if $heap->{joined} == 2;
78 }
79
80 sub irc_disconnected {
81 my ($kernel) = $_[KERNEL];
82 pass('irc_disconnected');
83 $kernel->yield('_shutdown');
84 }
85
86 sub _shutdown {
87 my ($kernel, $error) = @_[KERNEL, ARG0];
88 fail($error) if defined $error;
89
90 $kernel->alarm_remove_all();
91 $bot->yield('shutdown');
92 $ircd->yield('shutdown');
93 }
94