Conditional load conversion.

In Page.t, place the newly created Snippet under a versionTag
so that it can be cleaned up at the end of the test.
This commit is contained in:
Colin Kuskie 2006-07-30 18:34:47 +00:00
parent d154726bc1
commit dd9c807166
9 changed files with 124 additions and 26 deletions

View file

@ -13,7 +13,6 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::GroupText;
use WebGUI::Session;
use WebGUI::Group;
use WebGUI::User;
@ -22,7 +21,23 @@ my $session = WebGUI::Test->session;
use Test::More; # increment this value for each test you create
plan tests => 3 + 4;
my $numTests;
$numTests = 3; #Direct Macro tests
$numTests += 4; #Bug tests
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::GroupText';
my $loaded = use_ok($macro);
my @mob;
my ($ms_users, $ms_distributors, $ms_int_distributors);
my ($disti, $int_disti);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
my $output;
@ -45,7 +60,7 @@ $session->db->dbh->do(q!CREATE TABLE myUserTable (userId varchar(22) binary NOT
##Create a bunch of users and put them in the table.
my @mob = map { WebGUI::User->new($session, "new") } 0..3;
@mob = map { WebGUI::User->new($session, "new") } 0..3;
my $sth = $session->db->prepare('INSERT INTO myUserTable VALUES(?)');
foreach my $mob (@mob) {
$sth->execute([ $mob->userId ]);
@ -53,9 +68,9 @@ foreach my $mob (@mob) {
##Create the 3 groups
my $ms_users = WebGUI::Group->new($session, "new");
my $ms_distributors = WebGUI::Group->new($session, "new");
my $ms_int_distributors = WebGUI::Group->new($session, "new");
$ms_users = WebGUI::Group->new($session, "new");
$ms_distributors = WebGUI::Group->new($session, "new");
$ms_int_distributors = WebGUI::Group->new($session, "new");
$ms_users->name('MS Users');
$ms_distributors->name('MS Distributors');
@ -75,8 +90,8 @@ $ms_distributors->addGroups([$ms_int_distributors->getId]);
##Add two users for testing the two groups
my $disti = WebGUI::User->new($session, 'new');
my $int_disti = WebGUI::User->new($session, 'new');
$disti = WebGUI::User->new($session, 'new');
$int_disti = WebGUI::User->new($session, 'new');
$ms_distributors->addUsers([$disti->userId]);
$ms_int_distributors->addUsers([$int_disti->userId]);
@ -105,6 +120,8 @@ $output = join ',',
;
is($output, 'user,disti,int_disti', 'user is in all three groups');
}
##clean up everything
END {
foreach my $testGroup ($ms_users, $ms_distributors, $ms_int_distributors, ) {

View file

@ -13,7 +13,6 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::H_homeLink;
use WebGUI::Session;
use HTML::TokeParser;
use Data::Dumper;
@ -63,8 +62,17 @@ foreach my $testSet (@testSets) {
$numTests += 1 + (ref $testSet->{output} eq 'CODE');
}
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::H_homeLink';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::H_homeLink::process($session, $testSet->{label}, $testSet->{template});
if (ref $testSet->{output} eq 'CODE') {
@ -77,6 +85,8 @@ foreach my $testSet (@testSets) {
}
}
}
sub addTemplate {
$session->user({userId=>3});
my $importNode = WebGUI::Asset->getImportNode($session);

View file

@ -15,7 +15,6 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::Hash_userId;
use WebGUI::Session;
use Data::Dumper;
@ -36,10 +35,21 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Hash_userId';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->user({userId => $testSet->{userId}});
my $output = WebGUI::Macro::Hash_userId::process($session);
is($output, $testSet->{userId}, 'testing '.$testSet->{comment});
}
}

View file

@ -13,7 +13,6 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::Include;
use WebGUI::Session;
use WebGUI::Storage;
@ -33,8 +32,7 @@ my $storage = WebGUI::Storage->createTemp($session);
$storage->addFileFromScalar('goodFile', $goodFile);
$storage->addFileFromScalar('twoLines', $twoLines);
$storage->addFileFromScalar('unreadableFile', 'The contents of this file are not readable');
chmod 0111, $storage->getPath('unreadableFile')
or diag($!);
chmod(0111, $storage->getPath('unreadableFile')) or diag($!);
my @testSets = (
{
@ -96,13 +94,24 @@ my @testSets = (
my $numTests = scalar @testSets;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Include';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::Include::process($session, $testSet->{file});
my $passed = is($output, $testSet->{output}, $testSet->{comment} . ":" .$testSet->{file});
}
}
END {
$storage->delete;
}

View file

@ -43,8 +43,9 @@ my @testSets = (
},
);
my $numTests = scalar @testSets + 1;
my $numTests = scalar @testSets;
$numTests += 1;
plan tests => $numTests;
my $loaded = use_ok('WebGUI::Macro::International');

View file

@ -13,7 +13,6 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::LastModified;
use WebGUI::Session;
use Test::More; # increment this value for each test you create
@ -48,15 +47,28 @@ my @testSets = (
},
);
my $numTests = scalar @testSets + 2;
my $numTests = scalar @testSets;
$numTests += 1; #For the use_ok
$numTests += 2; #For TODO tests
plan tests => $numTests;
my $macro = 'WebGUI::Macro::LastModified';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
my $output = WebGUI::Macro::LastModified::process($session, $testSet->{label}, $testSet->{format});
is($output, $testSet->{output}, $testSet->{comment});
}
}
TODO: {
local $TODO = "Tests to make later";
ok(0, 'Check label and format');

View file

@ -131,9 +131,15 @@ foreach my $testSet (@testSets) {
$numTests += 1 + (ref $testSet->{parser} eq 'CODE');
}
plan tests => $numTests + 1;
$numTests += 1; #for the use_ok
plan tests => $numTests;
use_ok('WebGUI::Macro::LoginToggle');
my $macro = 'WebGUI::Macro::LoginToggle';
my $loaded = use_ok($macro);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->user({userId=>$testSet->{userId}});
@ -157,6 +163,8 @@ foreach my $testSet (@testSets) {
}
}
}
sub simpleHTMLParser {
my ($text) = @_;
my $p = HTML::TokeParser->new(\$text);

View file

@ -13,7 +13,6 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::Page;
use WebGUI::Session;
use Data::Dumper;
@ -47,13 +46,22 @@ foreach my $testSet (@testSets) {
$numTests += scalar keys %{ $testSet };
}
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::Page';
my $loaded = use_ok($macro);
my $homeAsset = WebGUI::Asset->getDefault($session);
my $versionTag;
($versionTag, @testSets) = setupTest($session, $homeAsset, @testSets);
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
foreach my $testSet (@testSets) {
$session->asset($testSet->{asset});
my $class = $testSet->{className};
@ -65,6 +73,8 @@ foreach my $testSet (@testSets) {
}
}
}
sub setupTest {
my ($session, $homeAsset, @testSets) = @_;
my $versionTag = WebGUI::VersionTag->getWorking($session);

View file

@ -13,7 +13,6 @@ use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Macro::PageTitle;
use WebGUI::Session;
use Data::Dumper;
@ -21,15 +20,18 @@ use Test::More; # increment this value for each test you create
my $session = WebGUI::Test->session;
plan tests => 2;
my $numTests = 2;
$numTests += 1; #For the use_ok
plan tests => $numTests;
my $macro = 'WebGUI::Macro::PageTitle';
my $loaded = use_ok($macro);
my $homeAsset = WebGUI::Asset->getDefault($session);
##Make the homeAsset the default asset in the session.
$session->asset($homeAsset);
my $output = WebGUI::Macro::PageTitle::process($session);
is($output, $homeAsset->get('title'), 'fetching title for site default asset');
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->set({name=>"PageTitle macro test"});
# Create a new snippet and set it's title then check it against the macros output
my $snippetTitle = "Roy's Incredible Snippet of Mystery and Intrique";
@ -40,6 +42,25 @@ my $snippet = $homeAsset->addChild({
groupIdView=>7,
groupIdEdit=>3,
});
$versionTag->commit;
SKIP: {
skip "Unable to load $macro", $numTests-1 unless $loaded;
##Make the homeAsset the default asset in the session.
$session->asset($homeAsset);
my $output = WebGUI::Macro::PageTitle::process($session);
is($output, $homeAsset->get('title'), 'fetching title for site default asset');
$session->asset($snippet);
my $macroOutput = WebGUI::Macro::PageTitle::process($session);
is($macroOutput, $snippet->get('title'), "testing title returned from localy created asset with known title");
}
END {
$versionTag->rollback;
}