diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 402145569..9e9ae35ca 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -27,6 +27,10 @@ - fixed #11181: ableToBeFriend label not i18n - fixed #11179: user.CanStartThread missing from help - fixed #11183: Calendar List View + - fixed #11135: Tree Navigation menu template shows a drop down fly-out menu + - fixed #10984: Edit Survey Screen isn't right in demo + - added: getTopKeywords method to Keywords API + - added: print remaining tickets feature to EMS 7.8.2 - Added scheduled vendor payout workflow activity. (Special thanks to Martin @ Oqapi) diff --git a/docs/upgrades/packages-7.8.3/root_import_ems.wgpkg b/docs/upgrades/packages-7.8.3/root_import_ems.wgpkg new file mode 100644 index 000000000..6b429b042 Binary files /dev/null and b/docs/upgrades/packages-7.8.3/root_import_ems.wgpkg differ diff --git a/docs/upgrades/packages-7.8.3/root_import_macro_picklanguage.wgpkg b/docs/upgrades/packages-7.8.3/root_import_macro_picklanguage.wgpkg index 30ba71727..da20e143f 100644 Binary files a/docs/upgrades/packages-7.8.3/root_import_macro_picklanguage.wgpkg and b/docs/upgrades/packages-7.8.3/root_import_macro_picklanguage.wgpkg differ diff --git a/docs/upgrades/packages-7.8.3/root_import_navigation_tree-navigation.wgpkg b/docs/upgrades/packages-7.8.3/root_import_navigation_tree-navigation.wgpkg new file mode 100644 index 000000000..f2ba1fc1e Binary files /dev/null and b/docs/upgrades/packages-7.8.3/root_import_navigation_tree-navigation.wgpkg differ diff --git a/docs/upgrades/packages-7.8.3/root_import_survey_default-survey-edit.wgpkg b/docs/upgrades/packages-7.8.3/root_import_survey_default-survey-edit.wgpkg new file mode 100644 index 000000000..bc776e75f Binary files /dev/null and b/docs/upgrades/packages-7.8.3/root_import_survey_default-survey-edit.wgpkg differ diff --git a/docs/upgrades/upgrade_7.8.2-7.8.3.pl b/docs/upgrades/upgrade_7.8.2-7.8.3.pl index b0d402b9b..3aac01b6d 100644 --- a/docs/upgrades/upgrade_7.8.2-7.8.3.pl +++ b/docs/upgrades/upgrade_7.8.2-7.8.3.pl @@ -40,9 +40,21 @@ addTrashAdminSetting($session); addPickLanguageMacro($session); installSetLanguage($session); i18nAbleToBeFriend($session); +addEMSEnhancements($session); finish($session); # this line required +#---------------------------------------------------------------------------- +sub addEMSEnhancements { + my $session = shift; + print "\tAdding EMS Enhancements, if needed... " unless $quiet; + my $sth = $session->db->read('describe EventManagementSystem printRemainingTicketsTemplateId'); + if (! defined $sth->hashRef) { + $session->db->write("alter table EventManagementSystem add column printRemainingTicketsTemplateId char(22) not null default 'hreA_bgxiTX-EzWCSZCZJw' after printTicketTemplateId"); + } + print "Done.\n" unless $quiet; +} + #---------------------------------------------------------------------------- sub i18nAbleToBeFriend { my $session = shift; diff --git a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm index e43ba0396..d5e17bae4 100644 --- a/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm +++ b/lib/WebGUI/Asset/Wobject/EventManagementSystem.pm @@ -212,6 +212,14 @@ sub definition { hoverHelp => $i18n->get('event submission queue template help'), namespace => 'EMS/SubmissionQueue', }, + printRemainingTicketsTemplateId => { + fieldType => 'template', + defaultValue => 'hreA_bgxiTX-EzWCSZCZJw', + tab => 'display', + label => $i18n->get('print remaining ticket template'), + hoverHelp => $i18n->get('print remaining ticket template help'), + namespace => 'EMS/PrintRemainingTickets', + }, badgeInstructions => { fieldType => 'HTMLArea', defaultValue => $i18n->get('default badge instructions'), @@ -854,6 +862,7 @@ sub www_buildBadge { importTicketsUrl => $self->getUrl('func=importEvents'), exportTicketsUrl => $self->getUrl('func=exportEvents'), getTicketsUrl => $self->getUrl('func=getTicketsAsJson;badgeId='.$badgeId), + printRemainingTicketsUrl => $self->getUrl('func=printRemainingTickets'), canEdit => $self->canEdit, hasBadge => ($badgeId ne ""), badgeId => $badgeId, @@ -2435,6 +2444,61 @@ sub www_printBadge { #------------------------------------------------------------------- +=head2 www_printRemainingTickets () + +Displays all of the remaining tickets for this EMS + +=cut + +sub www_printRemainingTickets { + my $self = shift; + my $session = $self->session; + return $session->privilege->insufficient() unless ($self->isRegistrationStaff); + + my $var = $self->get; + my $sth = $session->db->read(qq{ + SELECT + asset.creationDate, + assetData.*, + assetData.title as ticketTitle, + EMSTicket.price, + EMSTicket.seatsAvailable, + EMSTicket.startDate as ticketStart, + EMSTicket.duration as ticketDuration, + EMSTicket.eventNumber as ticketEventNumber, + EMSTicket.location as ticketLocation, + EMSTicket.relatedBadgeGroups, + EMSTicket.relatedRibbons, + (seatsAvailable - (select count(*) from EMSRegistrantTicket where ticketAssetId = asset.assetId)) as seatsRemaining + FROM + asset + join assetData using (assetId) + left join EMSTicket using (assetId) + WHERE + parentId=? + and className='WebGUI::Asset::Sku::EMSTicket' + and state='published' + and EMSTicket.revisionDate=(select max(revisionDate) from EMSTicket where assetId=asset.assetId) + and (seatsAvailable - (select count(*) from EMSRegistrantTicket where ticketAssetId = asset.assetId)) > 0 + GROUP BY + asset.assetId + ORDER BY + title desc + },[$self->getId]); + + $var->{'tickets_loop'} = []; + while (my $hash = $sth->hashRef) { + my $seatsRemaining = $hash->{seatsRemaining}; + for (my $i = 0; $i < $seatsRemaining; $i++ ) { + push(@{$var->{'tickets_loop'}},$hash); + } + } + + return $self->processTemplate($var,$self->get('printRemainingTicketsTemplateId')); +} + +#------------------------------------------------------------------- + =head2 www_printTicket ( ) Prints a ticket using a template. @@ -2515,7 +2579,7 @@ Toggles the registrant checked in flag. sub www_toggleRegistrantCheckedIn { my $self = shift; - return $self->session->privilege->insfufficient() unless ($self->isRegistrationStaff); + return $self->session->privilege->insufficient() unless ($self->isRegistrationStaff); my $db = $self->session->db; my $badgeId = $self->session->form->param('badgeId'); my $flag = $db->quickScalar("select hasCheckedIn from EMSRegistrant where badgeId=?",[$badgeId]); @@ -2524,7 +2588,6 @@ sub www_toggleRegistrantCheckedIn { return $self->www_manageRegistrant; } - #------------------------------------------------------------------- =head2 www_viewSchedule () diff --git a/lib/WebGUI/Help/Asset_EventManagementSystem.pm b/lib/WebGUI/Help/Asset_EventManagementSystem.pm index eacf27f93..9bb4a5115 100644 --- a/lib/WebGUI/Help/Asset_EventManagementSystem.pm +++ b/lib/WebGUI/Help/Asset_EventManagementSystem.pm @@ -42,6 +42,7 @@ our $HELP = { { 'name' => 'addTokenUrl'}, { 'name' => 'importTicketsUrl'}, { 'name' => 'exportTicketsUrl'}, + { 'name' => 'printRemainingTicketsUrl'}, { 'name' => 'canEdit'}, { 'name' => 'hasBadge'}, { 'name' => 'badgeId'}, @@ -226,6 +227,66 @@ our $HELP = { related => [], }, + 'ems print remaining ticket template' => { + source => 'sub www_printRemainingTickets', + title => 'print remaining ticket template help', + body => '', + variables => [ + { 'name' => 'tickets_loop', + 'variables' => [ + { 'name' => 'ticketTitle'}, + { 'name' => 'ticketStart'}, + { 'name' => 'ticketDuration'}, + { 'name' => 'ticketLocation'}, + { 'name' => 'ticketEventNumber'}, + { 'name' => 'seatsRemaining'}, + { 'name' => 'seatsAvailable'}, + { 'name' => 'price'}, + { 'name' => 'relatedRibbons'}, + { 'name' => 'relatedBadgeGroups'}, + { 'name' => 'title'}, + { 'name' => 'menuTitle'}, + { 'name' => 'url'}, + { 'name' => 'synopsis'}, + { 'name' => 'assetId'}, + { 'name' => 'assetSize'}, + { 'name' => 'creationDate'}, + { 'name' => 'encryptPage'}, + { 'name' => 'extraHeadTags'}, + { 'name' => 'extraHeadTagsPacked'}, + { 'name' => 'groupIdEdit'}, + { 'name' => 'groupIdView'}, + { 'name' => 'inheritUrlFromParent'}, + { 'name' => 'isExportable'}, + { 'name' => 'isHidden'}, + { 'name' => 'isPrototype'}, + { 'name' => 'isPackage'}, + { 'name' => 'lastModified'}, + { 'name' => 'newWindow'}, + { 'name' => 'ownerUserId'}, + { 'name' => 'revisedBy'}, + { 'name' => 'revisionDate'}, + { 'name' => 'skipNotification'}, + { 'name' => 'tagId'}, + { 'name' => 'usePackedHeadTags'}, + ], + }, + ], + isa => [ + { namespace => "Asset_EventManagementSystem", + tag => "ems asset template variables" + }, + { namespace => "Asset_Template", + tag => "template variables" + }, + { namespace => "Asset_Wobject", + tag => "wobject template variables" + }, + ], + fields => [], + related => [], + }, + 'ems asset template variables' => { source => 'sub definition', title => 'ems asset template variables', diff --git a/lib/WebGUI/Help/Macro_PickLanguage.pm b/lib/WebGUI/Help/Macro_PickLanguage.pm index f5bb02f61..a97371655 100644 --- a/lib/WebGUI/Help/Macro_PickLanguage.pm +++ b/lib/WebGUI/Help/Macro_PickLanguage.pm @@ -26,6 +26,12 @@ our $HELP = { }, ], }, + { + name => "delete_url", + }, + { + name => "delete_label", + }, ], related => [ ], diff --git a/lib/WebGUI/Keyword.pm b/lib/WebGUI/Keyword.pm index c0a2e4936..66f5e84ae 100644 --- a/lib/WebGUI/Keyword.pm +++ b/lib/WebGUI/Keyword.pm @@ -383,6 +383,80 @@ sub getMatchingAssets { return $self->session->db->buildArrayRef($query, \@params); } +#------------------------------------------------------------------- + +=head2 getTopKeywords ( $options ) + +Returns a hashref of the the top N keywords as well as the total number returned sorted in alphabetical order + +=head3 $options + +A hashref of options to change the behavior of the method. + +=head4 asset + +Find all keywords for all assets below an asset, providing a WebGUI::Asset object. + +=head4 assetId + +Find all keywords for all assets below an asset, providing an assetId. + +=head4 search + +Find all keywords using the SQL clause LIKE. This can be used in tandem with asset or assetId. + +=head4 limit + +Limit the number of top keywords that are returned. + +=cut + +sub getTopKeywords { + my $self = shift; + my $options = shift; + my $sql = q| + SELECT + keyword,occurrance + FROM ( + SELECT + keyword, count(keyword) as occurrance + FROM + assetKeyword + |; + my @where; + my @placeholders; + my $parentAsset; + if ($options->{asset}) { + $parentAsset = $options->{asset}; + } + if ($options->{assetId}) { + $parentAsset = WebGUI::Asset->new($self->session, $options->{assetId}); + } + if ($parentAsset) { + $sql .= ' INNER JOIN asset USING (assetId)'; + push @where, 'lineage LIKE ?'; + push @placeholders, $parentAsset->get('lineage') . '%'; + } + if ($options->{search}) { + push @where, 'keyword LIKE ?'; + push @placeholders, '%' . $options->{search} . '%'; + } + if (@where) { + $sql .= ' WHERE ' . join(' AND ', @where); + } + $sql .= ' GROUP BY keyword'; + $sql .= ' ORDER BY occurrance desc'; + if ($options->{limit}) { + $sql .= ' LIMIT ' . $options->{limit}; + } + $sql .= q| + ) as keywords + order by keyword + |; + my $keywords = $self->session->db->buildHashRef($sql, \@placeholders); + return $keywords; +} + #------------------------------------------------------------------- diff --git a/lib/WebGUI/Macro/PickLanguage.pm b/lib/WebGUI/Macro/PickLanguage.pm index 306f4f183..a1af2a40b 100644 --- a/lib/WebGUI/Macro/PickLanguage.pm +++ b/lib/WebGUI/Macro/PickLanguage.pm @@ -11,6 +11,7 @@ package WebGUI::Macro::PickLanguage; # edit this line to match your own macro na #------------------------------------------------------------------- use strict; +use WebGUI::Asset::Template; =head1 NAME @@ -47,17 +48,23 @@ sub process { return "Could not instanciate template with id [$templateId]" unless $template; my $i18n = WebGUI::International->new($session); my $languages = $i18n->getLanguages(); - my $vars = {'lang_loop' => []}; + my @lang_loop = (); foreach my $language ( keys %$languages ) { - my $langVars = {}; - $langVars->{ 'language_url' } = '?op=setLanguage;language=' . $language ; - $langVars->{ 'language_lang' } = $i18n->getLanguage($language , 'label'); - $langVars->{ 'language_langAbbr' } = $i18n->getLanguage($language, 'languageAbbreviation'); - $langVars->{ 'language_langAbbrLoc' } = $i18n->getLanguage($language, 'locale'); - $langVars->{ 'language_langEng' } = $language; - push(@{$vars->{lang_loop}}, $langVars); + push @lang_loop, { + language_url => '?op=setLanguage;language=' . $language, + language_lang => $i18n->getLanguage($language , 'label'), + language_langAbbr => $i18n->getLanguage($language, 'languageAbbreviation'), + language_langAbbrLoc => $i18n->getLanguage($language, 'locale'), + language_langEng => $language, + }; } - return $template->process($vars); + my %vars = ( + lang_loop => \@lang_loop, + delete_url => '?op=setLanguage;language=delete;', + delete_label => $i18n->get('delete',"Macro_PickLanguage"), + ); + + return $template->process(\%vars); } 1; diff --git a/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm b/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm index 3d04e6300..cbf6487f1 100644 --- a/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm +++ b/lib/WebGUI/i18n/English/Asset_EventManagementSystem.pm @@ -560,6 +560,25 @@ our $I18N = { context => q|help for a property label|, }, + + 'print remaining ticket template' => { + message => q|Print Remaining Tickets Template|, + lastUpdated => 0, + context => q|a property label|, + }, + + 'print remaining ticket template help' => { + message => q|Which template would you like to use for printing remaining tickets?|, + lastUpdated => 0, + context => q|help for a property label|, + }, + + 'print remaining tickets' => { + message => q|Print Remaining Tickets|, + lastUpdated => 0, + context => q|a link label on the builder page|, + }, + 'badge builder template' => { message => q|Badge Builder Template|, lastUpdated => 0, @@ -2044,12 +2063,200 @@ normal templates.|, lastUpdated => 1131394072, context => q|This is the help text for the 'next submission id' field, the user should be reminded not to edit this field.| }, + 'print remaining ticket template help' => { + message => q|EMS Print Remaining Ticket Template|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'tickets_loop' => { + message => q|A loop containing all of the remaining tickets and their associated data|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'seatsRemaining' => { + message => q|Total number of seats remaining for the ticket|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'seatsAvailable' => { + message => q|Total number of seats available for the ticket|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'relatedRibbons' => { + message => q|Ribbons related to the ticket|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'relatedBadgeGroups' => { + message => q|Badge groups related to the ticket|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'title' => { + message => q|The title of the ticket to be printed.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'menuTitle' => { + message => q|The title of the ticket to be displayed in the menu.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'synopsis' => { + message => q|Synopsis of the description for the ticket.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'assetId' => { + message => q|Asset Id of the ticket.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'assetSize' => { + message => q|Size of this ticket asset|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'creationDate' => { + message => q|Epoch value date for when the asset was created|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'encryptPage' => { + message => q|Whether or not to encrypt the page that the ticket is dipslayed on|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'extraHeadTags' => { + message => q|Extra tags that should be displayed in the header that this ticket is displayed on|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'extraHeadTagsPacked' => { + message => q|Extra tags that should be displayed in the header that this tikcet is displayed on minimized so no whitespace exists|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'groupIdEdit' => { + message => q|The id of the group that can edit this ticket.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'groupIdView' => { + message => q|The id of the group that can view this ticket.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'inheritUrlFromParent' => { + message => q|Whether or not to inherit the url from the parent|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'isExportable' => { + message => q|Whether or not this ticket is exportable|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'isHidden' => { + message => q|Whether or not this ticket should be hidden from the menu.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'isPrototype' => { + message => q|Whether or not this ticket asset is a prototype|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'isPackage' => { + message => q|Whether or not this ticket asset is a package|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'lastModified' => { + message => q|Epoch date for when this ticket was last modified|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'newWindow' => { + message => q|Whether this ticket should be displayed in a new window|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'ownerUserId' => { + message => q|User Id of the owner of this ticket|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'revisedBy' => { + message => q|Id of the user who last modified this ticket|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'revisionDate' => { + message => q|Epoch date for when this ticket was last revised|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'skipNotification' => { + message => q|Whether or not notifications for this ticket should be skipped.|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'tagId' => { + message => q|Tag Id for this asset|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'usePackedHeadTags' => { + message => q|Whether or not packed head tags should be used for this ticket|, + lastUpdated => 1147050475, + context => q|help text label|, + }, + + 'printRemainingTicketsUrl' => { + message => q|URL to the print remaining tickets page|, + lastUpdated => 1147050475, + context => q|Field Label|, + }, + + # 'TODO' => { # message => q|TODO|, # lastUpdated => 1147050475, # context => q|TODO|, # }, + }; 1; diff --git a/lib/WebGUI/i18n/English/Macro_PickLanguage.pm b/lib/WebGUI/i18n/English/Macro_PickLanguage.pm index a4f1cc78c..99458355a 100644 --- a/lib/WebGUI/i18n/English/Macro_PickLanguage.pm +++ b/lib/WebGUI/i18n/English/Macro_PickLanguage.pm @@ -40,6 +40,21 @@ our $I18N = { ##hashref of hashes lastUpdated => 1131394072, context => q|The url to change languages| }, + 'delete_url' => { + message => q|The url that deletes the scratch language from the session.|, + lastUpdated => 1131394072, + context => q|A template var to remove the scratch language| + }, + 'delete' => { + message => q|Go back to profile language.|, + lastUpdated => 1131394072, + context => q|An internationalized label to go back to the profile language| + }, + 'delete_label' => { + message => q|A label for the link to go back to the profile language.|, + lastUpdated => 1131394072, + context => q|Help for delete_label| + }, }; diff --git a/t/Asset/Wobject/EventManagementSystem.t b/t/Asset/Wobject/EventManagementSystem.t index 9796a6d91..8a7c73747 100644 --- a/t/Asset/Wobject/EventManagementSystem.t +++ b/t/Asset/Wobject/EventManagementSystem.t @@ -49,7 +49,7 @@ $versionTag->set({name=>"EventManagementSystem Test"}); #---------------------------------------------------------------------------- # Tests -plan tests => 35 ; # Increment this number for each test you create +plan tests => 41; # Increment this number for each test you create #---------------------------------------------------------------------------- @@ -128,16 +128,26 @@ ok(scalar(@$badges) == 2, 'Two Badges exist'); # Add tickets my @tickets; push(@tickets, $ems->addChild({ - className => 'WebGUI::Asset::Sku::EMSTicket', - startDate => '2009-01-01 14:00:00', - eventNumber => 1, - location => 'qq', + className => 'WebGUI::Asset::Sku::EMSTicket', + title => 'Test Ticket 1', + url => 'test-ems/ticket-1', + startDate => '2009-01-01 14:00:00', + eventNumber => 1, + location => 'qq', + seatsAvailable => 5, + price => 5, + duration => 1, })); push(@tickets, $ems->addChild({ - className => 'WebGUI::Asset::Sku::EMSTicket', - startDate => '2009-01-01 14:00:00', - eventNumber => 2, - location => 'qq', + className => 'WebGUI::Asset::Sku::EMSTicket', + title => 'Test Ticket 2', + url => 'test-ems/ticket-2', + startDate => '2009-01-01 14:00:00', + eventNumber => 2, + location => 'qq', + seatsAvailable => 3, + price => 10, + duration => 2, })); foreach my $ticket(@tickets) { @@ -163,17 +173,198 @@ ok(scalar(@$ribbons) == 2, 'Two ribbons exist'); ok( $ems->can('www_getScheduleDataJSON'), 'Can call get Schedule data' ); ok( $ems->can('www_viewSchedule'), 'Can call view Schedule' ); +ok( $ems->can('www_printRemainingTickets'), 'Can call print remaining tickets' ); + +#Test that the default template is correct +my $printRemainingTicketsTemplateId = $ems->get('printRemainingTicketsTemplateId'); +is($printRemainingTicketsTemplateId, "hreA_bgxiTX-EzWCSZCZJw", 'Default print remaining tickets template id ok'); + +#Make sure printRemainingTickets template returns the right data +my $templateMock = Test::MockObject->new({}); +$templateMock->set_isa('WebGUI::Asset::Template'); +$templateMock->set_always('getId', $printRemainingTicketsTemplateId); +my $templateVars; +$templateMock->mock('process', sub { $templateVars = $_[1]; } ); + +{ + WebGUI::Test->mockAssetId($printRemainingTicketsTemplateId, $templateMock); + $ems->www_printRemainingTickets(); + + my $ticket1 = { + 'seatsRemaining' => '5', + 'ticketTitle' => 'Test Ticket 1', + 'newWindow' => ignore(), + 'extraHeadTagsPacked' => ignore(), + 'synopsis' => ignore(), + 'extraHeadTags' => ignore(), + 'ownerUserId' => ignore(), + 'url' => 'test-ems/ticket-1', + 'assetId' => ignore(), + 'isPrototype' => ignore(), + 'isHidden' => ignore(), + 'groupIdEdit' => ignore(), + 'inheritUrlFromParent' => ignore(), + 'ticketEventNumber' => '1', + 'lastModified' => ignore(), + 'price' => '5', + 'title' => 'Test Ticket 1', + 'groupIdView' => ignore(), + 'ticketLocation' => 'qq', + 'skipNotification' => ignore(), + 'status' => ignore(), + 'menuTitle' => 'Test Ticket 1', + 'assetSize' => ignore(), + 'ticketDuration' => '1', + 'relatedRibbons' => ignore(), + 'revisionDate' => ignore(), + 'relatedBadgeGroups' => ignore(), + 'isPackage' => ignore(), + 'usePackedHeadTags' => ignore(), + 'encryptPage' => ignore(), + 'tagId' => ignore(), + 'seatsAvailable' => '5', + 'revisedBy' => ignore(), + 'isExportable' => ignore(), + 'creationDate' => ignore(), + 'ticketStart' => '2009-01-01 14:00:00' + }; + + my $ticket2 = { + 'seatsRemaining' => '3', + 'ticketTitle' => 'Test Ticket 2', + 'newWindow' => ignore(), + 'extraHeadTagsPacked' => ignore(), + 'synopsis' => ignore(), + 'extraHeadTags' => ignore(), + 'ownerUserId' => ignore(), + 'url' => 'test-ems/ticket-2', + 'assetId' => ignore(), + 'isPrototype' => ignore(), + 'isHidden' => ignore(), + 'groupIdEdit' => ignore(), + 'inheritUrlFromParent' => ignore(), + 'ticketEventNumber' => '2', + 'lastModified' => ignore(), + 'price' => '10', + 'title' => 'Test Ticket 2', + 'groupIdView' => ignore(), + 'ticketLocation' => 'qq', + 'skipNotification' => ignore(), + 'status' => ignore(), + 'menuTitle' => 'Test Ticket 2', + 'assetSize' => ignore(), + 'ticketDuration' => '2', + 'relatedRibbons' => ignore(), + 'revisionDate' => ignore(), + 'relatedBadgeGroups' => ignore(), + 'isPackage' => ignore(), + 'usePackedHeadTags' => ignore(), + 'encryptPage' => ignore(), + 'tagId' => ignore(), + 'seatsAvailable' => '3', + 'revisedBy' => ignore(), + 'isExportable' => ignore(), + 'creationDate' => ignore(), + 'ticketStart' => '2009-01-01 14:00:00' + }; + + my @ticketArray = (); + for(1..3) { + push(@ticketArray,$ticket2); + } + for(1..5) { + push(@ticketArray,$ticket1); + } + + cmp_deeply( + $templateVars, + { + 'badgeInstructions' => ignore(), + 'displayTitle' => ignore(), + 'createdBy' => ignore(), + 'lastExportedAs' => ignore(), + 'printRemainingTicketsTemplateId' => ignore(), + 'state' => ignore(), + 'printTicketTemplateId' => ignore(), + 'newWindow' => ignore(), + 'scheduleColumnsPerPage' => ignore(), + 'synopsis' => ignore(), + 'extraHeadTagsPacked' => ignore(), + 'ownerUserId' => ignore(), + 'extraHeadTags' => ignore(), + 'assetId' => ignore(), + 'url' => 'test-ems', + 'isHidden' => ignore(), + 'isPrototype' => ignore(), + 'groupIdEdit' => ignore(), + 'timezone' => ignore(), + 'styleTemplateId' => ignore(), + 'inheritUrlFromParent' => ignore(), + 'description' => 'This is a test ems', + 'stateChangedBy' => ignore(), + 'lineage' => ignore(), + 'className' => 'WebGUI::Asset::Wobject::EventManagementSystem', + 'groupToApproveEvents' => ignore(), + 'lastModified' => ignore(), + 'title' => 'Test EMS', + 'groupIdView' => ignore(), + 'mobileStyleTemplateId' => ignore(), + 'skipNotification' => ignore(), + 'scheduleTemplateId' => ignore(), + 'status' => ignore(), + 'menuTitle' => 'Test EMS', + 'assetSize' => ignore(), + 'lookupRegistrantTemplateId' => ignore(), + 'isLockedBy' => ignore(), + 'stateChanged' => ignore(), + 'revisionDate' => ignore(), + 'ribbonInstructions' => ignore(), + 'isPackage' => ignore(), + 'usePackedHeadTags' => ignore(), + 'templateId' => ignore(), + 'badgeBuilderTemplateId' => ignore(), + 'printBadgeTemplateId' => ignore(), + 'encryptPage' => ignore(), + 'tagId' => ignore(), + 'isSystem' => ignore(), + 'revisedBy' => ignore(), + 'isExportable' => ignore(), + 'creationDate' => ignore(), + 'registrationStaffGroupId' => ignore(), + 'parentId' => ignore(), + 'tokenInstructions' => ignore(), + 'printableStyleTemplateId' => ignore(), + 'ticketInstructions' => ignore(), + 'tickets_loop' => \@ticketArray, + }, + "www_printRemainingTickets: template variables valid" + ); + + WebGUI::Test->unmockAssetId($printRemainingTicketsTemplateId); +} + +#Make sure permissions work on pages my $data; $session->user({userId => $crasher->getId}); $session->http->setStatus(201); $data = $ems->www_viewSchedule(); is($session->http->getStatus, 401, 'www_viewSchedule: visitor may not see the schedule'); +$data = $ems->www_printRemainingTickets(); +is($session->http->getStatus, 401, 'www_printRemainingTickets: visitor may not print the remaining tickets'); $session->http->setStatus(201); $session->user({userId => $attender->getId}); $data = $ems->www_viewSchedule(); is($session->http->getStatus, 201, '... attender user can see the schedule'); +$data = $ems->www_printRemainingTickets(); +is($session->http->getStatus, 401, 'www_printRemainingTickets: attender may not print the remaining tickets'); + +$session->http->setStatus(201); +$session->user({userId => $registrar->getId}); +$data = $ems->www_printRemainingTickets(); +is($session->http->getStatus, 201, 'www_printRemainingTickets: registration staff may print the remaining tickets'); + $session->http->setStatus(201); $session->user({userId => $crasher->getId}); diff --git a/t/Keyword.t b/t/Keyword.t index 03c7e2a01..03e5e55d7 100644 --- a/t/Keyword.t +++ b/t/Keyword.t @@ -17,7 +17,7 @@ use WebGUI::Keyword; use WebGUI::Asset; # load your modules here -use Test::More tests => 14; # increment this value for each test you create +use Test::More tests => 15; # increment this value for each test you create use Test::Deep; use Data::Dumper; @@ -94,6 +94,12 @@ cmp_deeply( '... retrieving assets in more than one state' ); +cmp_deeply( + $keyword->getTopKeywords(), + { 'webgui' => '2' }, + 'check getTopKeywords returns correctly' +); + $keyword->deleteKeywordsForAsset($home); is(scalar(@{$keyword->getKeywordsForAsset({ asset=>$home, asArrayRef=>1})}), 0, "getKeywordsForAsset()"); diff --git a/t/Macro/Env.t b/t/Macro/Env.t index 1baa0c062..d84b51fb1 100644 --- a/t/Macro/Env.t +++ b/t/Macro/Env.t @@ -15,6 +15,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; use Data::Dumper; +use WebGUI::Macro::Env; use Test::More; # increment this value for each test you create @@ -27,17 +28,10 @@ my $session = WebGUI::Test->session; my %env = %{ $session->env->{_env} }; my @keys = keys %env; -my $numTests = 1 + 3 + scalar keys %env; +my $numTests = 3 + scalar keys %env; plan tests => $numTests; -my $macro = 'WebGUI::Macro::Env'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - my $output; $output = WebGUI::Macro::Env::process($session, ''); @@ -53,5 +47,3 @@ foreach my $key (keys %env) { my $output = WebGUI::Macro::Env::process($session, $key); is($output, $env{$key}, 'Fetching: '.$key); } - -} diff --git a/t/Macro/FetchMimeType.t b/t/Macro/FetchMimeType.t index 5b40e0a6b..83632e587 100644 --- a/t/Macro/FetchMimeType.t +++ b/t/Macro/FetchMimeType.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::FetchMimeType; use Test::More; # increment this value for each test you create @@ -49,17 +50,8 @@ my @testSets = ( my $numTests = scalar @testSets; -$numTests += 1; #For the use_ok - plan tests => $numTests; -my $macro = 'WebGUI::Macro::FetchMimeType'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - foreach my $testSet (@testSets) { my $file = $testSet->{input} ? join '/', WebGUI::Test->root, 'www/extras', $testSet->{input} @@ -67,5 +59,3 @@ foreach my $testSet (@testSets) { my $output = WebGUI::Macro::FetchMimeType::process($session, $file); is($output, $testSet->{output}, $testSet->{comment} ); } - -} diff --git a/t/Macro/FileUrl.t b/t/Macro/FileUrl.t index 6cc0963fe..05df10e4a 100644 --- a/t/Macro/FileUrl.t +++ b/t/Macro/FileUrl.t @@ -16,6 +16,7 @@ use WebGUI::Test; use WebGUI::Session; use WebGUI::Storage; use Data::Dumper; +use WebGUI::Macro::FileUrl; use Test::More; # increment this value for each test you create @@ -85,21 +86,13 @@ my @testSets = ( my $numTests = scalar @testSets; -$numTests += 1; #For the use_ok $numTests += 1; #non-existant URL plan tests => $numTests; -my $macro = 'WebGUI::Macro::FileUrl'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - my $homeAsset = WebGUI::Asset->getDefault($session); -my ($versionTag, @testSets) = setupTest($session, $homeAsset, @testSets); +my @testSets = setupTest($session, $homeAsset, @testSets); foreach my $testSet (@testSets) { my $output = WebGUI::Macro::FileUrl::process($session, $testSet->{url}); @@ -114,8 +107,6 @@ foreach my $testSet (@testSets) { my $output = WebGUI::Macro::FileUrl::process($session, "non-existant-url"); is($output, $i18n->get('invalid url'), "Non-existant url returns error message"); -} - sub setupTest { my ($session, $homeAsset, @testSets) = @_; my $versionTag = WebGUI::VersionTag->getWorking($session); @@ -145,9 +136,6 @@ sub setupTest { ++$testNum; } $versionTag->commit; - WebGUI::Test->tagsToRollback($versionTag); - return $versionTag, @testSets; -} - -END { ##Clean-up after yourself, always + addToCleanup($versionTag); + return @testSets; } diff --git a/t/Macro/FormParam.t b/t/Macro/FormParam.t index 4040fd15f..c608eaf2f 100644 --- a/t/Macro/FormParam.t +++ b/t/Macro/FormParam.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::FormParam; use Test::More; # increment this value for each test you create use Test::MockObject; @@ -53,23 +54,13 @@ my @testSets = ( my $numTests = scalar @testSets; -$numTests += 1; ##use_ok $numTests += 1; ##testBlock has no name collisions $numTests += 3; ##TODO block plan tests => $numTests; -my $macro = 'WebGUI::Macro::FormParam'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - auto_check($session, \@testSets); -} - TODO: { local $TODO = "Tests to write later"; ok(0, "What will this do with a non-existant form param?"); diff --git a/t/Macro/GroupAdd.t b/t/Macro/GroupAdd.t index 32e2f8c8d..582be72ba 100644 --- a/t/Macro/GroupAdd.t +++ b/t/Macro/GroupAdd.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::GroupAdd; use Data::Dumper; use Test::More; # increment this value for each test you create @@ -22,7 +23,7 @@ use HTML::TokeParser; my $session = WebGUI::Test->session; my $homeAsset = WebGUI::Asset->getDefault($session); -my ($versionTag, $template, $groups, $users) = setupTest($session, $homeAsset); +my ($template, $groups, $users) = setupTest($session, $homeAsset); my @testSets = ( { @@ -118,17 +119,8 @@ foreach my $testSet (@testSets) { $numTests += 1 + ($testSet->{empty} == 0); } -$numTests += 1; #For the use_ok - plan tests => $numTests; -my $macro = 'WebGUI::Macro::GroupAdd'; -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::GroupAdd::process($session, @@ -144,8 +136,6 @@ foreach my $testSet (@testSets) { } } -} - sub setupTest { my ($session, $defaultNode) = @_; my @groups; @@ -156,13 +146,13 @@ sub setupTest { $groups[1] = WebGUI::Group->new($session, "new"); $groups[1]->name('Regular Old Group'); $groups[1]->autoAdd(0); - WebGUI::Test->groupsToDelete(@groups); + addToCleanup(@groups); ##Three users. One in each group and one with no group membership my @users = map { WebGUI::User->new($session, "new") } 0..2; $users[0]->addToGroups([$groups[0]->getId]); $users[1]->addToGroups([$groups[1]->getId]); - WebGUI::Test->usersToDelete(@users); + addToCleanup(@users); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"GroupAdd test"}); @@ -178,8 +168,9 @@ sub setupTest { }; my $asset = $defaultNode->addChild($properties, $properties->{id}); $versionTag->commit; + addToCleanup($versionTag); - return $versionTag, $asset, \@groups, \@users; + return $asset, \@groups, \@users; } sub simpleHTMLParser { @@ -201,9 +192,3 @@ sub simpleTextParser { return ($url, $label); } - -END { ##Clean-up after yourself, always - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } -} diff --git a/t/Macro/GroupDelete.t b/t/Macro/GroupDelete.t index c8ec7eb0f..6e3b48cc1 100644 --- a/t/Macro/GroupDelete.t +++ b/t/Macro/GroupDelete.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::GroupDelete; use Data::Dumper; use Test::More; # increment this value for each test you create @@ -22,7 +23,7 @@ use HTML::TokeParser; my $session = WebGUI::Test->session; my $homeAsset = WebGUI::Asset->getDefault($session); -my ($versionTag, $template, $groups, $users) = setupTest($session, $homeAsset); +my ($template, $groups, $users) = setupTest($session, $homeAsset); my @testSets = ( { @@ -118,17 +119,8 @@ foreach my $testSet (@testSets) { $numTests += 1 + ($testSet->{empty} == 0); } -$numTests += 1; #For the use_ok - plan tests => $numTests; -my $macro = 'WebGUI::Macro::GroupDelete'; -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::GroupDelete::process($session, @@ -144,8 +136,6 @@ foreach my $testSet (@testSets) { } } -} - sub setupTest { my ($session, $defaultNode) = @_; my @groups; @@ -156,13 +146,13 @@ sub setupTest { $groups[1] = WebGUI::Group->new($session, "new"); $groups[1]->name('Regular Old Group'); $groups[1]->autoDelete(0); - WebGUI::Test->groupsToDelete(@groups); + addToCleanup(@groups); ##Three users. One in each group and one with no group membership my @users = map { WebGUI::User->new($session, "new") } 0..2; $users[0]->addToGroups([$groups[0]->getId]); $users[1]->addToGroups([$groups[1]->getId]); - WebGUI::Test->usersToDelete(@users); + addToCleanup(@users); my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"GroupDelete test"}); @@ -178,8 +168,9 @@ sub setupTest { }; my $asset = $defaultNode->addChild($properties, $properties->{id}); $versionTag->commit; + addToCleanup($versionTag); - return $versionTag, $asset, \@groups, \@users; + return $asset, \@groups, \@users; } sub simpleHTMLParser { @@ -201,9 +192,3 @@ sub simpleTextParser { return ($url, $label); } - -END { ##Clean-up after yourself, always - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } -} diff --git a/t/Macro/GroupText.t b/t/Macro/GroupText.t index c3f066066..e09085017 100644 --- a/t/Macro/GroupText.t +++ b/t/Macro/GroupText.t @@ -16,6 +16,7 @@ use WebGUI::Test; use WebGUI::Session; use WebGUI::Group; use WebGUI::User; +use WebGUI::Macro::GroupText; my $session = WebGUI::Test->session; @@ -24,21 +25,13 @@ use Test::More; # increment this value for each test you create 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; $session->user({userId => 1}); @@ -65,14 +58,14 @@ my $sth = $session->db->prepare('INSERT INTO myUserTable VALUES(?)'); foreach my $mob (@mob) { $sth->execute([ $mob->userId ]); } -WebGUI::Test->usersToDelete(@mob); +addToCleanup(@mob); ##Create the 3 groups $ms_users = WebGUI::Group->new($session, "new"); $ms_distributors = WebGUI::Group->new($session, "new"); $ms_int_distributors = WebGUI::Group->new($session, "new"); -WebGUI::Test->groupsToDelete($ms_users, $ms_distributors, $ms_int_distributors); +addToCleanup($ms_users, $ms_distributors, $ms_int_distributors); $ms_users->name('MS Users'); $ms_distributors->name('MS Distributors'); @@ -94,7 +87,7 @@ $ms_distributors->addGroups([$ms_int_distributors->getId]); $disti = WebGUI::User->new($session, 'new'); $int_disti = WebGUI::User->new($session, 'new'); -WebGUI::Test->usersToDelete($disti, $int_disti); +addToCleanup($disti, $int_disti); $ms_distributors->addUsers([$disti->userId]); $ms_int_distributors->addUsers([$int_disti->userId]); @@ -123,8 +116,6 @@ $output = join ',', ; is($output, 'user,disti,int_disti', 'user is in all three groups'); -} - ##clean up everything END { $session->db->dbh->do('DROP TABLE IF EXISTS myUserTable'); diff --git a/t/Macro/Hash_userId.t b/t/Macro/Hash_userId.t index 064c25465..cd2f2fca9 100644 --- a/t/Macro/Hash_userId.t +++ b/t/Macro/Hash_userId.t @@ -16,6 +16,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::Hash_userId; use Data::Dumper; my $session = WebGUI::Test->session; @@ -35,21 +36,10 @@ 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}); } - -} diff --git a/t/Macro/If.t b/t/Macro/If.t index c6563018a..fe2e929d4 100644 --- a/t/Macro/If.t +++ b/t/Macro/If.t @@ -14,23 +14,17 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::If; use Data::Dumper; my $session = WebGUI::Test->session; use Test::More; # increment this value for each test you create -my $numTests = 8 + 1; # For conditional load and skip +my $numTests = 8; # For conditional load and skip plan tests => $numTests; -my $macro = 'WebGUI::Macro::If'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - my $output; $output = WebGUI::Macro::If::process($session, '', 'full', 'empty'); @@ -56,5 +50,3 @@ is($output, 'There are 5 lights', 'true text works with sprintf'); $output = WebGUI::Macro::If::process($session, 0, 'Full', 'There are %s lights'); is($output, 'There are %s lights', '...false text does not'); - -} diff --git a/t/Macro/Include.t b/t/Macro/Include.t index a10fab767..cf57e7452 100644 --- a/t/Macro/Include.t +++ b/t/Macro/Include.t @@ -15,6 +15,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::Storage; +use WebGUI::Macro::Include; use Test::More; # increment this value for each test you create @@ -85,18 +86,10 @@ my @testSets = ( my $numTests = scalar @testSets; -$numTests += 1; #For the use_ok $numTests += 1; #For the unreadable file test 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}); is($output, $testSet->{output}, $testSet->{comment} . ":" .$testSet->{file}); @@ -109,8 +102,3 @@ SKIP: { my $output = WebGUI::Macro::Include::process($session, $file); is($output, $i18n->get('not found'), q|Unreadable file returns NOT FOUND|. ":" .$file); } - -} - -END { -} diff --git a/t/Macro/International.t b/t/Macro/International.t index 5aa5b97dd..ae4033da5 100644 --- a/t/Macro/International.t +++ b/t/Macro/International.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::International; use Data::Dumper; use Test::More; # increment this value for each test you create @@ -50,18 +51,9 @@ my @testSets = ( my $numTests = scalar @testSets; -$numTests += 1; plan tests => $numTests; -my $loaded = use_ok('WebGUI::Macro::International'); - -SKIP: { - -skip 'Module was not loaded, skipping all tests', $numTests -1 unless $loaded; - foreach my $testSet (@testSets) { my $output = WebGUI::Macro::International::process($session, @{ $testSet->{input} }); is($output, $testSet->{output}, $testSet->{comment} ); } - -} diff --git a/t/Macro/L_loginBox.t b/t/Macro/L_loginBox.t index 444e63acc..b66e0a198 100644 --- a/t/Macro/L_loginBox.t +++ b/t/Macro/L_loginBox.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::L_loginBox; use HTML::TokeParser; use Test::More; # increment this value for each test you create @@ -22,7 +23,7 @@ my $session = WebGUI::Test->session; my $homeAsset = WebGUI::Asset->getDefault($session); $session->asset($homeAsset); -my ($versionTag, $template) = setupTest($session, $homeAsset); +my $template = setupTest($session, $homeAsset); $session->user({userId=>1}); ##Replace the original ENV hash with one that will return a @@ -37,17 +38,7 @@ $session->{_env}->{_env} = \%newEnvHash; my $i18n = WebGUI::International->new($session,'Macro_L_loginBox'); -my $numTests = 1; #Module loading test -$numTests += 30; #Static tests - -plan tests => $numTests; - -my $macro = 'WebGUI::Macro::L_loginBox'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; +plan tests => 30; my $output = WebGUI::Macro::L_loginBox::process($session,'','',$template->getId); my %vars = simpleTextParser($output); @@ -170,8 +161,6 @@ $output = WebGUI::Macro::L_loginBox::process($session,'','',''); my $passwordLabel = $i18n->get(51, 'WebGUI'); like($output, qr/$passwordLabel/, 'default template works'); -} - sub simpleTextParser { my ($text) = @_; @@ -236,11 +225,6 @@ sub setupTest { #$properties->{template} .= "\n"; my $template = $defaultNode->addChild($properties, $properties->{id}); $versionTag->commit; - return ($versionTag, $template); -} - -END { ##Clean-up after yourself, always - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } + addToCleanup($versionTag); + return $template; } diff --git a/t/Macro/LastModified.t b/t/Macro/LastModified.t index 285a9219c..5907bae34 100644 --- a/t/Macro/LastModified.t +++ b/t/Macro/LastModified.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::LastModified; use Test::More; # increment this value for each test you create @@ -46,17 +47,12 @@ my @testSets = ( my $numTests = scalar @testSets; -$numTests += 1 + 2; #For the use_ok, default asset, and revisionDate=0 +$numTests += 2; #For the use_ok, default asset, and revisionDate=0 plan tests => $numTests; -my $macro = 'WebGUI::Macro::LastModified'; -my $loaded = use_ok($macro); my $versionTag = WebGUI::VersionTag->getWorking($session); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; +addToCleanup($versionTag); my $output = WebGUI::Macro::LastModified::process($session); is($output, '', "Macro returns '' if no asset is defined"); @@ -97,11 +93,3 @@ is($output, $i18n->get('never'), 'asset with 0 revisionDate returns never modifi ##Restore the original revisionDate, otherwise it dies during clean-up $session->db->write('update assetData set revisionDate=? where assetId=?', [$revDate, $assetA->getId]); - -} - -END { ##Clean-up after yourself, always - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } -} diff --git a/t/Macro/LoginToggle.t b/t/Macro/LoginToggle.t index 0b34064bd..dde519766 100644 --- a/t/Macro/LoginToggle.t +++ b/t/Macro/LoginToggle.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::LoginToggle; use HTML::TokeParser; use Data::Dumper; @@ -23,7 +24,7 @@ my $session = WebGUI::Test->session; my $homeAsset = WebGUI::Asset->getDefault($session); $session->asset($homeAsset); -my ($versionTag, $template) = setupTest($session, $homeAsset); +my $template = setupTest($session, $homeAsset); my $i18n = WebGUI::International->new($session,'Macro_LoginToggle'); @@ -131,16 +132,8 @@ foreach my $testSet (@testSets) { $numTests += 1 + (ref $testSet->{parser} eq 'CODE'); } -$numTests += 1; #for the use_ok plan tests => $numTests; -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}}); if ($testSet->{userId} eq '1') { @@ -163,8 +156,6 @@ foreach my $testSet (@testSets) { } } -} - sub simpleHTMLParser { my ($text) = @_; my $p = HTML::TokeParser->new(\$text); @@ -205,11 +196,6 @@ sub setupTest { }; my $template = $defaultNode->addChild($properties, $properties->{id}); $versionTag->commit; - return ($versionTag, $template); -} - -END { ##Clean-up after yourself, always - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } + addToCleanup($versionTag); + return ($template); } diff --git a/t/Macro/MiniCart.t b/t/Macro/MiniCart.t index 14ef3d2bf..101f2154b 100644 --- a/t/Macro/MiniCart.t +++ b/t/Macro/MiniCart.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::MiniCart; use JSON; use Data::Dumper; @@ -22,14 +23,7 @@ use Test::Deep; my $session = WebGUI::Test->session; -my $numTests = 4; - -$numTests += 1; #For the use_ok - -plan tests => $numTests; - -my $macro = 'WebGUI::Macro::MiniCart'; -my $loaded = use_ok($macro); +plan tests => 4; my $cart = WebGUI::Shop::Cart->newBySession($session); my $donation = WebGUI::Asset->getRoot($session)->addChild({ @@ -40,105 +34,94 @@ my $donation = WebGUI::Asset->getRoot($session)->addChild({ }); my $template = setupJSONtemplate($session); +addToCleanup($cart, $donation, $template); -SKIP: { +my $json; +my $templateVars; -skip "Unable to load $macro", $numTests-1 unless $loaded; +$json = WebGUI::Macro::MiniCart::process($session, $template->getId); +$templateVars = JSON::from_json($json); +cmp_deeply( + $templateVars, + { + totalPrice => '0', + totalItems => '0', + items => [], + }, + 'Empty cart works' +); - my $json; - my $templateVars; +my $item1 = $cart->addItem($donation); +$json = WebGUI::Macro::MiniCart::process($session, $template->getId); +$templateVars = JSON::from_json($json); +cmp_deeply( + $templateVars, + { + totalPrice => '10', + totalItems => '1', + items => [ + { + name => $donation->getConfiguredTitle(), + quantity => 1, + price => 10, + url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId), + }, + ], + }, + 'Cart with one item works' +); - $json = WebGUI::Macro::MiniCart::process($session, $template->getId); - $templateVars = JSON::from_json($json); - cmp_deeply( - $templateVars, - { - totalPrice => '0', - totalItems => '0', - items => [], - }, - 'Empty cart works' - ); +my $item2 = $cart->addItem($donation); +$json = WebGUI::Macro::MiniCart::process($session, $template->getId); +$templateVars = JSON::from_json($json); +cmp_deeply( + $templateVars, + { + totalPrice => '20', + totalItems => '2', + items => bag( + { + name => $donation->getConfiguredTitle(), + quantity => 1, + price => 10, + url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId), + }, + { + name => $donation->getConfiguredTitle(), + quantity => 1, + price => 10, + url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId), + }, + ), + }, + 'Cart with two items works' +); - my $item1 = $cart->addItem($donation); - $json = WebGUI::Macro::MiniCart::process($session, $template->getId); - $templateVars = JSON::from_json($json); - cmp_deeply( - $templateVars, - { - totalPrice => '10', - totalItems => '1', - items => [ - { - name => $donation->getConfiguredTitle(), - quantity => 1, - price => 10, - url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId), - }, - ], - }, - 'Cart with one item works' - ); - - my $item2 = $cart->addItem($donation); - $json = WebGUI::Macro::MiniCart::process($session, $template->getId); - $templateVars = JSON::from_json($json); - cmp_deeply( - $templateVars, - { - totalPrice => '20', - totalItems => '2', - items => bag( - { - name => $donation->getConfiguredTitle(), - quantity => 1, - price => 10, - url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId), - }, - { - name => $donation->getConfiguredTitle(), - quantity => 1, - price => 10, - url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId), - }, - ), - }, - 'Cart with two items works' - ); - - $item2->setQuantity(9); - $json = WebGUI::Macro::MiniCart::process($session, $template->getId); - $templateVars = JSON::from_json($json); - cmp_deeply( - $templateVars, - { - totalPrice => '100', - totalItems => '10', - items => bag( - { - name => $donation->getConfiguredTitle(), - quantity => 1, - price => 10, - url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId), - }, - { - name => $donation->getConfiguredTitle(), - quantity => 9, - price => 10, - url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId), - }, - ), - }, - 'Cart with two items and multiple quantities works' - ); - -} - -END { - $cart->delete; - $donation->purge; - $template->purge; -} +$item2->setQuantity(9); +$json = WebGUI::Macro::MiniCart::process($session, $template->getId); +$templateVars = JSON::from_json($json); +cmp_deeply( + $templateVars, + { + totalPrice => '100', + totalItems => '10', + items => bag( + { + name => $donation->getConfiguredTitle(), + quantity => 1, + price => 10, + url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item1->getId), + }, + { + name => $donation->getConfiguredTitle(), + quantity => 9, + price => 10, + url => $donation->getUrl('shop=cart;method=viewItem;itemId='.$item2->getId), + }, + ), + }, + 'Cart with two items and multiple quantities works' +); sub setupJSONtemplate { my ($session) = @_; diff --git a/t/Macro/Page.t b/t/Macro/Page.t index 0654a366d..6d063586a 100644 --- a/t/Macro/Page.t +++ b/t/Macro/Page.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::Page; use Data::Dumper; use Test::More; # increment this value for each test you create @@ -46,22 +47,13 @@ foreach my $testSet (@testSets) { $numTests += scalar keys %{ $testSet }; } -$numTests += 1; #For the use_ok $numTests += 1; #For macro call with undefined session asset 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; +@testSets = setupTest($session, $homeAsset, @testSets); is( WebGUI::Macro::Page::process($session,'url'), @@ -80,8 +72,6 @@ foreach my $testSet (@testSets) { } } -} - sub setupTest { my ($session, $homeAsset, @testSets) = @_; my $versionTag = WebGUI::VersionTag->getWorking($session); @@ -92,9 +82,6 @@ sub setupTest { $testSet->{asset} = $asset; } $versionTag->commit; - return $versionTag, @testSets; -} - -END { ##Clean-up after yourself, always - $versionTag->rollback; + addToCleanup($versionTag); + return @testSets; } diff --git a/t/Macro/PageTitle.t b/t/Macro/PageTitle.t index 58d7401ec..846968494 100644 --- a/t/Macro/PageTitle.t +++ b/t/Macro/PageTitle.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::PageTitle; use Data::Dumper; use Test::More; @@ -22,13 +23,9 @@ use Test::MockObject; my $session = WebGUI::Test->session; my $numTests = 7; -$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); my $versionTag = WebGUI::VersionTag->getWorking($session); @@ -45,10 +42,7 @@ my $snippet = $homeAsset->addChild({ }); $versionTag->commit; - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; +addToCleanup($versionTag); is( WebGUI::Macro::PageTitle::process($session), @@ -66,7 +60,6 @@ $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"); - my $origSessionRequest = $session->{_request}; my ($operation, $function) = (0,0); @@ -105,9 +98,3 @@ $operation = 1; $function = 1; $output = WebGUI::Macro::PageTitle::process($session); is($output, $urlizedTitle, 'fetching urlized title via an operation and function'); - -} - -END { - $versionTag->rollback; -} diff --git a/t/Macro/PickLanguage.t b/t/Macro/PickLanguage.t index ad93afb6a..bc7feaf71 100644 --- a/t/Macro/PickLanguage.t +++ b/t/Macro/PickLanguage.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; use WebGUI::Asset::Template; +use WebGUI::Macro::PickLanguage; use Test::More; # increment this value for each test you create use Test::Deep; @@ -24,13 +25,8 @@ my $session = WebGUI::Test->session; my $numTests = 3; -$numTests += 1; #For the use_ok - plan tests => $numTests; -my $macro = 'WebGUI::Macro::PickLanguage'; -my $loaded = use_ok($macro); - my $macroMock = Test::MockObject->new({}); $macroMock->set_isa('WebGUI::Macro::PickLanguage'); $macroMock->set_true('process'); @@ -61,6 +57,8 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } ); 'language_langEng' => 'English' }, ], + delete_url => '?op=setLanguage;language=delete;', + delete_label => 'Go back to profile language.', }, 'some template variables are created' ); @@ -90,6 +88,8 @@ $templateMock->mock('process', sub { $templateVars = $_[1]; } ); 'language_langEng' => 'English' }, ], + delete_url => '?op=setLanguage;language=delete;', + delete_label => "Go back to profile language.", }, 'some template variables are created, when no templateId is passed on with the macro' ); diff --git a/t/Macro/RootTitle.t b/t/Macro/RootTitle.t index 16a82ca56..353d14e6c 100644 --- a/t/Macro/RootTitle.t +++ b/t/Macro/RootTitle.t @@ -13,8 +13,8 @@ use strict; use lib "$FindBin::Bin/../lib"; use WebGUI::Test; -use WebGUI::Macro::RootTitle; use WebGUI::Session; +use WebGUI::Macro::RootTitle; use Data::Dumper; use Test::More; # increment this value for each test you create @@ -32,6 +32,7 @@ my $session = WebGUI::Test->session; my $versionTag = WebGUI::VersionTag->getWorking($session); $versionTag->set({name=>"Adding assets for RootTitle tests"}); +addToCleanup($versionTag); my $root = WebGUI::Asset->getRoot($session); my %properties_A = ( @@ -160,17 +161,10 @@ my @testSets = ( ); my $numTests = scalar @testSets; -$numTests += 2; +$numTests += 1; plan tests => $numTests; -my $macro = 'WebGUI::Macro::RootTitle'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - is( WebGUI::Macro::RootTitle::process($session), '', @@ -183,12 +177,3 @@ foreach my $testSet (@testSets) { my $output = WebGUI::Macro::RootTitle::process($session); is($output, $testSet->{title}, $testSet->{comment}); } - -} - -END { ##Clean-up after yourself, always - $session->db->write('update asset set lineage=? where assetId=?',[$origLineage, $asset_->getId]); - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } -} diff --git a/t/Macro/SQL.t b/t/Macro/SQL.t index 720536728..1e4219a62 100644 --- a/t/Macro/SQL.t +++ b/t/Macro/SQL.t @@ -17,6 +17,7 @@ use WebGUI::Macro::Slash_gatewayUrl; use WebGUI::Session; use WebGUI::International; use WebGUI::DatabaseLink; +use WebGUI::Macro::SQL; use Data::Dumper; use Test::More; # increment this value for each test you create @@ -119,14 +120,10 @@ my @testSets = ( my $numTests = scalar @testSets; -++$numTests; ##For the load check; ++$numTests; ##For the allow macro access test; plan tests => $numTests; -my $macro = 'WebGUI::Macro::SQL'; -my $loaded = use_ok($macro); - $WebGUIdbLink->set({allowMacroAccess=>0}); # run one test to test allowMacroAccess @@ -136,10 +133,6 @@ is($output, $i18n->get('database access not allowed'), 'Test allow access from m # set allowMacroAccess to 1 to allow other tests to run $WebGUIdbLink->set({allowMacroAccess=>1}); -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - foreach my $testSet (@testSets) { # we know some of these will fail. Keep them quiet. local $SIG{__WARN__} = sub {}; @@ -148,8 +141,6 @@ foreach my $testSet (@testSets) { is($output, $testSet->{output}, $testSet->{comment}); } -} - # reset allowMacroAccess to original value $WebGUIdbLink->set({allowMacroAccess=>$originalMacroAccessValue}); diff --git a/t/Macro/SessionId.t b/t/Macro/SessionId.t index e2ca4df69..5c4867db4 100644 --- a/t/Macro/SessionId.t +++ b/t/Macro/SessionId.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::SessionId; use HTML::TokeParser; use Data::Dumper; @@ -21,16 +22,7 @@ use Test::More; # increment this value for each test you create my $session = WebGUI::Test->session; -my $numTests = 1; -$numTests += 1; #For the use_ok -plan tests => 2; +plan tests => 1; -my $macro = 'WebGUI::Macro::SessionId'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - my $output = WebGUI::Macro::SessionId::process( $session ); - is($session->getId, $output, 'Session macro works'); -} +my $output = WebGUI::Macro::SessionId::process( $session ); +is($session->getId, $output, 'Session macro works'); diff --git a/t/Macro/Slash_gatewayUrl.t b/t/Macro/Slash_gatewayUrl.t index 596bcf6a0..670de8cc4 100644 --- a/t/Macro/Slash_gatewayUrl.t +++ b/t/Macro/Slash_gatewayUrl.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::Slash_gatewayUrl; use Data::Dumper; use Test::More; # increment this value for each test you create @@ -24,17 +25,7 @@ my $session = WebGUI::Test->session; ##in t/Session/Url.t All we need to do is make sure that the macro ##fetches the same thing as the method. -my $numTests = 4; -$numTests += 1; #For the use_ok - -plan tests => $numTests; - -my $macro = 'WebGUI::Macro::Slash_gatewayUrl'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; +plan tests => 4; $session->setting->set('preventProxyCache', 0); @@ -54,9 +45,3 @@ like($output, qr{/\?noCache=\d+:\d+$}, 'checking the cache settings in the URL') $output = WebGUI::Macro::Slash_gatewayUrl::process($session, '/foo/bar'); like($output, qr{/foo/bar\?noCache=\d+:\d+$}, 'checking the cache settings in the URL are at the end of the URL'); -$session->setting->set('preventProxyCache', 0); - -} - -END { -} diff --git a/t/Macro/Thumbnail.t b/t/Macro/Thumbnail.t index 6b8f97cd5..78100d881 100644 --- a/t/Macro/Thumbnail.t +++ b/t/Macro/Thumbnail.t @@ -68,6 +68,7 @@ $asset->update({ $asset->generateThumbnail(); $versionTag->commit; +addToCleanup($versionTag); ##Call the Thumbnail Macro with that Asset's URL and see if it returns @@ -95,10 +96,3 @@ SKIP: { cmp_bag([$thumbImg->GetPixels(width=>1, height=>1, x=>50, y=>50, map=>'RGB', normalize=>'true')], [0,0,1], 'blue pixel #3'); } - -END { - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } - ##Storage is cleaned up by rolling back the version tag -} diff --git a/t/Macro/User.t b/t/Macro/User.t index 6053a1955..33a0decba 100644 --- a/t/Macro/User.t +++ b/t/Macro/User.t @@ -79,6 +79,3 @@ sub setupTest { } return @testSets; } - -END { ##Clean-up after yourself, always -} diff --git a/t/Macro/UsersOnline.t b/t/Macro/UsersOnline.t index 42734ec33..c64e6e32b 100644 --- a/t/Macro/UsersOnline.t +++ b/t/Macro/UsersOnline.t @@ -29,130 +29,119 @@ my $template = setupJSONtemplate($session); my @users = setupUsers($session); my $i18n = WebGUI::International->new($session,'Macro_UsersOnline'); -my $numTests = 1; # Module loading test -$numTests += 30; # Static tests +plan tests => 30; -plan tests => $numTests; +# Basic testing ----------------------------------------------------------- -my $macro = 'WebGUI::Macro::UsersOnline'; -my $loaded = use_ok($macro); +# Check for default template +my $defTemplate = WebGUI::Asset->new($session, 'h_T2xtOxGRQ9QJOR6ebLpQ'); +ok(defined $defTemplate, 'default template is present'); -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - - # Basic testing ----------------------------------------------------------- - - # Check for default template - my $defTemplate = WebGUI::Asset->new($session, 'h_T2xtOxGRQ9QJOR6ebLpQ'); - ok(defined $defTemplate, 'default template is present'); - - # Call with default values - my $html = WebGUI::Macro::UsersOnline::process($session); - cmp_ok((length $html), '>', 0, 'call with default template and values returns some output'); +# Call with default values +my $html = WebGUI::Macro::UsersOnline::process($session); +cmp_ok((length $html), '>', 0, 'call with default template and values returns some output'); - # Test labels ------------------------------------------------------------- +# Test labels ------------------------------------------------------------- - $session->user({userId => 1}); - my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId); - my $vars = JSON::from_json($json); +$session->user({userId => 1}); +my $json = WebGUI::Macro::UsersOnline::process($session, $template->getId); +my $vars = JSON::from_json($json); - is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label'); - is($vars->{'members_label'}, $i18n->get('Members'), 'members_label'); - is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label'); - is($vars->{'total_label'}, $i18n->get('Total'), 'total_label'); - is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label'); - is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label'); - is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label'); - is($vars->{'name_label'}, $i18n->get('Name'), 'name_label'); - is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label'); - is($vars->{'session_label'}, $i18n->get('Session'), 'session_label'); - is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label'); - is($vars->{'lastActivity_label'}, $i18n->get('Last Activity'), 'lastActivity_label'); +is($vars->{'usersOnline_label'}, $i18n->get('Users Online'), 'usersOnline_label'); +is($vars->{'members_label'}, $i18n->get('Members'), 'members_label'); +is($vars->{'visitors_label'}, $i18n->get('Visitors'), 'visitors_label'); +is($vars->{'total_label'}, $i18n->get('Total'), 'total_label'); +is($vars->{'membersOnline_label'}, $i18n->get('Members Online'), 'membersOnline_label'); +is($vars->{'visitorsOnline_label'}, $i18n->get('Visitors Online'), 'visitorsOnline_label'); +is($vars->{'avatar_label'}, $i18n->get('Avatar'), 'avatar_label'); +is($vars->{'name_label'}, $i18n->get('Name'), 'name_label'); +is($vars->{'alias_label'}, $i18n->get('Alias'), 'alias_label'); +is($vars->{'session_label'}, $i18n->get('Session'), 'session_label'); +is($vars->{'ip_label'}, $i18n->get('IP'), 'ip_label'); +is($vars->{'lastActivity_label'}, $i18n->get('Last Activity'), 'lastActivity_label'); - # Test logic -------------------------------------------------------------- +# Test logic -------------------------------------------------------------- - like($vars->{'visitors'}, qr/[0-9]+/, 'visitors is numeric'); +like($vars->{'visitors'}, qr/[0-9]+/, 'visitors is numeric'); # Does not work in testing environments that run on the loopback interface, # since these queries are filtered out by the macro. # is($vars->{'visitors'} > 0, 1, 'visitors > 0 when calling as visitor'); - like($vars->{'members'}, qr/[0-9]+/, 'members is numeric'); - cmp_ok($vars->{'members'}, '>', 0, 'members > 0 since we have created one visible active member'); - is($vars->{'total'}, $vars->{'visitors'} + $vars->{'members'}, 'total == visitors + members'); - ok($vars->{'isVisitor'}, 'isVisitor is true when calling as visitor'); - ok(defined $vars->{'hasMembers'}, 'hasMembers is defined since we have created one visible active member'); +like($vars->{'members'}, qr/[0-9]+/, 'members is numeric'); +cmp_ok($vars->{'members'}, '>', 0, 'members > 0 since we have created one visible active member'); +is($vars->{'total'}, $vars->{'visitors'} + $vars->{'members'}, 'total == visitors + members'); +ok($vars->{'isVisitor'}, 'isVisitor is true when calling as visitor'); +ok(defined $vars->{'hasMembers'}, 'hasMembers is defined since we have created one visible active member'); - # Check member loop ------------------------------------------------------- +# Check member loop ------------------------------------------------------- - my $allFieldsSet = 1; - my $firstUserPresent = 0; - my $secondUserAbsent = 1; +my $allFieldsSet = 1; +my $firstUserPresent = 0; +my $secondUserAbsent = 1; - foreach (@{$vars->{'member_loop'}}) { - # Check whether first user is present - if ($_->{'username'} eq 'tester1') { - # Indicate success - $firstUserPresent = 1; - # Check whether alias and name have been set correctly - $allFieldsSet = $_->{'alias'} eq 'alias1'; - $allFieldsSet &&= $_->{'firstName'} eq 'first1'; - $allFieldsSet &&= $_->{'middleName'} eq 'middle1'; - $allFieldsSet &&= $_->{'lastName'} eq 'last1'; - } - - # Check whether second user is present - if ($_->{'username'} eq 'tester2') { - # Indicate failure - $secondUserAbsent = 0; - } - - # Check whether remaining fields have been set. Note that we cannot - # check for the alias, name or avatar, since these values may be - # optional. - $allFieldsSet &&= $_->{'uid'} =~ /.*/; - $allFieldsSet &&= $_->{'sessionId'} =~ /.*/; -# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user - $allFieldsSet &&= $_->{'lastActivity'} =~ /.*/; - } - # Check booleans indicating errors - ok($allFieldsSet, 'fields in the member loop have been set correctly'); - ok($firstUserPresent, 'the first user is present in the member loop'); - ok($secondUserAbsent, 'the second user is absent from the member loop'); - - - # Check visitor loop ------------------------------------------------------ - - $allFieldsSet = 1; - - foreach (@{$vars->{'visitor_loop'}}) { -# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user - $allFieldsSet &&= $_->{'sessionId'} =~ /.*/; - $allFieldsSet &&= $_->{'lastActivity'} =~ /.*/; +foreach (@{$vars->{'member_loop'}}) { + # Check whether first user is present + if ($_->{'username'} eq 'tester1') { + # Indicate success + $firstUserPresent = 1; + # Check whether alias and name have been set correctly + $allFieldsSet = $_->{'alias'} eq 'alias1'; + $allFieldsSet &&= $_->{'firstName'} eq 'first1'; + $allFieldsSet &&= $_->{'middleName'} eq 'middle1'; + $allFieldsSet &&= $_->{'lastName'} eq 'last1'; } - # Check booleans indicating errors - ok($allFieldsSet, 'fields in the visitor loop have been set correctly'); + # Check whether second user is present + if ($_->{'username'} eq 'tester2') { + # Indicate failure + $secondUserAbsent = 0; + } - - # Test macro parameters --------------------------------------------------- - - # Call with zero max limits - $json = WebGUI::Macro::UsersOnline::process($session, $template->getId, undef, 0, 0); - $vars = JSON::from_json($json); - ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when display limit is set to zero'); - is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when display limit is set to zero'); - is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when display limit is set to zero'); - - # Call with zero max inactivity time - $json = WebGUI::Macro::UsersOnline::process($session, $template->getId, 0, undef, undef); - $vars = JSON::from_json($json); - ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when max inactivity time is set to zero'); - is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when max inactivity time is set to zero'); - is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when max inactivity time is set to zero'); + # Check whether remaining fields have been set. Note that we cannot + # check for the alias, name or avatar, since these values may be + # optional. + $allFieldsSet &&= $_->{'uid'} =~ /.*/; + $allFieldsSet &&= $_->{'sessionId'} =~ /.*/; +# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user + $allFieldsSet &&= $_->{'lastActivity'} =~ /.*/; } +# Check booleans indicating errors +ok($allFieldsSet, 'fields in the member loop have been set correctly'); +ok($firstUserPresent, 'the first user is present in the member loop'); +ok($secondUserAbsent, 'the second user is absent from the member loop'); + + +# Check visitor loop ------------------------------------------------------ + +$allFieldsSet = 1; + +foreach (@{$vars->{'visitor_loop'}}) { +# $allFieldsSet &&= $_->{'ip'} =~ /.*/; # IP is not set for our test user + $allFieldsSet &&= $_->{'sessionId'} =~ /.*/; + $allFieldsSet &&= $_->{'lastActivity'} =~ /.*/; +} + +# Check booleans indicating errors +ok($allFieldsSet, 'fields in the visitor loop have been set correctly'); + + +# Test macro parameters --------------------------------------------------- + +# Call with zero max limits +$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, undef, 0, 0); +$vars = JSON::from_json($json); +ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when display limit is set to zero'); +is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when display limit is set to zero'); +is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when display limit is set to zero'); + +# Call with zero max inactivity time +$json = WebGUI::Macro::UsersOnline::process($session, $template->getId, 0, undef, undef); +$vars = JSON::from_json($json); +ok(!defined $vars->{'hasMembers'}, 'hasMembers undefined when max inactivity time is set to zero'); +is(@{$vars->{'member_loop'}} == 0, 1, 'empty member loop when max inactivity time is set to zero'); +is(@{$vars->{'visitor_loop'}} == 0, 1, 'empty visitor loop when max inactivity time is set to zero'); sub setupUsers { @@ -192,7 +181,7 @@ sub setupUsers { my $newSession = WebGUI::Session->open(WebGUI::Test::root, WebGUI::Test::file); $newSession->user({user => $_}); } - WebGUI::Test->usersToDelete(@users); + addToCleanup(@users); return @users; } @@ -246,10 +235,6 @@ sub setupJSONtemplate { } EOTMPL my $template = WebGUI::Asset->getImportNode($session)->addChild({className=>'WebGUI::Asset::Template', namespace => 'Macro/UsersOnline', template=>$templateBody}); + addToCleanup($template); return $template; } - - -END { ##Clean-up after yourself, always - $template->purge; -} diff --git a/t/Macro/ViewCart.t b/t/Macro/ViewCart.t index 5a2574f3e..063b09421 100644 --- a/t/Macro/ViewCart.t +++ b/t/Macro/ViewCart.t @@ -14,6 +14,7 @@ use lib "$FindBin::Bin/../lib"; use WebGUI::Test; use WebGUI::Session; +use WebGUI::Macro::ViewCart; use HTML::TokeParser; use Data::Dumper; @@ -21,8 +22,6 @@ use Test::More; # increment this value for each test you create my $session = WebGUI::Test->session; - - my @testSets = ( { comment => 'default', @@ -41,17 +40,8 @@ foreach my $testSet (@testSets) { $numTests += 1 + (ref $testSet->{output} eq 'CODE'); } -$numTests += 1; #For the use_ok - plan tests => $numTests; -my $macro = 'WebGUI::Macro::ViewCart'; -my $loaded = use_ok($macro); - -SKIP: { - -skip "Unable to load $macro", $numTests-1 unless $loaded; - foreach my $testSet (@testSets) { my $output = WebGUI::Macro::ViewCart::process( $session, $testSet->{label}); if (ref $testSet->{output} eq 'CODE') { @@ -64,9 +54,6 @@ foreach my $testSet (@testSets) { } } -} - - sub simpleHTMLParser { my ($text) = @_; my $p = HTML::TokeParser->new(\$text); @@ -86,6 +73,3 @@ sub simpleTextParser { return ($url, $label); } - -END { -} diff --git a/t/Macro/c_companyName.t b/t/Macro/c_companyName.t index 24d51d7ff..d3b22abb1 100644 --- a/t/Macro/c_companyName.t +++ b/t/Macro/c_companyName.t @@ -24,7 +24,7 @@ my $session = WebGUI::Test->session; plan tests => 2; my $output = WebGUI::Macro::c_companyName::process($session); -is($output, $originalCompanyName, "Testing companyName"); +is($output, $session->setting->get('companyName'), "Testing companyName"); $session->setting->set('companyName', q|Gooey's Consulting, LLC|); $output = WebGUI::Macro::c_companyName::process($session); diff --git a/t/Macro/r_printable.t b/t/Macro/r_printable.t index 2578c88eb..b0aa4e518 100644 --- a/t/Macro/r_printable.t +++ b/t/Macro/r_printable.t @@ -25,7 +25,7 @@ my $session = WebGUI::Test->session; my $homeAsset = WebGUI::Asset->getDefault($session); $session->asset($homeAsset); -my ($versionTag, $template) = setupTest($session, $homeAsset); +my $template = setupTest($session, $homeAsset); my $i18n = WebGUI::International->new($session, 'Macro_r_printable'); @@ -125,8 +125,9 @@ sub setupTest { }; my $asset = $defaultNode->addChild($properties, $properties->{id}); $versionTag->commit; + addToCleanup($versionTag); - return $versionTag, $asset; + return $asset; } sub simpleHTMLParser { @@ -148,9 +149,3 @@ sub simpleTextParser { return ($url, $label); } - -END { ##Clean-up after yourself, always - if (defined $versionTag and ref $versionTag eq 'WebGUI::VersionTag') { - $versionTag->rollback; - } -} diff --git a/t/rawHrefUrls.t b/t/rawHrefUrls.t index 43f4dc428..4d20286b6 100644 --- a/t/rawHrefUrls.t +++ b/t/rawHrefUrls.t @@ -26,11 +26,6 @@ use Test::More; # increment this value for each test you create my $numTests = 0; my $session = WebGUI::Test->session; -my $lib = WebGUI::Test->lib; - -##Find the name of the International macro in the user's config file. - -#note "International macro name = $international"; ##Regexp setup for parsing out the Macro calls. my $macro = qr{ @@ -43,19 +38,28 @@ my $macro = qr{ $numTests = $session->db->quickScalar('select count(distinct(assetId)) from template'); -plan tests => $numTests; +plan tests => 2*$numTests; my $validLinks = 0; +my $nonRootLink = qr{ + ^ + \s* #Optional whitespace + (?: \^ (?: / | Extras)) #Gateway or Extras macro + | # OR + {href}) { - if ($attrs->{href} !~ /\s*\^(?:\/|Extras)/) { + diag sprintf '%s: %s', $tag, $attrs->{href}; + if ($attrs->{href} !~ $nonRootLink) { $validLinks = 0; } } elsif ($tag eq 'script' && $attrs->{src}) { - if ($attrs->{src} !~ /\s*\^(?:\/|Extras)/) { + if ($attrs->{src} !~ $nonRootLink) { $validLinks = 0; } } @@ -70,15 +74,22 @@ my $parser = HTML::Parser->new( my $getATemplate = WebGUI::Asset::Template->getIsa($session); TEMPLATE: while (my $templateAsset = $getATemplate->()) { - my $template = $templateAsset->get('template'); my $header = $templateAsset->get('extraHeadTags'); if(! $header) { - ok(1, sprintf "%s: %s (%s) has no rooted link urls", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl); - next TEMPLATE; + ok(1, sprintf "%s: %s (%s) has no rooted link urls in the head tags", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl); + } + else { + $validLinks = 1; + $parser->parse($header); + ok($validLinks, sprintf "%s: %s (%s) has no rooted link urls in the head tags", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl); + } + my $template = $templateAsset->get('template'); + if(! $template) { + ok(1, sprintf "%s: %s (%s) has no rooted link urls in the template", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl); + } + else { + $validLinks = 1; + $parser->parse($template); + ok($validLinks, sprintf "%s: %s (%s) has no rooted link urls in the template", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl); } - $validLinks = 1; - $parser->parse($header); - ok($validLinks, sprintf "%s: %s (%s) has no rooted link urls", $templateAsset->getTitle, $templateAsset->getId, $templateAsset->getUrl); } - -