Cpanel-iContact-Provider-XMPP.t 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. use strict;
  2. use warnings;
  3. use Cwd qw{abs_path};
  4. use File::Basename qw{dirname};
  5. use lib abs_path( dirname(__FILE__) . "/../lib" );
  6. use Test::More 'tests' => 5;
  7. use Test::Fatal;
  8. use Config::Simple ();
  9. is( exception { require Cpanel::iContact::Provider::XMPP; }, undef, 'Module at least compiles' );
  10. isa_ok( my $xmpp = Cpanel::iContact::Provider::XMPP->new(), "Cpanel::iContact::Provider::XMPP" );
  11. my $sent;
  12. {
  13. no warnings qw{redefine once};
  14. local *Net::XMPP::Client::Connect = sub { return 1; };
  15. local *Net::XMPP::Client::AuthSend = sub { return ( 'ok', "Assumed Success" ); };
  16. local *Net::XMPP::Client::MessageSend = sub { return; };
  17. local *Net::XMPP::Client::Disconnect = sub { return; };
  18. is( exception { $sent = $xmpp->send(); }, undef, 'send() did not die' );
  19. }
  20. ok( $sent, "...and the message appears to have actually sent." );
  21. SKIP: {
  22. my $conf_file = abs_path( dirname(__FILE__) . "/../.xmpptestrc" );
  23. skip "Skipping functional testing, needful not supplied", 1 if !$ENV{'AUTHOR_TESTS'} || !-f $conf_file;
  24. my $test_conf = { Config::Simple->import_from($conf_file)->vars() };
  25. my %args = (
  26. 'destination' => $test_conf->{'XMPPUSERNAME'},
  27. 'subject' => 'My Super cool test notification',
  28. 'content' => "This is a test of Cpanel::iContact::Provider::XMPP. Please Ignore",
  29. );
  30. {
  31. no warnings qw{redefine once};
  32. local *Cpanel::iContact::Provider::XMPP::new = sub {
  33. return bless {
  34. 'contact' => $test_conf,
  35. }, $_[0];
  36. };
  37. my $spammer = Cpanel::iContact::Provider::XMPP->new();
  38. is( exception { $spammer->_send(%args) }, undef, "Didn't fail to send notification using full functional test" );
  39. }
  40. }
  41. # TODO error paths
  42. #isnt( exception { $xmpp->send(); }, undef, "We blew up when we timed out on connect" );