Kaynağa Gözat

WIP based on actually testing it for reals

Andy Baugh 8 yıl önce
ebeveyn
işleme
044455c7b4

+ 1 - 1
Makefile

@@ -10,4 +10,4 @@ test:
 	[ -x /usr/local/cpanel/3rdparty/bin/prove ] || prove t/*.t
 
 depend:
-	perl -MNet::XMPP -MMozilla::CA -MTest::More -MTest::Fatal -MTest::MockModule -MConfig::Simple -MBot::BasicBot -e 'exit 0;' || sudo cpan -i Net::XMPP Mozilla::CA Test::More Test::Fatal Test::MockModule Config::Simple Bot::BasicBot
+	perl -MNet::XMPP -MMozilla::CA -MTest::More -MTest::Fatal -MTest::MockModule -MConfig::Simple -MBot::BasicBot -MPOE::Component::SSLify -e 'exit 0;' || sudo cpan -i Net::XMPP Mozilla::CA Test::More Test::Fatal Test::MockModule Config::Simple Bot::BasicBot POE::Component::SSLify

+ 2 - 0
lib/Cpanel/iContact/Provider.pm

@@ -17,6 +17,8 @@ sub new {
             'XMPPTLSVERIFY'     => 1,
             'XMPPCOMPONENTNAME' => 'jibber.jabber.org',
             'IRCSERVER'         => 'irc.bot.test',
+            'IRCPORT'           => 666,
+            'IRCNICK'           => 'DevilBot',
         },
         'args' => {
             'subject'   => 'cPanel on Drugs',

+ 11 - 5
lib/Cpanel/iContact/Provider/IRC.pm

@@ -17,8 +17,8 @@ sub send {
     my $body_copy    = ${ $args_hr->{'text_body'} };
 
     require Encode;
-    my $subject      = Encode::decode_utf8( $subject_copy, $Encode::FB_QUIET );
-    my $body         = Encode::decode_utf8( $body_copy, $Encode::FB_QUIET );
+    my $subject = Encode::decode_utf8( $subject_copy, $Encode::FB_QUIET );
+    my $body    = Encode::decode_utf8( $body_copy, $Encode::FB_QUIET );
 
     foreach my $destination ( @{ $args_hr->{'to'} } ) {
         local $@;
@@ -44,15 +44,21 @@ sub send {
 sub _send {
     my ( $self, %args ) = @_;
     require Bot::BasicBot;
+    if( $ENV{'AUTHOR_TESTS'} ) {
+        my $debugmsg = "# Attempting connection to $self->{'contact'}{'IRCSERVER'}:$self->{'contact'}{'IRCPORT'} as $self->{'contact'}{'IRCNICK'} in channel $args{'destination'}";
+        $debugmsg   .= " using SSL" if $self->{'contact'}{'IRCUSESSL'};
+        print $debugmsg, "\n";
+    }
     my $bot = Bot::BasicBot->new(
         'server'   => $self->{'contact'}{'IRCSERVER'},
         'port'     => $self->{'contact'}{'IRCPORT'} || 6667,
-        'channels' => $args{'destination'},
+        'channels' => [ $args{'destination'} ],
         'nick'     => $self->{'contact'}{'IRCNICK'} || 'cPanel_&_WHM',
         'ssl'      => $self->{'contact'}{'IRCUSESSL'},
     );
-    $bot->say( { 'body' => $args{'subject'} } );
-    $bot->say( { 'body' => $args{'content'} } );
+    $bot->run();
+    $bot->notice( { 'channel' => $args{'destination'}, 'body' => $args{'subject'} } );
+    $bot->notice( { 'channel' => $args{'destination'}, 'body' => $args{'content'} } );
     $bot->shutdown();
 
     return;

+ 4 - 3
t/Cpanel-iContact-Provider-IRC.t

@@ -7,7 +7,8 @@ use lib abs_path( dirname(__FILE__) . "/../lib" );
 
 use Test::More 'tests' => 5;
 use Test::Fatal;
-use Bot::BasicBot ();
+use Bot::BasicBot  ();
+use Config::Simple ();
 
 is( exception { require Cpanel::iContact::Provider::IRC; }, undef, 'Module at least compiles' );
 isa_ok( my $bot = Cpanel::iContact::Provider::IRC->new(), "Cpanel::iContact::Provider::IRC" );
@@ -26,7 +27,7 @@ SKIP: {
     skip "Skipping functional testing, needful not supplied", 1 if !$ENV{'AUTHOR_TESTS'} || !-f $conf_file;
     my $test_conf = { Config::Simple->import_from($conf_file)->vars() };
     my %args = (
-        'destination' => $test_conf->{'XMPPUSERNAME'},
+        'destination' => $test_conf->{'CONTACTIRC'},
         'subject' => 'My Super cool test notification',
         'content' => "This is a test of Cpanel::iContact::Provider::IRC. Please Ignore",
     );
@@ -38,7 +39,7 @@ SKIP: {
                 'contact' => $test_conf,
             }, $_[0];
         };
-        my $spammer = Cpanel::iContact::Provider::XMPP->new();
+        my $spammer = Cpanel::iContact::Provider::IRC->new();
         is( exception { $spammer->_send(%args) }, undef, "Didn't fail to send notification using full functional test" );
     }
 }