Przeglądaj źródła

Working on tests

Andy Baugh 8 lat temu
rodzic
commit
951f29b96c

+ 1 - 1
lib/Cpanel/iContact/Provider/IRC.pm

@@ -41,7 +41,7 @@ sub send {
 
 sub _send {
     my ( $self, %args ) = @_;
-    # TODO research what is installed on cP boxes to see what I can use here
+    require Bot::BasicBot;
 
     return;
 }

+ 22 - 1
lib/Cpanel/iContact/Provider/Schema/IRC.pm

@@ -17,6 +17,16 @@ HALP
 <p>Whether or not the IRC server your Notification User is registered at supports SSL/TLS.<br />
 If set improperly, this will cause sending notifications to fail (some IRC servers <em>require</em> SSL/TLS, some <em>don't support it</em>).
 </p>
+HALP
+    my $help4 =<<HALP;
+<p>The IRC Server Address<br />
+The domain or IP your IRC server is active on.
+</p>
+HALP
+    my $help5 =<<HALP;
+<p>The IRC Server Port<br />
+The port your IRC server is active on. Defaults to 6667.
+</p>
 HALP
     return {
         'CONTACTIRC' => {
@@ -28,7 +38,7 @@ HALP
                 @chans = grep { index( $_, '#' ) != -1 } @chans;
                 return join( ",", @chans );
             },
-            'label' => 'IRC Notification Destinations',
+            'label' => 'IRC Notification Destinations'
             'help' => $help1,
         },
         'IRCNICK' => {
@@ -42,6 +52,17 @@ HALP
             'label' => 'IRC: Use SSL/TLS?',
             'help' => $help3,
         },
+        'IRCSERVER' => {
+            'type'     => 'binary',
+            'label' => 'IRC Server Address',
+            'help' => $help3,
+        },
+       'IRCPORT' => {
+            'type'     => 'binary',
+            'label' => 'IRC Server Port',
+            'help' => $help3,
+        },
+
     };
 }
 

+ 48 - 0
t/Cpanel-iContact-Provider-IRC.t

@@ -0,0 +1,48 @@
+use strict;
+use warnings;
+
+use Cwd qw{abs_path};
+use File::Basename qw{dirname};
+use lib abs_path( dirname(__FILE__) . "/../lib" );
+
+use Test::More 'tests' => 5;
+use Test::Fatal;
+use Config::Simple ();
+
+is( exception { require Cpanel::iContact::Provider::XMPP; }, undef, 'Module at least compiles' );
+isa_ok( my $xmpp = Cpanel::iContact::Provider::XMPP->new(), "Cpanel::iContact::Provider::XMPP" );
+my $sent;
+{
+    no warnings qw{redefine once};
+    local *Bot::BasicBot::new     = sub { return bless {}, "Bot::BasicBot"; };
+    local *Bot::BasicBot::AuthSend    = sub { return ( 'ok', "Assumed Success" ); };
+    local *Bot::BasicBot::MessageSend = sub { return; };
+    local *Bot::BasicBot::Disconnect  = sub { return; };
+    is( exception { $sent = $xmpp->send(); }, undef, 'send() did not die' );
+}
+ok( $sent, "...and the message appears to have actually sent." );
+
+SKIP: {
+    my $conf_file = abs_path( dirname(__FILE__) . "/../.irctestrc" );
+    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'},
+        'subject' => 'My Super cool test notification',
+        'content' => "This is a test of Cpanel::iContact::Provider::IRC. Please Ignore",
+    );
+
+    {
+        no warnings qw{redefine once};
+        local *Cpanel::iContact::Provider::IRC::new = sub {
+            return bless {
+                'contact' => $test_conf,
+            }, $_[0];
+        };
+        my $spammer = Cpanel::iContact::Provider::XMPP->new();
+        is( exception { $spammer->_send(%args) }, undef, "Didn't fail to send notification using full functional test" );
+    }
+}
+
+# TODO error paths
+

+ 0 - 1
t/Cpanel-iContact-Provider-XMPP.t

@@ -24,7 +24,6 @@ ok( $sent, "...and the message appears to have actually sent." );
 
 SKIP: {
     my $conf_file = abs_path( dirname(__FILE__) . "/../.xmpptestrc" );
-    diag("Conf file '$conf_file' doesn't exist") if !-f $conf_file;
     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 = (