_lookupEmailAddressId: implement helper function

This helper function will be needed for a few changes I'm about to make.
This commit is contained in:
Bradley M. Kuhn 2015-12-30 05:33:05 -08:00
parent 2ef0dad053
commit 4d2fc22de1
2 changed files with 46 additions and 1 deletions

View file

@ -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

View file

@ -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;