Move Macro utility module into t/lib

Break Macro.t into component tests
resolve conflicts from merge
prove passes on t/Macro
This commit is contained in:
Colin Kuskie 2006-01-17 22:16:12 +00:00
parent 83d59837fd
commit bf960218bf
9 changed files with 24 additions and 172 deletions

115
t/Macro.t
View file

@ -1,115 +0,0 @@
#-------------------------------------------------------------------
# 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 Data::Dumper;
my $session = WebGUI::Test->session;
#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 = 6 + $settingMacros;
plan tests => $numTests;
diag("Planning on running $numTests tests\n");
my $macroText = "^GroupText(3,local,foreigner);";
my $AdminText = "^AdminText(admin);";
my $output;
$output = $macroText;
WebGUI::Macro::process($session, \$output);
is($output, 'foreigner', 'GroupText, user not in group');
$output = $adminText;
WebGUI::Macro::process($session, \$output);
is($output, '', 'AdminText, user not in group');
$output = $macroText;
$session->user({userId => 3});
WebGUI::Macro::process($session, \$output);
is($output, 'local', 'GroupText, user in group');
$output = $adminText;
WebGUI::Macro::process($session, \$output);
is($output, 'admin', 'AdminText, user is admin');
my $apText = "^AssetProxy(getting_started);";
WebGUI::Macro::process($session, \$apText);
my $apPass = like($output, qr/If you're reading this/, 'AssetProxy functional check');
SKIP: {
skip("AssetProxy isn't working",1) unless $apPass;
$macroText = "^GroupText(3,^AssetProxy(getting_started);,foreigner)";
$output = $macroText;
WebGUI::Macro::process($session, \$output);
like($output, qr/If you're reading this/, 'GroupText, nesting, in group');
}
diag("Begin setting macro tests");
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});
}
}

View file

@ -16,7 +16,7 @@ use WebGUI::Test;
use WebGUI::Macro;
use WebGUI::Session;
use Data::Dumper;
use Macro_Config;
use WebGUI::Macro_Config;
my $session = WebGUI::Test->session;

View file

@ -16,7 +16,7 @@ use WebGUI::Test;
use WebGUI::Macro;
use WebGUI::Session;
use Data::Dumper;
use Macro_Config;
use WebGUI::Macro_Config;
my $session = WebGUI::Test->session;

View file

@ -9,17 +9,17 @@
#-------------------------------------------------------------------
# ---- BEGIN DO NOT EDIT ----
use FindBin;
use strict;
use lib '../../lib';
use Getopt::Long;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::Macro_Config;
use Data::Dumper;
use Macro_Config;
# ---- END DO NOT EDIT ----
my $session = initialize(); # this line is required
use Test::More; # increment this value for each test you create
my $macroText = '^D("%s",%s);';
@ -43,6 +43,8 @@ plan tests => $numTests;
diag("Planning on running $numTests tests\n");
my $session = WebGUI::Test->session;
unless ($session->config->get('macros')->{'D'}) {
diag("Inserting macro into config");
Macro_Config::insert_macro($session, 'D', 'Date');
@ -54,23 +56,3 @@ foreach my $testSet (@testSets) {
WebGUI::Macro::process($session, \$output);
is($output, $testSet->{output}, 'testing '.$testSet->{format});
}
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();
}

View file

@ -16,7 +16,7 @@ use WebGUI::Test;
use WebGUI::Macro;
use WebGUI::Session;
use Data::Dumper;
use Macro_Config;
use WebGUI::Macro_Config;
my $session = WebGUI::Test->session;

View file

@ -8,20 +8,20 @@
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
# ---- BEGIN DO NOT EDIT ----
use FindBin;
use strict;
use lib '../../lib';
use Getopt::Long;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro;
use WebGUI::Session;
use WebGUI::Macro_Config;
use Data::Dumper;
use Macro_Config;
# ---- END DO NOT EDIT ----
my $session = initialize(); # this line is required
use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
unless ($session->config->get('macros')->{'Quote'}) {
diag("Inserting macro into config");
Macro_Config::insert_macro($session, 'Quote', 'Quote');
@ -58,23 +58,3 @@ foreach my $testSet (@testSets) {
WebGUI::Macro::process($session, \$output);
is($output, $testSet->{output}, 'testing '.$testSet->{input});
}
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();
}

View file

@ -16,7 +16,7 @@ use WebGUI::Test;
use WebGUI::Macro;
use WebGUI::Session;
use Data::Dumper;
use Macro_Config;
use WebGUI::Macro_Config;
my $session = WebGUI::Test->session;

View file

@ -15,15 +15,20 @@ use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use Test::More tests => 22; # increment this value for each test you create
use Test::More tests => 26; # increment this value for each test you create
my $session = WebGUI::Test->session;
my $wgbday = 997966800;
my $bdayCopy = $wgbday;
ok($session->datetime->addToDate($wgbday,1,2,3) >= $wgbday+1*60*60*24*365+2*60*60*24*28+3*60*60*24, "addToDate()");
ok($session->datetime->addToTime($wgbday,1,2,3) >= $wgbday+1*60*60+2*60+3, "addToTime()");
my ($start, $end) = $session->datetime->dayStartEnd($wgbday);
ok($end-$start >= 60*60*23, "dayStartEnd()");
is($session->datetime->epochToHuman($wgbday,"%y"), "2001", "epochToHuman() - year");
is($session->datetime->epochToHuman($wgbday,"%c"), "August", "epochToHuman() - month name");
is($session->datetime->epochToHuman($wgbday,"%m"), "08", "epochToHuman() - month number, 2 digit");
is($session->datetime->epochToHuman($wgbday,"%M"), "8", "epochToHuman() - month number, variable digit");
is($session->datetime->epochToHuman($wgbday,"%%%c%d%h"), "%August1608", "epochToHuman()");
is($session->datetime->epochToSet($wgbday,1), "2001-08-16 08:00:00", "epochToSet()");
is($session->datetime->getDayName(7), "Sunday", "getDayName()");