Macro Tests: refactored all macro tests to remove a very evil hack
for inserting macros into the config. The new method is much cleaner and uses the Config API. Updated the docs for the RootTitle macro, both POD and online help.
This commit is contained in:
parent
cc61639232
commit
f1159269a0
32 changed files with 245 additions and 132 deletions
|
|
@ -25,7 +25,7 @@ Macro for returning the title of the root for this page.
|
|||
|
||||
If an asset exists in the session variable cache and and it's
|
||||
topmost parent (root) can be found the title for that asset
|
||||
is returned. Otherwise a space is returned.
|
||||
is returned. Otherwise an empty string is returned.
|
||||
|
||||
=cut
|
||||
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ our $I18N = {
|
|||
<p><b>^RootTitle;</b><br />
|
||||
Returns the title of the root of the current page. For instance, the main root in WebGUI is the "Home" page. Many advanced sites have many roots and thus need a way to display to the user which root they are in.
|
||||
</p>
|
||||
<p>If the macro is called outside of an asset, or if the root can't be found, then
|
||||
the macro returns an empty string</p>
|
||||
|,
|
||||
lastUpdated => 1146609161,
|
||||
lastUpdated => 1153849842,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -26,10 +26,8 @@ my $numTests = 4;
|
|||
|
||||
plan tests => $numTests;
|
||||
|
||||
|
||||
unless ($session->config->get('macros')->{'AdminText'}) {
|
||||
Macro_Config::insert_macro($session, 'AdminText', 'AdminText');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'AdminText', 'AdminText');
|
||||
|
||||
my $adminText = "^AdminText(admin);";
|
||||
my $output;
|
||||
|
|
@ -52,3 +50,10 @@ $session->var->switchAdminOff;
|
|||
$output = $adminText;
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, '', 'user is admin, not in admin mode');
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'AdminToggle'}) {
|
||||
Macro_Config::insert_macro($session, 'AdminToggle', 'AdminToggle');
|
||||
}
|
||||
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'AdminToggle', 'AdminToggle');
|
||||
|
||||
my ($versionTag, $template) = addTemplate();
|
||||
|
||||
|
|
@ -192,4 +192,8 @@ END {
|
|||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,10 +26,8 @@ my $numTests = 2;
|
|||
|
||||
plan tests => $numTests;
|
||||
|
||||
|
||||
unless ($session->config->get('macros')->{'@'}) {
|
||||
Macro_Config::insert_macro($session, '@', 'At_username');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, '@', 'At_username');
|
||||
|
||||
my $macroText = "^@;";
|
||||
my $output;
|
||||
|
|
@ -42,3 +40,10 @@ $output = $macroText;
|
|||
$session->user({userId => 3});
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, 'Admin', 'username = Admin');
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
use Test::More; # increment this value for each test you create
|
||||
|
||||
unless ($session->config->get('macros')->{'CanEditText'}) {
|
||||
Macro_Config::insert_macro($session, 'CanEditText', 'CanEditText');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'CanEditText', 'CanEditText');
|
||||
|
||||
my $adminText = "^CanEditText(editor);";
|
||||
my $output;
|
||||
|
|
@ -126,4 +125,8 @@ END { ##Clean-up after yourself, always
|
|||
foreach my $dude (@users) {
|
||||
$dude->delete if (defined $dude and ref $dude eq 'WebGUI::User');
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,15 +41,20 @@ my $numTests = scalar @testSets;
|
|||
|
||||
plan tests => $numTests;
|
||||
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'D'}) {
|
||||
Macro_Config::insert_macro($session, 'D', 'Date');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'D', 'Date');
|
||||
|
||||
foreach my $testSet (@testSets) {
|
||||
$output = sprintf $macroText, $testSet->{format}, $wgbday;
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, $testSet->{output}, 'testing '.$testSet->{format});
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'EditableToggle'}) {
|
||||
Macro_Config::insert_macro($session, 'EditableToggle', 'EditableToggle');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'EditableToggle', 'EditableToggle');
|
||||
|
||||
my $homeAsset = WebGUI::Asset->getDefault($session);
|
||||
$session->asset($homeAsset);
|
||||
|
|
@ -291,4 +290,8 @@ END { ##Clean-up after yourself, always
|
|||
foreach my $dude (@users) {
|
||||
$dude->delete if (defined $dude and ref $dude eq 'WebGUI::User');
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'Extras'}) {
|
||||
Macro_Config::insert_macro($session, 'Extras', 'Extras');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'Extras', 'Extras');
|
||||
|
||||
my @testSets = (
|
||||
{ ##Just get the extras path
|
||||
|
|
@ -59,3 +58,10 @@ foreach my $testSet (@testSets) {
|
|||
is($output, $testSet->{output}, 'testing '.$macro);
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'FetchMimeType'}) {
|
||||
Macro_Config::insert_macro($session, 'FetchMimeType', 'FetchMimeType');
|
||||
}
|
||||
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'FetchMimeType', 'FetchMimeType');
|
||||
|
||||
my $macroText = '^FetchMimeType("%s");';
|
||||
my $output;
|
||||
|
|
@ -63,3 +61,10 @@ foreach my $testSet (@testSets) {
|
|||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, $testSet->{output}, $testSet->{comment} );
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,8 @@ use Test::More; # increment this value for each test you create
|
|||
my $session = WebGUI::Test->session;
|
||||
my $i18n = WebGUI::International->new($session, 'Macro_FileUrl');
|
||||
|
||||
unless ($session->config->get('macros')->{'FileUrl'}) {
|
||||
Macro_Config::insert_macro($session, 'FileUrl', 'FileUrl');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'FileUrl', 'FileUrl');
|
||||
|
||||
##Add more Asset configurations here.
|
||||
my @testSets = (
|
||||
|
|
@ -138,4 +137,9 @@ sub setupTest {
|
|||
|
||||
END { ##Clean-up after yourself, always
|
||||
$versionTag->rollback;
|
||||
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ use HTML::TokeParser;
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'GroupAdd'}) {
|
||||
Macro_Config::insert_macro($session, 'GroupAdd', 'GroupAdd');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'GroupAdd', 'GroupAdd');
|
||||
|
||||
my $homeAsset = WebGUI::Asset->getDefault($session);
|
||||
my ($versionTag, $template, $groups, $users) = setupTest($session, $homeAsset);
|
||||
|
|
@ -217,4 +216,8 @@ END { ##Clean-up after yourself, always
|
|||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ use HTML::TokeParser;
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'GroupDelete'}) {
|
||||
Macro_Config::insert_macro($session, 'GroupDelete', 'GroupDelete');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'GroupDelete', 'GroupDelete');
|
||||
|
||||
my $homeAsset = WebGUI::Asset->getDefault($session);
|
||||
my ($versionTag, $template, $groups, $users) = setupTest($session, $homeAsset);
|
||||
|
|
@ -216,4 +215,8 @@ END { ##Clean-up after yourself, always
|
|||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,9 +25,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
plan tests => 3 + 4;
|
||||
|
||||
unless ($session->config->get('macros')->{'GroupText'}) {
|
||||
Macro_Config::insert_macro($session, 'GroupText', 'GroupText');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'GroupText', 'GroupText');
|
||||
|
||||
my $macroText = q!^GroupText("Admins","admin","visitor");!;
|
||||
my $output;
|
||||
|
|
@ -116,5 +115,9 @@ END {
|
|||
$dude->delete if (defined $dude and ref $dude eq 'WebGUI::User');
|
||||
}
|
||||
$session->db->dbh->do('DROP TABLE IF EXISTS myUserTable');
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'H_homeLink'}) {
|
||||
Macro_Config::insert_macro($session, 'H', 'H_homeLink');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'H', 'H_homeLink');
|
||||
|
||||
my ($versionTag, $template) = addTemplate();
|
||||
|
||||
|
|
@ -129,4 +128,8 @@ END {
|
|||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,8 @@ my $session = WebGUI::Test->session;
|
|||
|
||||
use Test::More; # increment this value for each test you create
|
||||
|
||||
unless ($session->config->get('macros')->{'#'}) {
|
||||
Macro_Config::insert_macro($session, '#', 'Hash_userId');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, '#', 'Hash_userId');
|
||||
|
||||
my @testSets = (
|
||||
{
|
||||
|
|
@ -49,3 +48,10 @@ foreach my $testSet (@testSets) {
|
|||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, $testSet->{userId}, 'testing '.$testSet->{comment});
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'International'}) {
|
||||
Macro_Config::insert_macro($session, 'International', 'International');
|
||||
}
|
||||
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'International', 'International');
|
||||
|
||||
my $macroText = '^International("%s","%s");';
|
||||
my $output;
|
||||
|
|
@ -63,3 +61,10 @@ foreach my $testSet (@testSets) {
|
|||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, $testSet->{output}, $testSet->{comment} );
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'LastModified'}) {
|
||||
Macro_Config::insert_macro($session, 'LastModified', 'LastModified');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'LastModified', 'LastModified');
|
||||
|
||||
my $homeAsset = WebGUI::Asset->getDefault($session);
|
||||
|
||||
|
|
@ -71,3 +70,10 @@ TODO: {
|
|||
ok(0, 'Check label and format');
|
||||
ok(0, 'Create asset with revisionDate = 0 and check label "never"');
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'Page'}) {
|
||||
Macro_Config::insert_macro($session, 'Page', 'Page');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'Page', 'Page');
|
||||
|
||||
##Add more Asset configurations here.
|
||||
my @testSets = (
|
||||
|
|
@ -89,4 +88,8 @@ sub setupTest {
|
|||
|
||||
END { ##Clean-up after yourself, always
|
||||
$versionTag->rollback;
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'PageTitle'}) {
|
||||
Macro_Config::insert_macro($session, 'PageTitle', 'PageTitle');
|
||||
}
|
||||
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'PageTitle', 'PageTitle');
|
||||
|
||||
my $macroText = '^PageTitle;';
|
||||
my $output;
|
||||
|
|
@ -46,3 +44,10 @@ TODO: {
|
|||
local $TODO = "Tests to make later";
|
||||
ok(0, 'Fetch title from locally made asset with known title');
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'PageUrl'}) {
|
||||
Macro_Config::insert_macro($session, 'PageUrl', 'PageUrl');
|
||||
}
|
||||
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'PageUrl', 'PageUrl');
|
||||
|
||||
my $macroText = '^PageUrl;';
|
||||
my $output;
|
||||
|
|
@ -46,3 +44,10 @@ TODO: {
|
|||
local $TODO = "Tests to make later";
|
||||
ok(0, 'Fetch url from locally made asset with known url');
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'Quote'}) {
|
||||
Macro_Config::insert_macro($session, 'Quote', 'Quote');
|
||||
}
|
||||
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'Quote', 'Quote');
|
||||
|
||||
my $macroText = '^Quote("%s");';
|
||||
my $output;
|
||||
|
|
@ -55,3 +53,10 @@ foreach my $testSet (@testSets) {
|
|||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, $testSet->{output}, 'testing '.$testSet->{input});
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,14 +22,9 @@ 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 @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'SQL', 'SQL');
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, '/', 'Slash_gatewayUrl');
|
||||
|
||||
my $macroText = '^SQL("%s","%s");';
|
||||
|
||||
|
|
@ -101,3 +96,10 @@ foreach my $testSet (@testSets) {
|
|||
}
|
||||
|
||||
$session->db->dbh->do('DROP TABLE testTable');
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,9 @@ use WebGUI::Session;
|
|||
use Data::Dumper;
|
||||
use WebGUI::Macro_Config;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
use Test::More; # increment this value for each test you create
|
||||
|
||||
#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 $session = WebGUI::Test->session;
|
||||
|
||||
my @settingMacros = (
|
||||
{
|
||||
|
|
@ -40,36 +37,28 @@ 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.
|
||||
|
||||
my %macroNames = reverse %{ $session->config->get('macros') };
|
||||
|
||||
my $settingMacros = 0;
|
||||
|
||||
##Build a reversed hash so we know how to call the macros based on
|
||||
##their name
|
||||
my @added_macros = ();
|
||||
foreach my $macro ( @settingMacros ) {
|
||||
++$settingMacros;
|
||||
if (exists $macroNames{ $macro->{macro} }) {
|
||||
$macro->{shortcut} = $macroNames{ $macro->{macro} };
|
||||
}
|
||||
else {
|
||||
Macro_Config::insert_macro($session, $macro->{macro}, $macro->{macro});
|
||||
$macro->{shortcut} = $macro->{macro};
|
||||
}
|
||||
$macro->{shortcut} = $macro->{macro};
|
||||
push @added_macros,
|
||||
WebGUI::Macro_Config::enable_macro($session, $macro->{shortcut}, $macro->{macro});
|
||||
}
|
||||
|
||||
my $numTests = $settingMacros;
|
||||
|
||||
plan tests => $numTests;
|
||||
plan tests => scalar @settingMacros;
|
||||
|
||||
foreach my $macro ( @settingMacros ) {
|
||||
my ($value) = $session->dbSlave->quickArray(
|
||||
sprintf "select value from settings where name=%s",
|
||||
$session->db->quote($macro->{settingKey})
|
||||
);
|
||||
"select value from settings where name=?", [$macro->{settingKey}]);
|
||||
my $macroVal = sprintf "^%s();", $macro->{shortcut};
|
||||
WebGUI::Macro::process($session, \$macroVal);
|
||||
is($value, $macroVal, sprintf "Testing %s", $macro->{macro});
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'/'}) {
|
||||
Macro_Config::insert_macro($session, '/', 'Slash_gatewayUrl');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, '/', 'Slash_gatewayUrl');
|
||||
|
||||
my $macroText = '^/;';
|
||||
my $output;
|
||||
|
|
@ -39,3 +38,10 @@ $output = $macroText;
|
|||
|
||||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, $session->url->gateway, 'fetching site gateway');
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'Spacer'}) {
|
||||
Macro_Config::insert_macro($session, 'Spacer', 'Spacer');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'Spacer', 'Spacer');
|
||||
|
||||
my @testSets = (
|
||||
{
|
||||
|
|
@ -86,3 +85,10 @@ sub simpleHTMLParser {
|
|||
|
||||
return ($width, $height, $src, $alt, $style);
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,9 +30,8 @@ use Data::Dumper;
|
|||
|
||||
plan tests => 4;
|
||||
|
||||
unless ($session->config->get('macros')->{'Splat_random'}) {
|
||||
Macro_Config::insert_macro($session, '*', 'Splat_random');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, '*', 'Splat_random');
|
||||
|
||||
my $macroText = q!^*(%s);!;
|
||||
my $output;
|
||||
|
|
@ -74,3 +73,10 @@ WHOLE: for (my $i=0; $i<=999; $i++) {
|
|||
is(scalar(@bins), 4, "All bins have values on a sample size of 1000");
|
||||
|
||||
#diag Dumper \@bins;
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,9 +27,8 @@ plan tests => 7;
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'Thumbnail'}) {
|
||||
Macro_Config::insert_macro($session, 'Thumbnail', 'Thumbnail');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'Thumbnail', 'Thumbnail');
|
||||
|
||||
my $square = WebGUI::Image->new($session, 100, 100);
|
||||
$square->setBackgroundColor('#0000FF');
|
||||
|
|
@ -93,4 +92,8 @@ END {
|
|||
$versionTag->rollback;
|
||||
}
|
||||
##Storage is cleaned up by rolling back the version tag
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,10 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'URLEncode'}) {
|
||||
Macro_Config::insert_macro($session, 'URLEncode', 'URLEncode');
|
||||
}
|
||||
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'URLEncode', 'URLEncode');
|
||||
|
||||
my $macroText = '^URLEncode("%s");';
|
||||
my $output;
|
||||
|
|
@ -63,3 +61,10 @@ foreach my $testSet (@testSets) {
|
|||
WebGUI::Macro::process($session, \$output);
|
||||
is($output, $testSet->{output}, 'testing '.$testSet->{input});
|
||||
}
|
||||
|
||||
END {
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,9 +22,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'User'}) {
|
||||
Macro_Config::insert_macro($session, 'User', 'User');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'User', 'User');
|
||||
|
||||
my @testSets = (
|
||||
{
|
||||
|
|
@ -90,4 +89,8 @@ END { ##Clean-up after yourself, always
|
|||
foreach my $dude (@users) {
|
||||
$dude->delete if (defined $dude and ref $dude eq 'WebGUI::User');
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,8 @@ use Test::More; # increment this value for each test you create
|
|||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
unless ($session->config->get('macros')->{'a_account'}) {
|
||||
Macro_Config::insert_macro($session, 'a', 'a_account');
|
||||
}
|
||||
my @added_macros = ();
|
||||
push @added_macros, WebGUI::Macro_Config::enable_macro($session, 'a', 'a_account');
|
||||
|
||||
# <a class="myAccountLink" href="<tmpl_var account.url>"><tmpl_var account.text></a>
|
||||
my ($versionTag, $template) = addTemplate();
|
||||
|
|
@ -132,4 +131,8 @@ END {
|
|||
if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
foreach my $macro (@added_macros) {
|
||||
next unless $macro;
|
||||
$session->config->deleteFromHash("macros", $macro);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
package Macro_Config;
|
||||
package WebGUI::Macro_Config;
|
||||
|
||||
sub insert_macro {
|
||||
sub enable_macro {
|
||||
my ($session, $nickname, $macroName) = @_;
|
||||
my %macros = %{ $session->config->get('macros') };
|
||||
$macros{$nickname} = $macroName;
|
||||
$session->config->{_config}->{'macros'} = \%macros;
|
||||
return '' if $macros{$nickname};
|
||||
$session->config->addToHash("macros", $nickname, $macroName);
|
||||
return $nickname;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue