More tests for addressBook.
Fixed bugs in delete and getAddresses.
This commit is contained in:
parent
5064a5ac92
commit
12b72c9b59
2 changed files with 53 additions and 4 deletions
|
|
@ -35,7 +35,9 @@ private properties => my %properties;
|
||||||
|
|
||||||
=head2 addAddress ( address )
|
=head2 addAddress ( address )
|
||||||
|
|
||||||
Adds an address to the address book.
|
Adds an address to the address book. Returns a reference to the WebGUI::Shop::Address
|
||||||
|
object that was created. It does not trap exceptions, so any problems with creating
|
||||||
|
the object will be passed to the caller.
|
||||||
|
|
||||||
=head2 address
|
=head2 address
|
||||||
|
|
||||||
|
|
@ -133,7 +135,7 @@ Deletes this address book and all addresses contained in it.
|
||||||
|
|
||||||
sub delete {
|
sub delete {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
foreach my $address (@{$self->addresses}) {
|
foreach my $address (@{$self->getAddresses}) {
|
||||||
$address->delete;
|
$address->delete;
|
||||||
}
|
}
|
||||||
$self->session->db->write("delete from addressBook where addressBookId=?",[$self->getId]);
|
$self->session->db->write("delete from addressBook where addressBookId=?",[$self->getId]);
|
||||||
|
|
@ -187,7 +189,7 @@ Returns an array reference of address objects that are in this book.
|
||||||
sub getAddresses {
|
sub getAddresses {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
my @addressObjects = ();
|
my @addressObjects = ();
|
||||||
my $addresses = $self->session->db->read("select addressId from addresses where addressBookId=?",[$self->getId]);
|
my $addresses = $self->session->db->read("select addressId from address where addressBookId=?",[$self->getId]);
|
||||||
while (my ($addressId) = $addresses->array) {
|
while (my ($addressId) = $addresses->array) {
|
||||||
push(@addressObjects, WebGUI::Shop::Address->new($self, $addressId));
|
push(@addressObjects, WebGUI::Shop::Address->new($self, $addressId));
|
||||||
}
|
}
|
||||||
|
|
@ -264,6 +266,7 @@ sub update {
|
||||||
$properties{$id}{lastPayId} = $newProperties->{lastPayId} || $properties{$id}{lastPayId};
|
$properties{$id}{lastPayId} = $newProperties->{lastPayId} || $properties{$id}{lastPayId};
|
||||||
$properties{$id}{userId} = (exists $newProperties->{userId}) ? $newProperties->{userId} : $properties{$id}{userId};
|
$properties{$id}{userId} = (exists $newProperties->{userId}) ? $newProperties->{userId} : $properties{$id}{userId};
|
||||||
$properties{$id}{sessionId} = (exists $newProperties->{sessionId}) ? $newProperties->{sessionId} : $properties{$id}{sessionId};
|
$properties{$id}{sessionId} = (exists $newProperties->{sessionId}) ? $newProperties->{sessionId} : $properties{$id}{sessionId};
|
||||||
|
##Having both a userId and sessionId will confuse create.
|
||||||
if ($properties{$id}{userId} ne "") {
|
if ($properties{$id}{userId} ne "") {
|
||||||
$properties{$id}{sessionId} = "";
|
$properties{$id}{sessionId} = "";
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 15;
|
my $tests = 20;
|
||||||
plan tests => 1 + $tests;
|
plan tests => 1 + $tests;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -128,6 +128,52 @@ is($bookCount, 1, 'only 1 address book was created');
|
||||||
my $alreadyHaveBook = WebGUI::Shop::AddressBook->create($session);
|
my $alreadyHaveBook = WebGUI::Shop::AddressBook->create($session);
|
||||||
is($book->getId, $alreadyHaveBook->getId, 'creating an addressbook as visitor, when you already have one, returns the one already created');
|
is($book->getId, $alreadyHaveBook->getId, 'creating an addressbook as visitor, when you already have one, returns the one already created');
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
#
|
||||||
|
# getId
|
||||||
|
#
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
is($book->getId, $book->get('addressBookId'), 'getId is a shortcut for ->get');
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
#
|
||||||
|
# addAddress
|
||||||
|
#
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
my $address1 = $book->addAddress({ label => q{Red's cell} });
|
||||||
|
isa_ok($address1, 'WebGUI::Shop::Address', 'addAddress returns an object');
|
||||||
|
|
||||||
|
my $address2 = $book->addAddress({ label => q{Norton's office} });
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
#
|
||||||
|
# getAddresses
|
||||||
|
#
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
my @addresses = @{ $book->getAddresses() };
|
||||||
|
|
||||||
|
cmp_deeply(
|
||||||
|
\@addresses,
|
||||||
|
[$address1, $address2],
|
||||||
|
'getAddresses returns all address objects for this book'
|
||||||
|
);
|
||||||
|
|
||||||
|
#######################################################################
|
||||||
|
#
|
||||||
|
# delete
|
||||||
|
#
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
$book->delete();
|
||||||
|
$bookCount = $session->db->quickScalar('select count(*) from addressBook');
|
||||||
|
my $addrCount = $session->db->quickScalar('select count(*) from address');
|
||||||
|
|
||||||
|
is($bookCount, 0, 'delete: book deleted');
|
||||||
|
is($addrCount, 0, 'delete: also deletes addresses in the book');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
END: {
|
END: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue