Macro test maintenance, up through Page.t

This commit is contained in:
Colin Kuskie 2009-10-31 15:53:10 -07:00
parent 3b11493744
commit bd6677942c
4 changed files with 98 additions and 158 deletions

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::L_loginBox;
use HTML::TokeParser;
use Test::More; # increment this value for each test you create
@ -22,7 +23,7 @@ my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
$session->asset($homeAsset);
my ($versionTag, $template) = setupTest($session, $homeAsset);
my $template = setupTest($session, $homeAsset);
$session->user({userId=>1});
##Replace the original ENV hash with one that will return a
@ -37,17 +38,7 @@ $session->{_env}->{_env} = \%newEnvHash;
my $i18n = WebGUI::International->new($session,'Macro_L_loginBox');
my $numTests = 1; #Module loading test
$numTests += 30; #Static tests
plan tests => $numTests;
my $macro = 'WebGUI::Macro::L_loginBox';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
plan tests => 30;
my $output = WebGUI::Macro::L_loginBox::process($session,'','',$template->getId);
my %vars = simpleTextParser($output);
@ -170,8 +161,6 @@ $output = WebGUI::Macro::L_loginBox::process($session,'','','');
my $passwordLabel = $i18n->get(51, 'WebGUI');
like($output, qr/$passwordLabel/, 'default template works');
}
sub simpleTextParser {
my ($text) = @_;
@ -236,11 +225,6 @@ sub setupTest {
#$properties->{template} .= "\n";
my $template = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
return ($versionTag, $template);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
addToCleanup($versionTag);
return $template;
}

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::LoginToggle;
use HTML::TokeParser;
use Data::Dumper;
@ -23,7 +24,7 @@ my $session = WebGUI::Test->session;
my $homeAsset = WebGUI::Asset->getDefault($session);
$session->asset($homeAsset);
my ($versionTag, $template) = setupTest($session, $homeAsset);
my $template = setupTest($session, $homeAsset);
my $i18n = WebGUI::International->new($session,'Macro_LoginToggle');
@ -131,16 +132,8 @@ foreach my $testSet (@testSets) {
$numTests += 1 + (ref $testSet->{parser} eq 'CODE');
}
$numTests += 1; #for the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::LoginToggle';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->user({userId=>$testSet->{userId}});
if ($testSet->{userId} eq '1') {
@ -163,8 +156,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub simpleHTMLParser {
my ($text) = @_;
my $p = HTML::TokeParser->new(\$text);
@ -205,11 +196,6 @@ sub setupTest {
};
my $template = $defaultNode->addChild($properties, $properties->{id});
$versionTag->commit;
return ($versionTag, $template);
}
END { ##Clean-up after yourself, always
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
$versionTag->rollback;
}
addToCleanup($versionTag);
return ($template);
}

View file

@ -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) = @_;

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Macro::Page;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@ -46,22 +47,13 @@ foreach my $testSet (@testSets) {
$numTests += scalar keys %{ $testSet };
}
$numTests += 1; #For the use_ok
$numTests += 1; #For macro call with undefined session asset
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Page';
my $loaded = use_ok($macro);
my $homeAsset = WebGUI::Asset->getDefault($session);
my $versionTag;
($versionTag, @testSets) = setupTest($session, $homeAsset, @testSets);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
@testSets = setupTest($session, $homeAsset, @testSets);
is(
WebGUI::Macro::Page::process($session,'url'),
@ -80,8 +72,6 @@ foreach my $testSet (@testSets) {
}
}
}
sub setupTest {
my ($session, $homeAsset, @testSets) = @_;
my $versionTag = WebGUI::VersionTag->getWorking($session);
@ -92,9 +82,6 @@ sub setupTest {
$testSet->{asset} = $asset;
}
$versionTag->commit;
return $versionTag, @testSets;
}
END { ##Clean-up after yourself, always
$versionTag->rollback;
addToCleanup($versionTag);
return @testSets;
}