Macro test maintenance, up through Page.t
This commit is contained in:
parent
3b11493744
commit
bd6677942c
4 changed files with 98 additions and 158 deletions
|
|
@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
|
|||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
use WebGUI::Macro::MiniCart;
|
||||
use JSON;
|
||||
use Data::Dumper;
|
||||
|
||||
|
|
@ -22,14 +23,7 @@ use Test::Deep;
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
my $numTests = 4;
|
||||
|
||||
$numTests += 1; #For the use_ok
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
my $macro = 'WebGUI::Macro::MiniCart';
|
||||
my $loaded = use_ok($macro);
|
||||
plan tests => 4;
|
||||
|
||||
my $cart = WebGUI::Shop::Cart->newBySession($session);
|
||||
my $donation = WebGUI::Asset->getRoot($session)->addChild({
|
||||
|
|
@ -40,105 +34,94 @@ my $donation = WebGUI::Asset->getRoot($session)->addChild({
|
|||
});
|
||||
|
||||
my $template = setupJSONtemplate($session);
|
||||
addToCleanup($cart, $donation, $template);
|
||||
|
||||
SKIP: {
|
||||
my $json;
|
||||
my $templateVars;
|
||||
|
||||
skip "Unable to load $macro", $numTests-1 unless $loaded;
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '0',
|
||||
totalItems => '0',
|
||||
items => [],
|
||||
},
|
||||
'Empty cart works'
|
||||
);
|
||||
|
||||
my $json;
|
||||
my $templateVars;
|
||||
my $item1 = $cart->addItem($donation);
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '10',
|
||||
totalItems => '1',
|
||||
items => [
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
|
||||
},
|
||||
],
|
||||
},
|
||||
'Cart with one item works'
|
||||
);
|
||||
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '0',
|
||||
totalItems => '0',
|
||||
items => [],
|
||||
},
|
||||
'Empty cart works'
|
||||
);
|
||||
my $item2 = $cart->addItem($donation);
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '20',
|
||||
totalItems => '2',
|
||||
items => bag(
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
|
||||
},
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
|
||||
},
|
||||
),
|
||||
},
|
||||
'Cart with two items works'
|
||||
);
|
||||
|
||||
my $item1 = $cart->addItem($donation);
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '10',
|
||||
totalItems => '1',
|
||||
items => [
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
|
||||
},
|
||||
],
|
||||
},
|
||||
'Cart with one item works'
|
||||
);
|
||||
|
||||
my $item2 = $cart->addItem($donation);
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '20',
|
||||
totalItems => '2',
|
||||
items => bag(
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
|
||||
},
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
|
||||
},
|
||||
),
|
||||
},
|
||||
'Cart with two items works'
|
||||
);
|
||||
|
||||
$item2->setQuantity(9);
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '100',
|
||||
totalItems => '10',
|
||||
items => bag(
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
|
||||
},
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 9,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
|
||||
},
|
||||
),
|
||||
},
|
||||
'Cart with two items and multiple quantities works'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
END {
|
||||
$cart->delete;
|
||||
$donation->purge;
|
||||
$template->purge;
|
||||
}
|
||||
$item2->setQuantity(9);
|
||||
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
|
||||
$templateVars = JSON::from_json($json);
|
||||
cmp_deeply(
|
||||
$templateVars,
|
||||
{
|
||||
totalPrice => '100',
|
||||
totalItems => '10',
|
||||
items => bag(
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 1,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId),
|
||||
},
|
||||
{
|
||||
name => $donation->getConfiguredTitle(),
|
||||
quantity => 9,
|
||||
price => 10,
|
||||
url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId),
|
||||
},
|
||||
),
|
||||
},
|
||||
'Cart with two items and multiple quantities works'
|
||||
);
|
||||
|
||||
sub setupJSONtemplate {
|
||||
my ($session) = @_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue