From d27b3c24b626bb0adbf52df1df5c8f41757d276f Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 2 Jul 2006 02:19:58 +0000 Subject: [PATCH] test for examples from SQL macro docs --- t/Macro/SQL.t | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 t/Macro/SQL.t diff --git a/t/Macro/SQL.t b/t/Macro/SQL.t new file mode 100644 index 000000000..10007a9f0 --- /dev/null +++ b/t/Macro/SQL.t @@ -0,0 +1,67 @@ +#------------------------------------------------------------------- +# WebGUI is Copyright 2001-2006 Plain Black Corporation. +#------------------------------------------------------------------- +# Please read the legal notices (docs/legal.txt) and the license +# (docs/license.txt) that came with this distribution before using +# this software. +#------------------------------------------------------------------- +# http://www.plainblack.com info@plainblack.com +#------------------------------------------------------------------- + +use FindBin; +use strict; +use lib "$FindBin::Bin/../lib"; + +use WebGUI::Test; +use WebGUI::Macro; +use WebGUI::Session; +use WebGUI::Macro_Config; +use Data::Dumper; + +use Test::More; # increment this value for each test you create + +my $session = WebGUI::Test->session; + +unless ($session->config->get('macros')->{'SQL'}) { + Macro_Config::insert_macro($session, 'SQL', 'SQL'); +} + +unless ($session->config->get('macros')->{'/'}) { + Macro_Config::insert_macro($session, '/', 'Slash_gatewayUrl'); +} + + +my $macroText = '^SQL("%s","%s");'; + +my $url = "^/;"; + +WebGUI::Macro::process($session, \$url); + +my @testSets = ( + { ##first example from docs + sql => q!select count(*) from users!, + template => q!There are ^0; users!, + output => q!There are 2 users!, + }, + { ##pretest for second example + sql => q!select userId,username from users order by username!, + template => q!^0;:^1;-!, + output => q!3:Admin-1:Visitor-!, + }, + { ##second example from docs + sql => q!select userId,username from users order by username!, + template => q!^1;
!, + output => join '', map {sprintf "%s
", @{ $_ }} ([$url, 3,'Admin'],[$url, 1,'Visitor']), + }, +); + +my $numTests = scalar @testSets; + +plan tests => $numTests; + +foreach my $testSet (@testSets) { + my $output = sprintf $macroText, $testSet->{sql}, $testSet->{template}; + my $macro = $output; + WebGUI::Macro::process($session, \$output); + is($output, $testSet->{output}, 'testing '.$macro); +}