insert macros into session config if not defined for testing
This commit is contained in:
parent
831f5a36e1
commit
734484f48e
7 changed files with 200 additions and 36 deletions
|
|
@ -15,6 +15,8 @@ use lib "$FindBin::Bin/../lib";
|
|||
use WebGUI::Test;
|
||||
use WebGUI::Macro;
|
||||
use WebGUI::Session;
|
||||
use Data::Dumper;
|
||||
use Macro_Config;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -26,6 +28,11 @@ plan tests => $numTests;
|
|||
|
||||
diag("Planning on running $numTests tests\n");
|
||||
|
||||
unless ($session->config->get('macros')->{'AdminText'}) {
|
||||
diag("Inserting macro into config");
|
||||
Macro_Config::insert_macro($session, 'AdminText', 'AdminText');
|
||||
}
|
||||
|
||||
my $adminText = "^AdminText(admin);";
|
||||
my $output;
|
||||
|
||||
|
|
@ -47,23 +54,3 @@ $session->var->switchAdminOff;
|
|||
$output = $adminText;
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, '', 'user is admin, not in admin mode');
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ use WebGUI::Test;
|
|||
use WebGUI::Macro;
|
||||
use WebGUI::Session;
|
||||
use Data::Dumper;
|
||||
use Macro_Config;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -27,6 +28,11 @@ plan tests => $numTests;
|
|||
|
||||
diag("Planning on running $numTests tests\n");
|
||||
|
||||
unless ($session->config->get('macros')->{'@'}) {
|
||||
diag("Inserting macro into config");
|
||||
Macro_Config::insert_macro($session, '@', 'At_username');
|
||||
}
|
||||
|
||||
my $macroText = "^@;";
|
||||
my $output;
|
||||
|
||||
|
|
|
|||
76
t/Macro/D_date.t
Normal file
76
t/Macro/D_date.t
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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;
|
||||
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);';
|
||||
my $wgbday = 997966800;
|
||||
my $output;
|
||||
|
||||
my @testSets = (
|
||||
{
|
||||
format => '%%%c%d%h',
|
||||
output =>'%August1608',
|
||||
},
|
||||
{
|
||||
format => '',
|
||||
output =>'8/16/2001 8:00 am',
|
||||
},
|
||||
);
|
||||
|
||||
my $numTests = scalar @testSets;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
diag("Planning on running $numTests tests\n");
|
||||
|
||||
unless ($session->config->get('macros')->{'D'}) {
|
||||
diag("Inserting macro into config");
|
||||
Macro_Config::insert_macro($session, 'D', 'Date');
|
||||
}
|
||||
|
||||
foreach my $testSet (@testSets) {
|
||||
$output = sprintf $macroText, $testSet->{format}, $wgbday;
|
||||
diag("current test: $output");
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -16,17 +16,23 @@ use WebGUI::Test;
|
|||
use WebGUI::Macro;
|
||||
use WebGUI::Session;
|
||||
use Data::Dumper;
|
||||
use Macro_Config;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
use Test::More; # increment this value for each test you create
|
||||
use Test::More;
|
||||
|
||||
my $numTests = 2;
|
||||
my $numTests = 2; # increment this value for each test you create
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
diag("Planning on running $numTests tests\n");
|
||||
|
||||
unless ($session->config->get('macros')->{'GroupText'}) {
|
||||
diag("Inserting macro into config");
|
||||
Macro_Config::insert_macro($session, 'GroupText', 'GroupText');
|
||||
}
|
||||
|
||||
my $macroText = "^GroupText(3,local,foreigner);";
|
||||
my $output;
|
||||
|
||||
|
|
|
|||
10
t/Macro/Macro_Config.pm
Normal file
10
t/Macro/Macro_Config.pm
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
package Macro_Config;
|
||||
|
||||
sub insert_macro {
|
||||
my ($session, $nickname, $macroName) = @_;
|
||||
my %macros = $session->config->get('macros');
|
||||
$macros{$nickname} = $macroName;
|
||||
$session->config->{_config}->set(macros => \%macros);
|
||||
}
|
||||
|
||||
1;
|
||||
80
t/Macro/Quote.t
Normal file
80
t/Macro/Quote.t
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
#-------------------------------------------------------------------
|
||||
# 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;
|
||||
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
|
||||
|
||||
unless ($session->config->get('macros')->{'Quote'}) {
|
||||
diag("Inserting macro into config");
|
||||
Macro_Config::insert_macro($session, 'Quote', 'Quote');
|
||||
}
|
||||
|
||||
|
||||
my $macroText = '^Quote("%s");';
|
||||
my $output;
|
||||
|
||||
my @testSets = (
|
||||
{
|
||||
input => q!that's great!,
|
||||
output => q!'that\\'s great'!,
|
||||
},
|
||||
{
|
||||
input => q!0!,
|
||||
output => q!'0'!,
|
||||
},
|
||||
{
|
||||
input => q!!,
|
||||
output => q!''!,
|
||||
},
|
||||
);
|
||||
|
||||
my $numTests = scalar @testSets;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
||||
diag("Planning on running $numTests tests\n");
|
||||
|
||||
foreach my $testSet (@testSets) {
|
||||
$output = sprintf $macroText, $testSet->{input};
|
||||
diag("current test: $output");
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -16,6 +16,7 @@ use WebGUI::Test;
|
|||
use WebGUI::Macro;
|
||||
use WebGUI::Session;
|
||||
use Data::Dumper;
|
||||
use Macro_Config;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -39,6 +40,8 @@ my @settingMacros = (
|
|||
},
|
||||
);
|
||||
|
||||
use Test::More; # increment this value for each test you create
|
||||
|
||||
##Build a reverse hash of the macro settings in the session var so that
|
||||
##we can lookup the aliases for each macro.
|
||||
|
||||
|
|
@ -50,15 +53,14 @@ foreach my $macro ( @settingMacros ) {
|
|||
++$settingMacros;
|
||||
if (exists $macroNames{ $macro->{macro} }) {
|
||||
$macro->{shortcut} = $macroNames{ $macro->{macro} };
|
||||
$macro->{skip} = 0;
|
||||
}
|
||||
else {
|
||||
$macro->{skip} = 1;
|
||||
diag("Installing macro $macro->{macro} into config");
|
||||
Macro_Config::insert_macro($session, $macro->{macro}, $macro->{macro});
|
||||
$macro->{shortcut} = $macro->{macro};
|
||||
}
|
||||
}
|
||||
|
||||
use Test::More; # increment this value for each test you create
|
||||
|
||||
my $numTests = $settingMacros;
|
||||
|
||||
plan tests => $numTests;
|
||||
|
|
@ -66,14 +68,11 @@ 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});
|
||||
}
|
||||
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});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue