From 76ef4da7803adb1cf660abe479b92dcad500ba2b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Tue, 17 Jan 2006 17:55:02 +0000 Subject: [PATCH] finish up basic Date macro test --- t/Macro/At_username.t | 60 +++++++++++++++++++++++++ t/Macro/SettingMacros.t | 99 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 t/Macro/At_username.t create mode 100644 t/Macro/SettingMacros.t diff --git a/t/Macro/At_username.t b/t/Macro/At_username.t new file mode 100644 index 000000000..1a9e8a6aa --- /dev/null +++ b/t/Macro/At_username.t @@ -0,0 +1,60 @@ +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------- + +# ---- BEGIN DO NOT EDIT ---- +use strict; +use lib '../../lib'; +use Getopt::Long; +use WebGUI::Macro; +use WebGUI::Session; +use Data::Dumper; +# ---- END DO NOT EDIT ---- + +my $session = initialize(); # this line is required + +use Test::More; # increment this value for each test you create + +my $numTests = 2; + +plan tests => $numTests; + +diag("Planning on running $numTests tests\n"); + +my $macroText = "^@;"; +my $output; + +$output = $macroText; +WebGUI::Macro::process($session, \$output); +is($output, 'Visitor', 'username = Visitor'); + +$output = $macroText; +$session->user({userId => 3}); +WebGUI::Macro::process($session, \$output); +is($output, 'Admin', 'username = Admin'); + +cleanup($session); # this line is required + +# ---- DO NOT EDIT BELOW THIS LINE ----- + +sub initialize { + $|=1; # disable output buffering + my $configFile; + GetOptions( + 'configFile=s'=>\$configFile + ); + exit 1 unless ($configFile); + my $session = WebGUI::Session->open("../..",$configFile); +} + +sub cleanup { + my $session = shift; + $session->close(); +} + diff --git a/t/Macro/SettingMacros.t b/t/Macro/SettingMacros.t new file mode 100644 index 000000000..9dae57657 --- /dev/null +++ b/t/Macro/SettingMacros.t @@ -0,0 +1,99 @@ +#------------------------------------------------------------------- +# 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 +#------------------------------------------------------------------- + +# ---- BEGIN DO NOT EDIT ---- +use strict; +use lib '../../lib'; +use Getopt::Long; +use WebGUI::Macro; +use WebGUI::Session; +use Data::Dumper; +# ---- END DO NOT EDIT ---- + +my $session = initialize(); # this line is required + +#This test is to verify bugs with respect to Macros: +# - [ 1364838 ] ^GroupText Macro cannot execute other macros +# +# It also checks some macros which pull data out of the setting table. + +my @settingMacros = ( + { + settingKey => 'companyEmail', + macro => 'e_companyEmail' + }, + { + settingKey => 'companyName', + macro => 'c_companyName' + }, + { + settingKey => 'companyURL', + macro => 'u_companyUrl' + }, +); + +##Build a reverse hash of the macro settings in the session var so that +##we can lookup the aliases for each macro. + +my %macroNames = reverse %{ $session->config->get('macros') }; + +my $settingMacros = 0; + +foreach my $macro ( @settingMacros ) { + ++$settingMacros; + if (exists $macroNames{ $macro->{macro} }) { + $macro->{shortcut} = $macroNames{ $macro->{macro} }; + $macro->{skip} = 0; + } + else { + $macro->{skip} = 1; + } +} + +use Test::More; # increment this value for each test you create + +my $numTests = $settingMacros; + +plan tests => $numTests; + +diag("Planning on running $numTests tests\n"); + +foreach my $macro ( @settingMacros ) { + SKIP: { + skip("Unable to lookup macro: $macro->{macro}",1) if $macro->{skip}; + my ($value) = $session->dbSlave->quickArray( + sprintf "select value from settings where name=%s", + $session->db->quote($macro->{settingKey}) + ); + my $macroVal = sprintf "^%s();", $macro->{shortcut}; + WebGUI::Macro::process($session, \$macroVal); + is($value, $macroVal, sprintf "Testing %s", $macro->{macro}); + } +} + +cleanup($session); # this line is required + +# ---- DO NOT EDIT BELOW THIS LINE ----- + +sub initialize { + $|=1; # disable output buffering + my $configFile; + GetOptions( + 'configFile=s'=>\$configFile + ); + exit 1 unless ($configFile); + my $session = WebGUI::Session->open("../..",$configFile); +} + +sub cleanup { + my $session = shift; + $session->close(); +} +