diff --git a/t/Macro/PageTitle.t b/t/Macro/PageTitle.t
index 55cdcc48b..9a39de7a9 100644
--- a/t/Macro/PageTitle.t
+++ b/t/Macro/PageTitle.t
@@ -16,11 +16,12 @@ use WebGUI::Test;
use WebGUI::Session;
use Data::Dumper;
-use Test::More; # increment this value for each test you create
+use Test::More;
+use Test::MockObject;
my $session = WebGUI::Test->session;
-my $numTests = 3;
+my $numTests = 7;
$numTests += 1; #For the use_ok
plan tests => $numTests;
@@ -65,7 +66,6 @@ $session->asset($snippet);
my $macroOutput = WebGUI::Macro::PageTitle::process($session);
is($macroOutput, $snippet->get('title'), "testing title returned from localy created asset with known title");
-}
my $origSessionRequest = $session->{_request};
@@ -75,14 +75,37 @@ my $request = Test::MockObject->new;
$request->mock('body',
sub {
my ($self, $value) = @_;
- return 1 if $operation;
- return 1 if $function;
+ return 1 if $operation and ($value eq "op");
+ return 1 if $function and ($value eq "func");
return 0;
}
);
+$session->{_request} = $request;
+
$output = WebGUI::Macro::PageTitle::process($session);
-is($output, $homeAsset->get('title'), 'fetching title for site default asset');
+is($output, $session->asset->get('title'), 'fetching title for session asset, no func or op');
+
+my $urlizedTitle = sprintf q!%s!,
+ $session->asset->getUrl,
+ $session->asset->get('title');
+
+$operation = 1;
+$function = 0;
+$output = WebGUI::Macro::PageTitle::process($session);
+is($output, $urlizedTitle, 'fetching urlized title via an operation');
+
+$operation = 0;
+$function = 1;
+$output = WebGUI::Macro::PageTitle::process($session);
+is($output, $urlizedTitle, 'fetching urlized title via a function');
+
+$operation = 1;
+$function = 1;
+$output = WebGUI::Macro::PageTitle::process($session);
+is($output, $urlizedTitle, 'fetching urlized title via an operation and function');
+
+}
END {
$versionTag->rollback;
diff --git a/t/Macro/SQL.t b/t/Macro/SQL.t
index 92fbb3aa2..0d75c2ed4 100644
--- a/t/Macro/SQL.t
+++ b/t/Macro/SQL.t
@@ -14,8 +14,8 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::Slash_gatewayUrl;
-use WebGUI::Macro::SQL;
use WebGUI::Session;
+use WebGUI::International;
use Data::Dumper;
use Test::More; # increment this value for each test you create
@@ -24,6 +24,8 @@ my $session = WebGUI::Test->session;
my $url = WebGUI::Macro::Slash_gatewayUrl::process($session);
+my $i18n = WebGUI::International->new($session, 'Macro_SQL');
+
$session->db->dbh->do('DROP TABLE IF EXISTS 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)');
@@ -48,6 +50,12 @@ my @testSets = (
template => qq!^1;
!,
output => join '', map {sprintf "%s
", @{ $_ }} ([$url, 3,'Admin'],[$url, 1,'Visitor']),
},
+ {
+ comment => q!Null template returns ^0;!,
+ sql => q!select count(*) from users!,
+ template => q!!,
+ output => q!2!,
+ },
{
comment => q!test two digit macros!,
sql => q!select * from testTable order by one!,
@@ -58,13 +66,25 @@ my @testSets = (
comment => q!Test illegal SQL, update!,
sql => q!update testTable set one=201 where one=101!,
template => '^0;',
- output => 'Cannot execute this type of query.',
+ output => $i18n->get('illegal query'),
},
{
comment => q!Test illegal SQL, update!,
sql => q!INSERT INTO testTable (zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven ) VALUES(200,201,202,203,204,205,206,207,208,209,210,211)!,
template => '^0;',
- output => 'Cannot execute this type of query.',
+ output => $i18n->get('illegal query'),
+ },
+ {
+ comment => q!Test valid SQL, show!,
+ sql => q!show columns from testTable like 'zero'!,
+ template => '^0;',
+ output => 'zero',
+ },
+ {
+ comment => q!Test valid SQL, describe!,
+ sql => q!DESCRIBE testTable 'one'!,
+ template => '^0;',
+ output => 'one',
},
{
comment => q!Test unused macro variables!,
@@ -78,15 +98,35 @@ my @testSets = (
template => join(':', map { "^$_;" } 'rownum', 0..3).',',
output => '1:0:1:2:3,2:100:101:102:103,',
},
+ {
+ comment => q!SQL error!,
+ sql => q!select ** from testTable order by one!,
+ template => join(':', map { "^$_;" } 'rownum', 0..3).',',
+ output => sprintf $i18n->get('sql error'),
+ q!You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* from testTable order by one' at line 1!,
+ },
);
my $numTests = scalar @testSets;
+++$numTests; ##For the load check;
+
plan tests => $numTests;
+my $macro = 'WebGUI::Macro::SQL';
+my $loaded = use_ok($macro);
+
+SKIP: {
+
+skip "Unable to load $macro", $numTests-1 unless $loaded;
+
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::SQL::process($session, $testSet->{sql}, $testSet->{template});
is($output, $testSet->{output}, $testSet->{comment});
}
-$session->db->dbh->do('DROP TABLE testTable');
+}
+
+END {
+ $session->db->dbh->do('DROP TABLE testTable');
+}