update tests to match new code

This commit is contained in:
JT Smith 2008-03-19 22:30:41 +00:00
parent 3e6687ef7f
commit 1cb43b13af
2 changed files with 32 additions and 23 deletions

View file

@ -29,6 +29,27 @@ These subroutines are available from this package:
readonly cart => my %cart;
private properties => my %properties;
#-------------------------------------------------------------------
=head2 adjustQuantity ( [ quantity ] )
Increments quantity of item by one. Returns the quantity of this item in the cart.
=head3 quantity
If specified may increment quantity by more than one. Specify a negative number to decrement quantity. If the quantity ever reaches 0 or lower, the item will be removed from the cart.
=cut
sub adjustQuantity {
my ($self, $quantity) = @_;
$quantity ||= 1;
$self->setQuantity($quantity + $self->get("quantity"));
return $self->get("quantity");
}
#-------------------------------------------------------------------
=head2 cart ( )
@ -157,25 +178,6 @@ sub getSku {
}
#-------------------------------------------------------------------
=head2 incrementQuantity ( [ quantity ] )
Increments quantity of item by one. Returns the quantity of this item in the cart.
=head3 quantity
If specified may increment quantity by more than one. Specify a negative number to decrement quantity. If the quantity ever reaches 0 or lower, the item will be removed from the cart.
=cut
sub incrementQuantity {
my ($self, $quantity) = @_;
$quantity ||= 1;
$self->setQuantity($quantity + $self->get("quantity"));
return $self->get("quantity");
}
#-------------------------------------------------------------------

View file

@ -30,7 +30,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 16; # Increment this number for each test you create
plan tests => 19; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -42,17 +42,17 @@ isa_ok($cart->session, "WebGUI::Session");
my $root = WebGUI::Asset->getRoot($session);
my $product = $root->addChild({
className=>"WebGUI::Asset::Sku",
className=>"WebGUI::Asset::Sku::Donation",
title=>"Test Product",
});
$product->applyOptions({price=>50.25});
my $item = $cart->addItem($product);
isa_ok($item, "WebGUI::Shop::CartItem");
isa_ok($item->cart, "WebGUI::Shop::Cart", "Does the item have a cart?");
is(ref($item->get), "HASH", "Do we have a hash of properties?");
is($item->get("quantity"), 1, "Should have 1 of these in the cart.");
is($item->incrementQuantity(2), 3, "incrementQuantity() should tell us how many items of this type are in the cart");
is($item->adjustQuantity(2), 3, "adjustQuantity() should tell us how many items of this type are in the cart");
is($item->get("quantity"), 3, "Should have 3 of these in the cart.");
is(scalar(@{$cart->getItems}), 1, "Should have 1 item type in cart regardless of quanity.");
@ -64,12 +64,19 @@ like($cart->getId, qr/[A-Za-z0-9\_\-]{22}/, "Id looks like a guid.");
is(ref($cart->get), "HASH", "Cart properties are a hash reference.");
is($cart->get("sessionId"), $session->getId, "Can retrieve a value from the cart properties.");
is($cart->formatCurrency(11.1), "11.10", "can format currency");
is($cart->calculateSubtotal, 150.75, "can determine the price of the items in the cart");
$cart->update({shippingAddressId => "XXXX"});
is($cart->get("shippingAddressId"), "XXXX", "Can set values to the cart properties.");
isa_ok($cart->getAddressBook, "WebGUI::Shop::AddressBook", "can get an address book");
$cart->empty;
is($session->db->quickScalar("select count(*) from cartItem where cartId=?",[$cart->getId]), 0, "Items are removed from cart.");
$cart->delete;
is($cart->delete, undef, "Can destroy cart.");