started cart tests, realizing need to build sku first
This commit is contained in:
parent
70b8331794
commit
649d34f1a7
3 changed files with 88 additions and 9 deletions
|
|
@ -25,16 +25,32 @@ my $session = start(); # this line required
|
|||
# upgrade functions go here
|
||||
|
||||
insertCommerceTaxTable($session);
|
||||
migrateToNewCart($session);
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
||||
##-------------------------------------------------
|
||||
#sub exampleFunction {
|
||||
# my $session = shift;
|
||||
# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet);
|
||||
# # and here's our code
|
||||
#}
|
||||
#-------------------------------------------------
|
||||
sub migrateToNewCart {
|
||||
my $session = shift;
|
||||
print "\tInstall new shopping cart.\n" unless ($quiet);
|
||||
$session->db->write("create table cart (
|
||||
cartId varchar(22) binary not null primary key,
|
||||
sessionId varchar(22) binary not null,
|
||||
shippingAddressId varchar(22) binary,
|
||||
couponId varchar(22) binary,
|
||||
index sessionId (sessionId)
|
||||
)");
|
||||
$session->db->write("create table cartItems (
|
||||
cartId varchar(22) binary not null,
|
||||
assetId varchar(22) binary not null,
|
||||
options mediumtext,
|
||||
shippingAddressId varchar(22) binary,
|
||||
quantity integer not null default 1,
|
||||
index cartId_assetId (cartId,assetId)
|
||||
)");
|
||||
$session->db->write("drop table shoppingCart");
|
||||
}
|
||||
|
||||
#-------------------------------------------------
|
||||
sub insertCommerceTaxTable {
|
||||
|
|
@ -44,7 +60,7 @@ sub insertCommerceTaxTable {
|
|||
$session->db->write(<<EOSQL);
|
||||
|
||||
CREATE TABLE tax (
|
||||
taxId VARCHAR(22) NOT NULL,
|
||||
taxId VARCHAR(22) binary NOT NULL,
|
||||
field VARCHAR(100) NOT NULL,
|
||||
value VARCHAR(100) DEFAULT 0.0,
|
||||
taxRate FLOAT NOT NULL,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ use lib "$FindBin::Bin/../lib";
|
|||
use Test::More;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Shop::Cart;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -55,11 +56,13 @@ is($cart->get("sessionId"), $session->getId, "Can retrieve a value from the cart
|
|||
$cart->set({shippingAddressId => "XXXX"});
|
||||
is($cart->get("shippingAddressId"), "XXXX", "Can set values to the cart properties.");
|
||||
|
||||
my $id = $cart->getId;
|
||||
$cart->empty;
|
||||
is($session->db->quickScalar("select count(*) from cartItems where cartId=?",[$cart->getId]), 0, "Items are removed from cart.");
|
||||
|
||||
$cart->delete;
|
||||
is($cart, undef, "Can destroy cart.");
|
||||
is($session->db->quickScalar("select count(*) from cartItems where cartId=?",[$id]), 0, "Items are also removed from cart.");
|
||||
|
||||
$product->purge;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
|
|
|
|||
60
t/Shop/CartItem.t
Normal file
60
t/Shop/CartItem.t
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2008 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Write a little about what this script tests.
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Asset;
|
||||
use WebGUI::Shop::CartItem;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
plan tests => 5; # Increment this number for each test you create
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# put your tests here
|
||||
|
||||
my $root = WebGUI::Asset->getRoot($session);
|
||||
my $product = $root->addChild($session, {
|
||||
className=>"WebGUI::Asset::Sku::Product",
|
||||
title=>"Test Product",
|
||||
price=>4.99
|
||||
});
|
||||
|
||||
my $item = WebGUI::Shop::CartItem->create($session, "XXX", $product, 2);
|
||||
isa_ok($item, "WebGUI::Shop::CartItem");
|
||||
isa_ok($item->session, "WebGUI::Session", "did we get a session");
|
||||
|
||||
is(ref($item->get), "HASH", "Do we have a hash of properties?");
|
||||
is($item->get("quantity"), 2, "Should have 2 of these in the cart.");
|
||||
is($item->delete, undef, "actually deletes the item");
|
||||
|
||||
|
||||
$product->purge;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue