2015-12-10 02:39:40 +00:00
|
|
|
# Supporters.t -*- Perl -*-
|
|
|
|
# Basic unit tests for Supporters.pm
|
2015-12-07 01:20:14 +00:00
|
|
|
#########################
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2015-12-10 03:56:22 +00:00
|
|
|
use Test::More tests => 21;
|
2015-12-07 02:56:59 +00:00
|
|
|
use Test::Exception;
|
|
|
|
|
2015-12-09 23:44:05 +00:00
|
|
|
use Scalar::Util qw(looks_like_number);
|
|
|
|
|
2015-12-07 02:28:49 +00:00
|
|
|
=pod
|
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
Supporters.t is the basic unit tests for Supporters.pm. It tests the
|
|
|
|
following things:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item use command for the module.
|
2015-12-07 02:28:49 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
BEGIN { use_ok('Supporters') };
|
|
|
|
|
|
|
|
|
2015-12-07 02:28:49 +00:00
|
|
|
require 't/CreateTestDB.pl';
|
|
|
|
|
|
|
|
my $dbh = get_test_dbh();
|
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
|
|
|
|
=item Public-facing methods of the module, as follows:
|
|
|
|
|
|
|
|
=over
|
|
|
|
|
|
|
|
=item new
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2015-12-07 02:55:01 +00:00
|
|
|
my $sp = new Supporters($dbh, "testcmd");
|
2015-12-07 02:28:49 +00:00
|
|
|
|
2015-12-07 03:08:29 +00:00
|
|
|
is($dbh, $sp->dbh(), "new: verify dbh set");
|
|
|
|
is("testcmd", $sp->ledgerCmd(), "new: verify ledgerCmd set");
|
2015-12-07 01:20:14 +00:00
|
|
|
|
2015-12-07 02:56:59 +00:00
|
|
|
|
|
|
|
=pod
|
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
=item addSupporter
|
2015-12-07 02:56:59 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2015-12-07 03:24:10 +00:00
|
|
|
dies_ok { $sp->addSupporter({}) }
|
|
|
|
"addSupporter: ledger_entity_id required";
|
2015-12-07 03:07:34 +00:00
|
|
|
|
2015-12-09 23:44:05 +00:00
|
|
|
my $id1;
|
|
|
|
lives_ok { $id1 = $sp->addSupporter({ ledger_entity_id => "Campbell-Peter" }); }
|
|
|
|
"addSupporter: add works for minimal acceptable settings";
|
|
|
|
|
|
|
|
ok( (looks_like_number($id1) and $id1 > 0),
|
|
|
|
"addSupporter: add works for minimal acceptable settings");
|
2015-12-07 03:24:10 +00:00
|
|
|
|
|
|
|
dies_ok { $sp->addSupporter({ public_ack => 1, ledger_entity_id => "Whitman-Dick" }) }
|
|
|
|
"addSupporter: display_name required";
|
|
|
|
|
2015-12-10 03:52:31 +00:00
|
|
|
my $drapperId;
|
|
|
|
lives_ok { $drapperId = $sp->addSupporter({ display_name => "Donald Drapper",
|
2015-12-09 23:44:05 +00:00
|
|
|
public_ack => 1, ledger_entity_id => "Whitman-Dick" }); }
|
2015-12-07 03:24:10 +00:00
|
|
|
"addSupporter: public_ack set to true with a display_name given";
|
2015-12-07 02:56:59 +00:00
|
|
|
|
2015-12-10 03:52:31 +00:00
|
|
|
ok( (looks_like_number($drapperId) and $drapperId > $id1),
|
2015-12-09 23:44:05 +00:00
|
|
|
"addSupporter: add works with public_ack set to true and a display_name given");
|
2015-12-07 01:20:14 +00:00
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
=item addEmailAddress
|
2015-12-10 02:38:07 +00:00
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
=cut
|
2015-12-10 02:38:07 +00:00
|
|
|
|
2015-12-10 03:50:02 +00:00
|
|
|
dies_ok { $sp->addEmailAddress(undef, 'drapper@example.org', 'paypal'); }
|
2015-12-10 03:53:20 +00:00
|
|
|
"addEmailAddress: dies for undefined id";
|
2015-12-10 03:50:02 +00:00
|
|
|
dies_ok { $sp->addEmailAddress("String", 'drapper@example.org', 'paypal'); }
|
2015-12-10 03:53:20 +00:00
|
|
|
"addEmailAddress: dies for non-numeric id";
|
|
|
|
|
2015-12-10 03:56:22 +00:00
|
|
|
ok($sp->addEmailAddress($drapperId, 'drapper@example.org', 'work'),
|
|
|
|
"addEmailAddress: simple add test");
|
2015-12-10 03:38:22 +00:00
|
|
|
|
2015-12-10 03:48:59 +00:00
|
|
|
=item addAddressType
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2015-12-10 03:56:22 +00:00
|
|
|
# This test cheats a bit -- it assumes that the database is assigning serials starting with 1
|
|
|
|
|
|
|
|
ok($sp->addAddressType('work') == 1,
|
|
|
|
"addEmailAddress: verify addEmailAddress added the addressType underneath");
|
|
|
|
|
2015-12-10 03:48:59 +00:00
|
|
|
dies_ok { $sp->addAddressType(undef); } "addAddressType: dies for undef";
|
|
|
|
|
|
|
|
my $paypalPayerAddressType;
|
|
|
|
|
|
|
|
ok($paypalPayerAddressType = $sp->addAddressType("paypal payer"), "addAddressType: basic add works");
|
|
|
|
|
|
|
|
my $same;
|
|
|
|
|
|
|
|
ok($same = $sp->addAddressType("paypal payer"), "addAddressType: lookup works");
|
|
|
|
|
|
|
|
ok($same == $paypalPayerAddressType, "addAddressType: lookup returns same as the basic add");
|
|
|
|
|
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
=back
|
|
|
|
|
|
|
|
=item Internal methods used only by the module itself.
|
2015-12-10 02:38:07 +00:00
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
=over
|
2015-12-10 02:38:07 +00:00
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
=item _verifyId
|
2015-12-10 02:38:07 +00:00
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2015-12-10 03:52:31 +00:00
|
|
|
ok( $sp->_verifyId($drapperId), "_verifyId: id just added exists");
|
2015-12-10 02:38:07 +00:00
|
|
|
|
|
|
|
dies_ok { $sp->_verifyId(undef); } "_verifyId: dies for undefined id";
|
|
|
|
dies_ok { $sp->_verifyId("String") } "_verifyId: dies for non-numeric id";
|
|
|
|
|
|
|
|
# This is a hacky way to test this; but should work
|
2015-12-10 03:52:31 +00:00
|
|
|
ok(not ($sp->_verifyId($drapperId + 10)), "_verifyId: non-existent id is not found");
|
2015-12-10 02:38:07 +00:00
|
|
|
|
|
|
|
=pod
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
2015-12-10 03:38:22 +00:00
|
|
|
=back
|
|
|
|
|
2015-12-10 02:38:07 +00:00
|
|
|
=cut
|
|
|
|
|
2015-12-09 23:44:05 +00:00
|
|
|
$dbh->disconnect();
|
2015-12-10 02:36:57 +00:00
|
|
|
###############################################################################
|
|
|
|
#
|
|
|
|
# Local variables:
|
|
|
|
# compile-command: "perl -c Supporters.t"
|
|
|
|
# End:
|
|
|
|
|