Add a creation date to the Cart.

Use that date to expire carts older than an interval, via a new workflow.
Config file changes, tests, i18n.
This commit is contained in:
Colin Kuskie 2009-04-02 21:58:45 +00:00
parent 6bd159bcfd
commit 60a3906b05
9 changed files with 299 additions and 5 deletions

View file

@ -33,7 +33,7 @@ my $i18n = WebGUI::International->new($session, "Shop");
#----------------------------------------------------------------------------
# Tests
plan tests => 27; # Increment this number for each test you create
plan tests => 29; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -52,6 +52,7 @@ my $cart = WebGUI::Shop::Cart->newBySession($session);
isa_ok($cart, "WebGUI::Shop::Cart");
isa_ok($cart->session, "WebGUI::Session");
ok($cart->get('creationDate'), 'creationDate set on cart creation');
my $message = $i18n->get('empty cart') . "\n";
like($cart->www_view, qr/There are no items currently in your cart./, 'Display empty cart message');
@ -73,9 +74,13 @@ 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.");
$item->update({shippingAddressId => "XXXX"});
is($item->get("shippingAddressId"), "XXXX", "Can set values to the cart item properties.");
is($item->get("shippingAddressId"), "XXXX", "Can set shippingAddressId in the cart item properties.");
$item->update({shippingAddressId => undef});
my $now = time();
$cart->update({creationDate => $now});
is($cart->get('creationDate'), $now, 'update: set creationDate');
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.");

View file

@ -0,0 +1,110 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Utility;
use WebGUI::Workflow::Activity::RemoveOldCarts;
use WebGUI::Shop::Cart;
use Test::More;
use Test::Deep;
plan tests => 6; # increment this value for each test you create
my $session = WebGUI::Test->session;
my $root = WebGUI::Asset->getRoot($session);
my $donation = $root->addChild({
className => 'WebGUI::Asset::Sku::Donation',
title => 'test donation',
});
my $tag = WebGUI::VersionTag->getWorking($session);
$tag->commit;
my $cart1 = WebGUI::Shop::Cart->create($session);
my $session2 = WebGUI::Session->open(WebGUI::Test->root, WebGUI::Test->file);
my $cart2 = WebGUI::Shop::Cart->create($session2);
$cart2->update({creationDate => time()-10000});
my @cartIds = $session->db->buildArray('select cartId from cart');
cmp_bag(
\@cartIds,
[ $cart1->getId, $cart2->getId ],
'Made two carts for testing'
);
$donation->applyOptions({ price => 1111});
my $item1 = $cart1->addItem($donation);
$donation->applyOptions({ price => 2222});
my $item2 = $cart2->addItem($donation);
my @itemIds = $session->db->buildArray('select itemId from cartItem');
cmp_bag(
\@itemIds,
[ $item1->getId, $item2->getId ],
'Made two items for testing'
);
my $workflow = WebGUI::Workflow->create($session,
{
enabled => 1,
objectType => 'None',
mode => 'realtime',
},
);
my $cartNuker = $workflow->addActivity('WebGUI::Workflow::Activity::RemoveOldCarts');
$cartNuker->set('cartTimeout', 3600);
my $instance1 = WebGUI::Workflow::Instance->create($session,
{
workflowId => $workflow->getId,
skipSpectreNotification => 1,
}
);
my $retVal;
$retVal = $instance1->run();
is($retVal, 'complete', 'cleanup: activity complete');
$retVal = $instance1->run();
is($retVal, 'done', 'cleanup: activity is done');
$instance1->delete;
@cartIds = $session->db->buildArray('select cartId from cart');
cmp_bag(
\@cartIds,
[ $cart1->getId, ],
'Deleted 1 cart, the correct one'
);
@itemIds = $session->db->buildArray('select itemId from cartItem');
cmp_bag(
\@itemIds,
[ $item1->getId, ],
'Deleted 1 item, the correct one'
);
END {
$instance1->delete('skipNotify');
$workflow->delete;
$cart1->delete;
$cart2->delete;
$session2->close;
$donation->purge;
$tag->rollback;
}