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

View file

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

View file

@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test; use WebGUI::Test;
use WebGUI::Session; use WebGUI::Session;
use WebGUI::Macro::MiniCart;
use JSON; use JSON;
use Data::Dumper; use Data::Dumper;
@ -22,14 +23,7 @@ use Test::Deep;
my $session = WebGUI::Test->session; my $session = WebGUI::Test->session;
my $numTests = 4; plan tests => 4;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::MiniCart';
my $loaded = use_ok($macro);
my $cart = WebGUI::Shop::Cart->newBySession($session); my $cart = WebGUI::Shop::Cart->newBySession($session);
my $donation = WebGUI::Asset->getRoot($session)->addChild({ my $donation = WebGUI::Asset->getRoot($session)->addChild({
@ -40,17 +34,14 @@ my $donation = WebGUI::Asset->getRoot($session)->addChild({
}); });
my $template = setupJSONtemplate($session); 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);
my $json; cmp_deeply(
my $templateVars;
$json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json);
cmp_deeply(
$templateVars, $templateVars,
{ {
totalPrice => '0', totalPrice => '0',
@ -58,12 +49,12 @@ skip "Unable to load $macro", $numTests-1 unless $loaded;
items => [], items => [],
}, },
'Empty cart works' 'Empty cart works'
); );
my $item1 = $cart->addItem($donation); my $item1 = $cart->addItem($donation);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId); $json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json); $templateVars = JSON::from_json($json);
cmp_deeply( cmp_deeply(
$templateVars, $templateVars,
{ {
totalPrice => '10', totalPrice => '10',
@ -78,12 +69,12 @@ skip "Unable to load $macro", $numTests-1 unless $loaded;
], ],
}, },
'Cart with one item works' 'Cart with one item works'
); );
my $item2 = $cart->addItem($donation); my $item2 = $cart->addItem($donation);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId); $json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json); $templateVars = JSON::from_json($json);
cmp_deeply( cmp_deeply(
$templateVars, $templateVars,
{ {
totalPrice => '20', totalPrice => '20',
@ -104,12 +95,12 @@ skip "Unable to load $macro", $numTests-1 unless $loaded;
), ),
}, },
'Cart with two items works' 'Cart with two items works'
); );
$item2->setQuantity(9); $item2->setQuantity(9);
$json = WebGUI::Macro::MiniCart::process($session, $template->getId); $json = WebGUI::Macro::MiniCart::process($session, $template->getId);
$templateVars = JSON::from_json($json); $templateVars = JSON::from_json($json);
cmp_deeply( cmp_deeply(
$templateVars, $templateVars,
{ {
totalPrice => '100', totalPrice => '100',
@ -130,15 +121,7 @@ skip "Unable to load $macro", $numTests-1 unless $loaded;
), ),
}, },
'Cart with two items and multiple quantities works' 'Cart with two items and multiple quantities works'
); );
}
END {
$cart->delete;
$donation->purge;
$template->purge;
}
sub setupJSONtemplate { sub setupJSONtemplate {
my ($session) = @_; my ($session) = @_;

View file

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