From 1c20f132eb28c8198617597f2ff85af2fd0661a2 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 8 Nov 2009 22:55:57 -0800 Subject: [PATCH] 100% coverage on t/Macro/SQL.t. Refactor DatabaseLink. --- lib/WebGUI/DatabaseLink.pm | 9 ++++----- t/Macro/SQL.t | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/DatabaseLink.pm b/lib/WebGUI/DatabaseLink.pm index 562835ebc..8dffa550f 100644 --- a/lib/WebGUI/DatabaseLink.pm +++ b/lib/WebGUI/DatabaseLink.pm @@ -337,11 +337,10 @@ is reserved for the WebGUI database. =cut sub new { - my ($class, $databaseLinkId, %databaseLink); - tie %databaseLink, 'Tie::CPHash'; - $class = shift; - my $session = shift; - $databaseLinkId = shift; + my $class = shift; + my $session = shift; + my $databaseLinkId = shift; + tie my %databaseLink, 'Tie::CPHash'; unless ($databaseLinkId eq "") { if ($databaseLinkId eq "0") { %databaseLink = ( diff --git a/t/Macro/SQL.t b/t/Macro/SQL.t index 1e4219a62..8644e55f5 100644 --- a/t/Macro/SQL.t +++ b/t/Macro/SQL.t @@ -118,10 +118,10 @@ my @testSets = ( }, ); -my $numTests = scalar @testSets; - -++$numTests; ##For the allow macro access test; - +my $numTests = scalar @testSets + + 2 + ; + plan tests => $numTests; $WebGUIdbLink->set({allowMacroAccess=>0}); @@ -144,6 +144,15 @@ foreach my $testSet (@testSets) { # reset allowMacroAccess to original value $WebGUIdbLink->set({allowMacroAccess=>$originalMacroAccessValue}); +my $newLinkId = $WebGUIdbLink->copy; +addToCleanup(WebGUI::DatabaseLink->new($session, $newLinkId)); +my $output = WebGUI::Macro::SQL::process( + $session, + q{show columns from testTable like 'zero'}, + q{^0;}, + $newLinkId, +); +is($output, 'zero', 'alternate linkId works'); END { $session->db->dbh->do('DROP TABLE testTable');