addAddressType: initial implementation & unit test
This commit is contained in:
		
							parent
							
								
									a1df7fc544
								
							
						
					
					
						commit
						a3aafac44a
					
				
					 2 changed files with 52 additions and 0 deletions
				
			
		| 
						 | 
					@ -110,6 +110,41 @@ sub addSupporter ($$) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
######################################################################
 | 
					######################################################################
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=begin addAddressType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Adds an address type, or returns the existing one of that name if it already exists.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Arguments:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=over
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=item $addressType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Scalar string that contains the email address type.  die() is called if not defined.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=back
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  Returns id of the address type.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=cut
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					sub addAddressType($$) {
 | 
				
			||||||
 | 
					  my($self, $type) = @_;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  die "addAddressType: type argument must be defined" if not defined $type;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  my $val = $self->dbh()->selectall_hashref("SELECT id, name FROM address_type WHERE name = '$type'", 'name');
 | 
				
			||||||
 | 
					  return $val->{$type}{id} if (defined $val and defined $val->{$type} and defined $val->{$type}{id});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  my $sth = $self->dbh->prepare("INSERT INTO address_type(name) VALUES(?)");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  $sth->execute($type);
 | 
				
			||||||
 | 
					  my $id = $self->dbh->last_insert_id("","","","");
 | 
				
			||||||
 | 
					  $sth->finish();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  return $id;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=begin addEmailAddress
 | 
					=begin addEmailAddress
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Arguments:
 | 
					Arguments:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -79,6 +79,23 @@ dies_ok { $sp->_addEmailAdress(undef, 'drapper@example.org', 'paypal'); }
 | 
				
			||||||
dies_ok { $sp->_addEmailAdress("String", 'drapper@example.org', 'paypal'); }
 | 
					dies_ok { $sp->_addEmailAdress("String", 'drapper@example.org', 'paypal'); }
 | 
				
			||||||
        "_addEmailAdress: dies for non-numeric id";
 | 
					        "_addEmailAdress: dies for non-numeric id";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=item addAddressType
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					=cut
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=back
 | 
					=back
 | 
				
			||||||
 | 
					
 | 
				
			||||||
=item Internal methods used only by the module itself.
 | 
					=item Internal methods used only by the module itself.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue