From 83e945142e24ec3ab230ca02662eecf4d6c46a19 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 8 Jun 2010 19:27:12 -0700 Subject: [PATCH] More END block cleanups. --- t/Asset/Event/edit.t | 12 +++------ t/Asset/File/GalleryFile/Photo/00base.t | 9 ++----- t/Asset/Sku/ProductCollateral.t | 14 +++------- t/Asset/Template/HTMLTemplateExpr.t | 35 +++++++++---------------- t/Asset/Wobject/Article.t | 5 ---- t/Asset/Wobject/Carousel.t | 8 ++---- t/Asset/Wobject/DataTable.t | 8 +----- t/Macro/GroupText.t | 6 ++--- t/Macro/SQL.t | 5 ++-- t/Session.t | 5 ++-- 10 files changed, 30 insertions(+), 77 deletions(-) diff --git a/t/Asset/Event/edit.t b/t/Asset/Event/edit.t index c44d6d81f..596e16c7b 100644 --- a/t/Asset/Event/edit.t +++ b/t/Asset/Event/edit.t @@ -62,6 +62,7 @@ my $calendar = $node->addChild( { my $eventUrl; $versionTags[-1]->commit; +WebGUI::Test->addToCleanup($versionTags[-1]); #---------------------------------------------------------------------------- # Tests @@ -167,15 +168,6 @@ $properties = { cmp_deeply( $event->get, superhashof( $properties ), 'Events properties saved correctly' ); -#---------------------------------------------------------------------------- -# Cleanup -END { - for my $tag ( @versionTags ) { - $tag->rollback; - } - -} - #---------------------------------------------------------------------------- # getMechLogin( baseUrl, WebGUI::User, "identifier" ) # Returns a Test::WWW::Mechanize session after logging in the given user using @@ -197,3 +189,5 @@ sub getMechLogin { return $mech; } + +#vim:ft=perl diff --git a/t/Asset/File/GalleryFile/Photo/00base.t b/t/Asset/File/GalleryFile/Photo/00base.t index 5fcb8b76e..7882ac88b 100644 --- a/t/Asset/File/GalleryFile/Photo/00base.t +++ b/t/Asset/File/GalleryFile/Photo/00base.t @@ -24,6 +24,7 @@ use Test::More; my $session = WebGUI::Test->session; my $node = WebGUI::Asset->getImportNode($session); my $versionTag = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->addToCleanup($versionTag); $versionTag->set({name=>"Photo Test"}); @@ -95,10 +96,4 @@ is( "Photo no longer able to be instanciated", ); -#---------------------------------------------------------------------------- -# Cleanup -END { - $versionTag->rollback; -} - - +#vim:ft=perl diff --git a/t/Asset/Sku/ProductCollateral.t b/t/Asset/Sku/ProductCollateral.t index 5ed86a964..44a181eb7 100644 --- a/t/Asset/Sku/ProductCollateral.t +++ b/t/Asset/Sku/ProductCollateral.t @@ -41,6 +41,8 @@ plan tests => 34; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here my $root = WebGUI::Asset->getRoot($session); +my $versionTag = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->addToCleanup($versionTag); my $product = $root->addChild({ className => "WebGUI::Asset::Sku::Product", title => "Rock Hammer", @@ -303,16 +305,8 @@ $newVid = $product6->setCollateral('variantsJSON', 'vid', 'new', { wideChar => q , vid => 'new' }); my $product6a = WebGUI::Asset->newByDynamicClass($session, $product6->getId); -lives_ok { $product6a->getAllCollateral('variantsJSON', 'vid', $newVid); }, 'Product collateral handles wide-character encodings okay'; +lives_ok { $product6a->getAllCollateral('variantsJSON', 'vid', $newVid); } 'Product collateral handles wide-character encodings okay'; $product6->purge; -#---------------------------------------------------------------------------- -# Cleanup -END { - - WebGUI::VersionTag->getWorking($session)->rollback; - -} - -1; +#vim:ft=perl diff --git a/t/Asset/Template/HTMLTemplateExpr.t b/t/Asset/Template/HTMLTemplateExpr.t index ad5c9ddd8..b8b31da3e 100644 --- a/t/Asset/Template/HTMLTemplateExpr.t +++ b/t/Asset/Template/HTMLTemplateExpr.t @@ -27,26 +27,22 @@ plan tests => 2 + $num_tests; my $session = WebGUI::Test->session; # put your tests here -my ($versionTag, $template); -my $originalParsers = $session->config->get('templateParsers'); +WebGUI::Test->originalConfig('templateParsers'); my $module = use_ok('HTML::Template::Expr'); +my $plugin = use_ok('WebGUI::Asset::Template::HTMLTemplateExpr'); + SKIP: { - skip "HTML::Template::Expr or plugin not loaded", $num_tests+1 unless $module; - my $plugin = use_ok('WebGUI::Asset::Template::HTMLTemplateExpr'); - - SKIP: { - skip "HTML::Template::Expr or plugin not loaded", $num_tests unless $plugin; - - $session->config->set('templateParsers', ['WebGUI::Asset::Template::HTMLTemplate', 'WebGUI::Asset::Template::HTMLTemplateExpr',] ); - ($versionTag, $template) = setup_assets($session); - my $templateOutput = $template->process({ "foo.bar" => "baz", "number.value" => 2 }); - my $companyName = $session->config->get('companyName'); - like($templateOutput, qr/NAME=$companyName/, "session variable with underscores"); - like($templateOutput, qr/FOOBAR=baz/, "explicit variable with dots"); - like($templateOutput, qr/EQN=4/, "explicit variable with dots in expr"); - } + skip "HTML::Template::Expr or plugin not loaded", $num_tests unless $plugin; + $session->config->set('templateParsers', ['WebGUI::Asset::Template::HTMLTemplate', 'WebGUI::Asset::Template::HTMLTemplateExpr',] ); + my ($versionTag, $template) = setup_assets($session); + WebGUI::Test->addToCleanup($versionTag); + my $templateOutput = $template->process({ "foo.bar" => "baz", "number.value" => 2 }); + my $companyName = $session->config->get('companyName'); + like($templateOutput, qr/NAME=$companyName/, "session variable with underscores"); + like($templateOutput, qr/FOOBAR=baz/, "explicit variable with dots"); + like($templateOutput, qr/EQN=4/, "explicit variable with dots in expr"); } sub setup_assets { @@ -67,10 +63,3 @@ sub setup_assets { $versionTag->commit; return ($versionTag, $template); } - -END { - $session->config->set('templateParsers', $originalParsers); - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } -} diff --git a/t/Asset/Wobject/Article.t b/t/Asset/Wobject/Article.t index 43dd38e6f..afaa24970 100644 --- a/t/Asset/Wobject/Article.t +++ b/t/Asset/Wobject/Article.t @@ -136,8 +136,3 @@ TODO: { ok(0, 'Test www_deleteFile method'); ok(0, 'Test www_view method... maybe?'); } - -END { - # Clean up after thy self -} - diff --git a/t/Asset/Wobject/Carousel.t b/t/Asset/Wobject/Carousel.t index bf78d0232..8eb9f96b2 100644 --- a/t/Asset/Wobject/Carousel.t +++ b/t/Asset/Wobject/Carousel.t @@ -26,6 +26,7 @@ my $node = WebGUI::Asset->getImportNode($session); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"Search Test"}); +WebGUI::Test->addToCleanup($versionTag); my $carousel = $node->addChild({className=>'WebGUI::Asset::Wobject::Carousel'}); # Test for a sane object type @@ -41,9 +42,4 @@ foreach my $newSetting (keys %{$newSettings}) { is ($carousel->get($newSetting), $newSettings->{$newSetting}, "updated $newSetting is ".$newSettings->{$newSetting}); } - -END { - # Clean up after thy self - $versionTag->rollback(); -} - +#vim:ft=perl diff --git a/t/Asset/Wobject/DataTable.t b/t/Asset/Wobject/DataTable.t index 4467db994..bf23b805b 100644 --- a/t/Asset/Wobject/DataTable.t +++ b/t/Asset/Wobject/DataTable.t @@ -27,8 +27,6 @@ use WebGUI::Session; my $session = WebGUI::Test->session; my $node = WebGUI::Asset->getImportNode( $session ); -my $dt; - #---------------------------------------------------------------------------- # Tests @@ -41,6 +39,7 @@ my $dt = $node->addChild( { className => 'WebGUI::Asset::Wobject::DataTable', } ); isa_ok( $dt, 'WebGUI::Asset::Wobject::DataTable' ); +WebGUI::Test->addToCleanup($dt); #---------------------------------------------------------------------------- # Value and variables @@ -138,9 +137,4 @@ cmp_deeply( "getTemplateVars returns complete and correct data structure", ); -#---------------------------------------------------------------------------- -# Cleanup -END { - $dt->purge; -} #vim:ft=perl diff --git a/t/Macro/GroupText.t b/t/Macro/GroupText.t index e09085017..f8c9595f9 100644 --- a/t/Macro/GroupText.t +++ b/t/Macro/GroupText.t @@ -50,6 +50,7 @@ is($output, 'Group Not a Group was not found', 'Non-existant group returns an er ##Create a small database $session->db->dbh->do('DROP TABLE IF EXISTS myUserTable'); $session->db->dbh->do(q!CREATE TABLE myUserTable (userId CHAR(22) binary NOT NULL default '', PRIMARY KEY(userId)) TYPE=InnoDB!); +WebGUI::Test->addToCleanup(SQL => 'DROP TABLE IF EXISTS myUserTable'); ##Create a bunch of users and put them in the table. @@ -116,7 +117,4 @@ $output = join ',', ; is($output, 'user,disti,int_disti', 'user is in all three groups'); -##clean up everything -END { - $session->db->dbh->do('DROP TABLE IF EXISTS myUserTable'); -} +#vim:ft=perl diff --git a/t/Macro/SQL.t b/t/Macro/SQL.t index 8644e55f5..b6b26b521 100644 --- a/t/Macro/SQL.t +++ b/t/Macro/SQL.t @@ -32,6 +32,7 @@ my $WebGUIdbLink = WebGUI::DatabaseLink->new($session, '0'); my $originalMacroAccessValue = $WebGUIdbLink->macroAccessIsAllowed(); $session->db->dbh->do('DROP TABLE IF EXISTS testTable'); +WebGUI::Test->addToCleanup(SQL => 'DROP TABLE testTable'); $session->db->dbh->do('CREATE TABLE testTable (zero int(8), one int(8), two int(8), three int(8), four int(8), five int(8), six int(8), seven int(8), eight int(8), nine int(8), ten int(8), eleven int(8) ) TYPE=InnoDB'); $session->db->dbh->do('INSERT INTO testTable (zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven ) VALUES(0,1,2,3,4,5,6,7,8,9,10,11)'); $session->db->dbh->do('INSERT INTO testTable (zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven ) VALUES(100,101,102,103,104,105,106,107,108,109,110,111)'); @@ -154,6 +155,4 @@ my $output = WebGUI::Macro::SQL::process( ); is($output, 'zero', 'alternate linkId works'); -END { - $session->db->dbh->do('DROP TABLE testTable'); -} +#vim:ft=perl diff --git a/t/Session.t b/t/Session.t index 32883162e..677284fdb 100644 --- a/t/Session.t +++ b/t/Session.t @@ -51,10 +51,9 @@ my $slaveHash2 = { }; $session->config->set('dbslave2', $slaveHash2); +WebGUI::Test->addToCleanup(sub {$session->config->delete('dbslave2');}); my $slave2 = $session->dbSlave; isa_ok($slave2, 'WebGUI::SQL'); -END { - $session->config->delete('dbslave2'); -} +#vim:ft=perl