diff --git a/Supporters/lib/Supporters.pm b/Supporters/lib/Supporters.pm index 90c5ab7..2f0780d 100644 --- a/Supporters/lib/Supporters.pm +++ b/Supporters/lib/Supporters.pm @@ -975,6 +975,40 @@ sub _lookupRequestTypeById($$) { return undef; } } +###################################################################### + +=item _lookupEmailAddressId() + +Parameters: + +=over + +=item $self: current object. + +=item $emailAdress: A scalar string argument that is the email_adress + + +=back + +Returns: scalar, which is the email_address.id found iff. the C<$emailAddress> is valid and +already in the supporter database's email_address table. + +=cut + + +sub _lookupEmailAddressId($$) { + my($self, $emailAddress) = @_; + + die "_lookupEmailAddressId() called with undef" unless defined $emailAddress; + + my $val = $self->dbh()->selectall_hashref("SELECT id, email_address FROM email_address WHERE email_address = " . + $self->dbh->quote($emailAddress), 'email_address'); + if (defined $val and defined $val->{$emailAddress}) { + return $val->{$emailAddress}{id}; + } else { + return undef; + } +} =item _getOrCreateRequestType diff --git a/Supporters/t/Supporters.t b/Supporters/t/Supporters.t index 08ed631..1807dac 100644 --- a/Supporters/t/Supporters.t +++ b/Supporters/t/Supporters.t @@ -5,7 +5,7 @@ use strict; use warnings; -use Test::More tests => 173; +use Test::More tests => 176; use Test::Exception; use Scalar::Util qw(looks_like_number reftype); @@ -538,6 +538,17 @@ dies_ok { $sp->_verifyId("String") } "_verifyId: dies for non-numeric id"; # This is a hacky way to test this; but should work ok(not ($sp->_verifyId($drapperId + 10)), "_verifyId: non-existent id is not found"); +=item _lookupEmailAddressId + +=cut + +dies_ok { $sp->_lookupEmailAddressId(undef); } "_lookupEmailAddressId: dies for undefined email_address"; + +is($sp->_lookupEmailAddressId('drapper@example.org'), $drapperEmailId, + "_lookupEmailAddressId: returns email Id for known item"); + +is($sp->_lookupEmailAddressId('drapper@example.com'), undef, + "_lookupEmailAddressId: returns undef for unknown item."); $sp = undef;