Browse files

Added 2 new tests

1) Test amount of items in cart after removing an item that
   got caught by a hook.  I also expanded the error message
   from the hook to be a bit more specific.
2) Test the amount of items in the cart after removing an item
   without a hook.
  • Loading branch information...
1 parent 0e5de0c commit cd52d4b49eafa04a29ccf59ee2fcd6e8cad44c94 @rmtemplet committed Oct 4, 2011
Showing with 10 additions and 4 deletions.
  1. +10 −4 t/003_cart.t
View
14 t/003_cart.t
@@ -5,7 +5,7 @@
use strict;
use warnings;
-use Test::More tests => 22;
+use Test::More tests => 24;
use Nitesi::Cart;
@@ -57,12 +57,12 @@ ok(ref($ret) eq 'HASH', $cart->error);
$ret = $cart->items;
ok(@$ret == 2, "Items: $ret");
-# Cart removal tests
+# Cart removal
$cart = Nitesi::Cart->new(run_hooks => sub {
my ($hook, $cart, $item) = @_;
if ($hook eq 'before_cart_remove' && $item->{sku} eq '123') {
- $item->{error} = 'Test error';
+ $item->{error} = 'Item not removed due to hook.';
}
});
@@ -73,11 +73,17 @@ $item = {sku => '123', name => 'Foobar', price => 5};
$ret = $cart->add($item);
$ret = $cart->remove('123');
-ok($cart->error eq 'Test error', "Cart error: " . $cart->error);
+ok($cart->error eq 'Item not removed due to hook.', "Cart Error: " . $cart->error);
+
+$ret = $cart->items;
+ok(@$ret == 2, "Items: $ret");
$ret = $cart->remove('DEF');
ok(defined($ret), "Item DEF removed from cart.");
+$ret = $cart->items;
+ok(@$ret == 1, "Items: $ret");
+
#
# Calculating total
$cart->clear;

0 comments on commit cd52d4b

Please sign in to comment.