Cpanel-iContact-Provider-XMPP.t 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. diag("Conf file '$conf_file' doesn't exist") if !-f $conf_file;
  24. skip "Skipping functional testing, needful not supplied", 1 if !$ENV{'AUTHOR_TESTS'} || !-f $conf_file;
  25. my $test_conf = { Config::Simple->import_from($conf_file)->vars() };
  26. my %args = (
  27. 'destination' => $test_conf->{'XMPPUSERNAME'},
  28. 'subject' => 'My Super cool test notification',
  29. 'content' => "This is a test of Cpanel::iContact::Provider::XMPP. Please Ignore",
  30. );
  31. {
  32. no warnings qw{redefine once};
  33. local *Cpanel::iContact::Provider::XMPP::new = sub {
  34. return bless {
  35. 'contact' => $test_conf,
  36. }, $_[0];
  37. };
  38. my $spammer = Cpanel::iContact::Provider::XMPP->new();
  39. is( exception { $spammer->_send(%args) }, undef, "Didn't fail to send notification using full functional test" );
  40. }
  41. }
  42. # TODO error paths
  43. #isnt( exception { $xmpp->send(); }, undef, "We blew up when we timed out on connect" );