202 lines
8.4 KiB
Perl
202 lines
8.4 KiB
Perl
# 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
|
|
#------------------------------------------------------------------
|
|
|
|
# Tests the transaction backend for the shop.
|
|
#
|
|
#
|
|
|
|
use FindBin;
|
|
use strict;
|
|
use lib "$FindBin::Bin/../lib";
|
|
use Test::More;
|
|
use Test::Deep;
|
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
|
use WebGUI::Session;
|
|
use WebGUI::Shop::Transaction;
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Init
|
|
my $session = WebGUI::Test->session;
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Tests
|
|
|
|
plan tests => 64; # Increment this number for each test you create
|
|
|
|
#----------------------------------------------------------------------------
|
|
# put your tests here
|
|
|
|
my $transaction = WebGUI::Shop::Transaction->create($session,{
|
|
amount => 40,
|
|
shippingAddressId => 'xxx1',
|
|
shippingAddressName => 'abc',
|
|
shippingAddress1 => 'def',
|
|
shippingAddress2 => 'hij',
|
|
shippingAddress3 => 'lmn',
|
|
shippingCity => 'opq',
|
|
shippingState => 'wxy',
|
|
shippingCountry => 'z',
|
|
shippingCode => '53333',
|
|
shippingPhoneNumber => '123456',
|
|
shippingDriverId => 'xxx2',
|
|
shippingDriverLabel => 'foo',
|
|
shippingPrice => 5,
|
|
paymentAddressId => 'xxx3',
|
|
paymentAddressName => 'abc1',
|
|
paymentAddress1 => 'def1',
|
|
paymentAddress2 => 'hij1',
|
|
paymentAddress3 => 'lmn1',
|
|
paymentCity => 'opq1',
|
|
paymentState => 'wxy1',
|
|
paymentCountry => 'z1',
|
|
paymentCode => '66666',
|
|
paymentPhoneNumber => '908765',
|
|
paymentDriverId => 'xxx4',
|
|
paymentDriverLabel => 'kkk',
|
|
couponId => 'xxx5',
|
|
couponTitle => 'title1',
|
|
couponDiscount => -5,
|
|
taxes => 7,
|
|
});
|
|
|
|
# objects work
|
|
isa_ok($transaction, "WebGUI::Shop::Transaction");
|
|
isa_ok($transaction->session, "WebGUI::Session");
|
|
|
|
|
|
# basic transaction properties
|
|
is($transaction->get("amount"), 40, "set and get amount");
|
|
is($transaction->get("shippingAddressId"), 'xxx1', "set and get shipping address id");
|
|
is($transaction->get("shippingAddressName"), 'abc', "set and get shipping address name");
|
|
is($transaction->get("shippingAddress1"), 'def', "set and get shipping address 1");
|
|
is($transaction->get("shippingAddress2"), 'hij', "set and get shipping address 2");
|
|
is($transaction->get("shippingAddress3"), 'lmn', "set and get shipping address 3");
|
|
is($transaction->get("shippingCity"), 'opq', "set and get shipping city");
|
|
is($transaction->get("shippingState"), 'wxy', "set and get shipping state");
|
|
is($transaction->get("shippingCountry"), 'z', "set and get shipping country");
|
|
is($transaction->get("shippingCode"), '53333', "set and get shipping code");
|
|
is($transaction->get("shippingPhoneNumber"), '123456', "set and get shipping phone number");
|
|
is($transaction->get("shippingDriverId"), 'xxx2', "set and get shipping driver id");
|
|
is($transaction->get("shippingDriverLabel"), 'foo', "set and get shipping driver label");
|
|
is($transaction->get("shippingPrice"), 5, "set and get shipping price");
|
|
is($transaction->get("paymentAddressId"), 'xxx3', "set and get payment address id");
|
|
is($transaction->get("paymentAddressName"), 'abc1', "set and get payment address name");
|
|
is($transaction->get("paymentAddress1"), 'def1', "set and get payment address 1");
|
|
is($transaction->get("paymentAddress2"), 'hij1', "set and get payment address 2");
|
|
is($transaction->get("paymentAddress3"), 'lmn1', "set and get payment address 3");
|
|
is($transaction->get("paymentCity"), 'opq1', "set and get payment city");
|
|
is($transaction->get("paymentState"), 'wxy1', "set and get payment state");
|
|
is($transaction->get("paymentCountry"), 'z1', "set and get payment country");
|
|
is($transaction->get("paymentCode"), '66666', "set and get payment code");
|
|
is($transaction->get("paymentPhoneNumber"), '908765', "set and get payment phone number");
|
|
is($transaction->get("paymentDriverId"), 'xxx4', "set and get payment driver id");
|
|
is($transaction->get("paymentDriverLabel"), 'kkk', "set and get payment driver label");
|
|
is($transaction->get("couponId"), 'xxx5', "set and get coupon id");
|
|
is($transaction->get("couponTitle"), 'title1', "set and get coupon title");
|
|
is($transaction->get("couponDiscount"), -5, "set and get coupon discount");
|
|
is($transaction->get("taxes"), 7, "set and get taxes");
|
|
|
|
|
|
$transaction->update({
|
|
isSuccessful => 1,
|
|
transactionCode => 'yyy',
|
|
statusCode => 'jd31',
|
|
statusMessage => 'was a success',
|
|
});
|
|
|
|
is($transaction->get("isSuccessful"), 1,"update and get isSuccessful");
|
|
is($transaction->get("transactionCode"), 'yyy',"update and get transaction code");
|
|
is($transaction->get("statusCode"), 'jd31',"update and get status code");
|
|
is($transaction->get("statusMessage"), 'was a success',"update and get status message");
|
|
|
|
# make sure new() works
|
|
my $tcopy = WebGUI::Shop::Transaction->new($session, $transaction->getId);
|
|
|
|
isa_ok($tcopy, "WebGUI::Shop::Transaction");
|
|
is($tcopy->getId, $transaction->getId, "is it the same object");
|
|
|
|
|
|
# basic item properties
|
|
my $item = $transaction->addItem({
|
|
assetId => 'a',
|
|
configuredTitle => 'b',
|
|
options => {color=>'blue'},
|
|
shippingAddressId => 'c',
|
|
shippingName => 'd',
|
|
shippingAddress1 => 'e',
|
|
shippingAddress2 => 'f',
|
|
shippingAddress3 => 'g',
|
|
shippingCity => 'h',
|
|
shippingState => 'i',
|
|
shippingCountry => 'j',
|
|
shippingCode => 'k',
|
|
shippingPhoneNumber => 'l',
|
|
quantity => 5,
|
|
price => 33,
|
|
});
|
|
|
|
isa_ok($item, "WebGUI::Shop::TransactionItem");
|
|
isa_ok($item->transaction, "WebGUI::Shop::Transaction");
|
|
|
|
is($item->get("assetId"), 'a', "set and get asset id");
|
|
is($item->get("configuredTitle"), 'b', "set and get configured title");
|
|
cmp_deeply($item->get("options"), {color=>'blue'}, "set and get options");
|
|
is($item->get("shippingAddressId"), 'c', "set and get shipping address id");
|
|
is($item->get("shippingName"), 'd', "set and get shipping name");
|
|
is($item->get("shippingAddress1"), 'e', "set and get shipping address 1");
|
|
is($item->get("shippingAddress2"), 'f', "set and get shipping address 2");
|
|
is($item->get("shippingAddress3"), 'g', "set and get shipping address 3");
|
|
is($item->get("shippingCity"), 'h', "set and get shipping city");
|
|
is($item->get("shippingState"), 'i', "set and get shipping state");
|
|
is($item->get("shippingCountry"), 'j', "set and get shipping country");
|
|
is($item->get("shippingCode"), 'k', "set and get shipping code");
|
|
is($item->get("shippingPhoneNumber"), 'l', "set and get shipping phone number");
|
|
is($item->get("quantity"), 5, "set and get quantity");
|
|
is($item->get("price"), 33, "set and get price");
|
|
|
|
$item->update({
|
|
shippingTrackingNumber => 'adfs',
|
|
shippingStatus => 'BackOrdered',
|
|
});
|
|
|
|
is($item->get("shippingTrackingNumber"), 'adfs', "update and get shipping tracking number");
|
|
is($item->get("shippingStatus"), 'BackOrdered', "update and get shipping status");
|
|
|
|
# make sure shipping date is updated when shipping status is changed
|
|
like($item->get("shippingDate"), qr/\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/, "shipping date is set");
|
|
my $dateNow = $item->get('shippingDate');
|
|
sleep(1);
|
|
$item->update({shippingStatus=>'Cancelled'});
|
|
isnt($item->get('shippingDate'), $dateNow, 'shipping date is updated');
|
|
|
|
# make sure new() works
|
|
my $icopy = $transaction->getItem($item->getId);
|
|
isa_ok($icopy, "WebGUI::Shop::TransactionItem");
|
|
is($icopy->getId, $item->getId, "items are the same");
|
|
|
|
# get itmes
|
|
is(scalar @{$transaction->getItems}, 1, "can retrieve items");
|
|
|
|
# delete
|
|
$item->delete;
|
|
is(scalar @{$transaction->getItems}, 0, "can delete items");
|
|
|
|
$transaction->delete;
|
|
is($session->db->quickScalar("select transactionId from transaction where transactionId=?",[$transaction->getId]), undef, "can delete transactions");
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Cleanup
|
|
END {
|
|
|
|
}
|